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 = 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 * The GDate data structure represents a day between January 1, Year 1, 70 * and sometime a few thousand years in the future (right now it will go 71 * to the year 65535 or so, but g_date_set_parse() only parses up to the 72 * year 8000 or so - just count on "a few thousand"). GDate is meant to 73 * represent everyday dates, not astronomical dates or historical dates 74 * or ISO timestamps or the like. It extrapolates the current Gregorian 75 * calendar forward and backward in time; there is no attempt to change 76 * the calendar to match time periods or locations. GDate does not store 77 * time information; it represents a day. 78 * 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 * 89 * GDate is simple to use. First you need a "blank" date; you can get a 90 * dynamically allocated date from g_date_new(), or you can declare an 91 * automatic variable or array and initialize it to a sane state by 92 * calling g_date_clear(). A cleared date is sane; it's safe to call 93 * g_date_set_dmy() and the other mutator functions to initialize the 94 * value of a cleared date. However, a cleared date is initially 95 * invalid, meaning that it doesn't represent a day 96 * that exists. It is undefined to call any of the date calculation 97 * routines on an invalid date. If you obtain a date from a user or other 98 * unpredictable source, you should check its validity with the 99 * g_date_valid() predicate. g_date_valid() is also used to check for 100 * errors with g_date_set_parse() and other functions that can 101 * fail. Dates can be invalidated by calling g_date_clear() again. 102 * 103 * It is very important to use the API to access the GDate 104 * struct. Often only the day-month-year or only the Julian 105 * representation is valid. Sometimes neither is valid. Use the API. 106 * 107 * GLib also features GDateTime which represents a precise time. 108 */ 109 public class TimeVal 110 { 111 112 /** 113 */ 114 115 /** 116 * Equivalent to the UNIX gettimeofday() function, but portable. 117 * You may find g_get_real_time() to be more convenient. 118 * Params: 119 * result = GTimeVal structure in which to store current time. 120 */ 121 public static void getCurrentTime(out GTimeVal result) 122 { 123 // void g_get_current_time (GTimeVal *result); 124 g_get_current_time(&result); 125 } 126 127 /** 128 * Pauses the current thread for the given number of microseconds. 129 * There are 1 million microseconds per second (represented by the 130 * G_USEC_PER_SEC macro). g_usleep() may have limited precision, 131 * depending on hardware and operating system; don't rely on the exact 132 * length of the sleep. 133 * Params: 134 * microseconds = number of microseconds to pause 135 */ 136 public static void usleep(gulong microseconds) 137 { 138 // void g_usleep (gulong microseconds); 139 g_usleep(microseconds); 140 } 141 142 /** 143 * Adds the given number of microseconds to time_. microseconds can 144 * also be negative to decrease the value of time_. 145 * Params: 146 * time = a GTimeVal 147 * microseconds = number of microseconds to add to time 148 */ 149 public static void add(ref GTimeVal time, glong microseconds) 150 { 151 // void g_time_val_add (GTimeVal *time_, glong microseconds); 152 g_time_val_add(&time, microseconds); 153 } 154 155 /** 156 * Converts a string containing an ISO 8601 encoded date and time 157 * to a GTimeVal and puts it into time_. 158 * iso_date must include year, month, day, hours, minutes, and 159 * seconds. It can optionally include fractions of a second and a time 160 * zone indicator. (In the absence of any time zone indication, the 161 * timestamp is assumed to be in local time.) 162 * Since 2.12 163 * Params: 164 * isoDate = an ISO 8601 encoded date string 165 * time = a GTimeVal. [out] 166 * Returns: TRUE if the conversion was successful. 167 */ 168 public static int fromIso8601(string isoDate, out GTimeVal time) 169 { 170 // gboolean g_time_val_from_iso8601 (const gchar *iso_date, GTimeVal *time_); 171 return g_time_val_from_iso8601(Str.toStringz(isoDate), &time); 172 } 173 174 /** 175 * Converts time_ into an RFC 3339 encoded string, relative to the 176 * Coordinated Universal Time (UTC). This is one of the many formats 177 * allowed by ISO 8601. 178 * ISO 8601 allows a large number of date/time formats, with or without 179 * punctuation and optional elements. The format returned by this function 180 * is a complete date and time, with optional punctuation included, the 181 * UTC time zone represented as "Z", and the tv_usec part included if 182 * and only if it is nonzero, i.e. either 183 * "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS.fffffZ". 184 * This corresponds to the Internet date/time format defined by 185 * RFC 3339, and 186 * to either of the two most-precise formats defined by 187 * the W3C Note 188 * "Date and Time Formats". Both of these documents are profiles of 189 * ISO 8601. 190 * Use g_date_time_format() or g_strdup_printf() if a different 191 * variation of ISO 8601 format is required. 192 * Since 2.12 193 * Params: 194 * time = a GTimeVal 195 * Returns: a newly allocated string containing an ISO 8601 date 196 */ 197 public static string toIso8601(ref GTimeVal time) 198 { 199 // gchar * g_time_val_to_iso8601 (GTimeVal *time_); 200 return Str.toString(g_time_val_to_iso8601(&time)); 201 } 202 203 /** 204 * Queries the system monotonic time, if available. 205 * On POSIX systems with clock_gettime() and CLOCK_MONOTONIC this call 206 * is a very shallow wrapper for that. Otherwise, we make a best effort 207 * that probably involves returning the wall clock time (with at least 208 * microsecond accuracy, subject to the limitations of the OS kernel). 209 * It's important to note that POSIX CLOCK_MONOTONIC does 210 * not count time spent while the machine is suspended. 211 * On Windows, "limitations of the OS kernel" is a rather substantial 212 * statement. Depending on the configuration of the system, the wall 213 * clock time is updated as infrequently as 64 times a second (which 214 * is approximately every 16ms). Also, on XP (but not on Vista or later) 215 * the monotonic clock is locally monotonic, but may differ in exact 216 * value between processes due to timer wrap handling. 217 * Since 2.28 218 * Returns: the monotonic time, in microseconds 219 */ 220 public static long getMonotonicTime() 221 { 222 // gint64 g_get_monotonic_time (void); 223 return g_get_monotonic_time(); 224 } 225 226 /** 227 * Queries the system wall-clock time. 228 * This call is functionally equivalent to g_get_current_time() except 229 * that the return value is often more convenient than dealing with a 230 * GTimeVal. 231 * You should only use this call if you are actually interested in the real 232 * wall-clock time. g_get_monotonic_time() is probably more useful for 233 * measuring intervals. 234 * Since 2.28 235 * Returns: the number of microseconds since January 1, 1970 UTC. 236 */ 237 public static long getRealTime() 238 { 239 // gint64 g_get_real_time (void); 240 return g_get_real_time(); 241 } 242 }