1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = glib-Date-and-Time-Functions.html 27 * outPack = glib 28 * outFile = TimeVal 29 * strct = GTimeVal 30 * realStrct= 31 * ctorStrct= 32 * clss = TimeVal 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_time_val_ 41 * - g_ 42 * omit structs: 43 * omit prefixes: 44 * - g_date_ 45 * omit code: 46 * omit signals: 47 * imports: 48 * - glib.Str 49 * structWrap: 50 * module aliases: 51 * local aliases: 52 * overrides: 53 */ 54 55 module glib.TimeVal; 56 57 public import gtkc.glibtypes; 58 59 private import gtkc.glib; 60 private import glib.ConstructionException; 61 62 63 private import glib.Str; 64 65 66 67 68 /** 69 * Description 70 * The GDate data structure represents a day between January 1, Year 1, 71 * and sometime a few thousand years in the future (right now it will go 72 * to the year 65535 or so, but g_date_set_parse() only parses up to the 73 * year 8000 or so - just count on "a few thousand"). GDate is meant to 74 * represent everyday dates, not astronomical dates or historical dates 75 * or ISO timestamps or the like. It extrapolates the current Gregorian 76 * calendar forward and backward in time; there is no attempt to change 77 * the calendar to match time periods or locations. GDate does not store 78 * time information; it represents a day. 79 * The GDate implementation has several nice features; it is only a 80 * 64-bit struct, so storing large numbers of dates is very efficient. It 81 * can keep both a Julian and day-month-year representation of the date, 82 * since some calculations are much easier with one representation or the 83 * other. A Julian representation is simply a count of days since some 84 * fixed day in the past; for GDate the fixed day is January 1, 1 AD. 85 * ("Julian" dates in the GDate API aren't really Julian dates in the 86 * technical sense; technically, Julian dates count from the start of the 87 * Julian period, Jan 1, 4713 BC). 88 * GDate is simple to use. First you need a "blank" date; you can get a 89 * dynamically allocated date from g_date_new(), or you can declare an 90 * automatic variable or array and initialize it to a sane state by 91 * calling g_date_clear(). A cleared date is sane; it's safe to call 92 * g_date_set_dmy() and the other mutator functions to initialize the 93 * value of a cleared date. However, a cleared date is initially 94 * invalid, meaning that it doesn't represent a day 95 * that exists. It is undefined to call any of the date calculation 96 * routines on an invalid date. If you obtain a date from a user or other 97 * unpredictable source, you should check its validity with the 98 * g_date_valid() predicate. g_date_valid() is also used to check for 99 * errors with g_date_set_parse() and other functions that can 100 * fail. Dates can be invalidated by calling g_date_clear() again. 101 * It is very important to use the API to access the GDate 102 * struct. Often only the day-month-year or only the Julian 103 * representation is valid. Sometimes neither is valid. Use the API. 104 * GLib also features GDateTime which represents a precise time. 105 */ 106 public class TimeVal 107 { 108 109 /** the main Gtk struct */ 110 protected GTimeVal* gTimeVal; 111 112 113 public GTimeVal* getTimeValStruct() 114 { 115 return gTimeVal; 116 } 117 118 119 /** the main Gtk struct as a void* */ 120 protected void* getStruct() 121 { 122 return cast(void*)gTimeVal; 123 } 124 125 /** 126 * Sets our main struct and passes it to the parent class 127 */ 128 public this (GTimeVal* gTimeVal) 129 { 130 this.gTimeVal = gTimeVal; 131 } 132 133 /** 134 */ 135 136 /** 137 * Equivalent to the UNIX gettimeofday() function, but portable. 138 * You may find g_get_real_time() to be more convenient. 139 */ 140 public void getCurrentTime() 141 { 142 // void g_get_current_time (GTimeVal *result); 143 g_get_current_time(gTimeVal); 144 } 145 146 /** 147 * Pauses the current thread for the given number of microseconds. There 148 * are 1 million microseconds per second (represented by the 149 * G_USEC_PER_SEC macro). g_usleep() may have limited precision, 150 * depending on hardware and operating system; don't rely on the exact 151 * length of the sleep. 152 * Params: 153 * microseconds = number of microseconds to pause 154 */ 155 public static void usleep(gulong microseconds) 156 { 157 // void g_usleep (gulong microseconds); 158 g_usleep(microseconds); 159 } 160 161 /** 162 * Adds the given number of microseconds to time_. microseconds can 163 * also be negative to decrease the value of time_. 164 * Params: 165 * microseconds = number of microseconds to add to time 166 */ 167 public void add(glong microseconds) 168 { 169 // void g_time_val_add (GTimeVal *time_, glong microseconds); 170 g_time_val_add(gTimeVal, microseconds); 171 } 172 173 /** 174 * Converts a string containing an ISO 8601 encoded date and time 175 * to a GTimeVal and puts it into time_. 176 * Since 2.12 177 * Params: 178 * isoDate = an ISO 8601 encoded date string 179 * time = a GTimeVal 180 * Returns: TRUE if the conversion was successful. 181 */ 182 public static int fromIso8601(string isoDate, GTimeVal* time) 183 { 184 // gboolean g_time_val_from_iso8601 (const gchar *iso_date, GTimeVal *time_); 185 return g_time_val_from_iso8601(Str.toStringz(isoDate), time); 186 } 187 188 /** 189 * Converts time_ into an ISO 8601 encoded string, relative to the 190 * Coordinated Universal Time (UTC). 191 * Since 2.12 192 * Returns: a newly allocated string containing an ISO 8601 date 193 */ 194 public string toIso8601() 195 { 196 // gchar * g_time_val_to_iso8601 (GTimeVal *time_); 197 return Str.toString(g_time_val_to_iso8601(gTimeVal)); 198 } 199 200 /** 201 * Queries the system monotonic time, if available. 202 * On POSIX systems with clock_gettime() and CLOCK_MONOTONIC this call 203 * is a very shallow wrapper for that. Otherwise, we make a best effort 204 * that probably involves returning the wall clock time (with at least 205 * microsecond accuracy, subject to the limitations of the OS kernel). 206 * Note that, on Windows, "limitations of the OS kernel" is a rather 207 * substantial statement. Depending on the configuration of the system, 208 * the wall clock time is updated as infrequently as 64 times a second 209 * (which is approximately every 16ms). 210 * Since 2.28 211 * Returns: the monotonic time, in microseconds 212 */ 213 public static long getMonotonicTime() 214 { 215 // gint64 g_get_monotonic_time (void); 216 return g_get_monotonic_time(); 217 } 218 219 /** 220 * Queries the system wall-clock time. 221 * This call is functionally equivalent to g_get_current_time() except 222 * that the return value is often more convenient than dealing with a 223 * GTimeVal. 224 * You should only use this call if you are actually interested in the real 225 * wall-clock time. g_get_monotonic_time() is probably more useful for 226 * measuring intervals. 227 * Since 2.28 228 * Returns: the number of microseconds since January 1, 1970 UTC. 229 */ 230 public static long getRealTime() 231 { 232 // gint64 g_get_real_time (void); 233 return g_get_real_time(); 234 } 235 }