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 module glib.TimeVal; 26 27 private import glib.Str; 28 private import gtkc.glib; 29 public import gtkc.glibtypes; 30 31 32 /** 33 * Represents a precise time, with seconds and microseconds. 34 * Similar to the struct timeval returned by the gettimeofday() 35 * UNIX system call. 36 * 37 * GLib is attempting to unify around the use of 64bit integers to 38 * represent microsecond-precision time. As such, this type will be 39 * removed from a future version of GLib. 40 */ 41 public class TimeVal 42 { 43 /** the main Gtk struct */ 44 protected GTimeVal* gTimeVal; 45 46 /** Get the main Gtk struct */ 47 public GTimeVal* getTimeValStruct() 48 { 49 return gTimeVal; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gTimeVal; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GTimeVal* gTimeVal) 62 { 63 this.gTimeVal = gTimeVal; 64 } 65 66 67 /** 68 * Adds the given number of microseconds to @time_. @microseconds can 69 * also be negative to decrease the value of @time_. 70 * 71 * Params: 72 * microseconds = number of microseconds to add to @time 73 */ 74 public void add(glong microseconds) 75 { 76 g_time_val_add(gTimeVal, microseconds); 77 } 78 79 /** 80 * Converts @time_ into an RFC 3339 encoded string, relative to the 81 * Coordinated Universal Time (UTC). This is one of the many formats 82 * allowed by ISO 8601. 83 * 84 * ISO 8601 allows a large number of date/time formats, with or without 85 * punctuation and optional elements. The format returned by this function 86 * is a complete date and time, with optional punctuation included, the 87 * UTC time zone represented as "Z", and the @tv_usec part included if 88 * and only if it is nonzero, i.e. either 89 * "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS.fffffZ". 90 * 91 * This corresponds to the Internet date/time format defined by 92 * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt), 93 * and to either of the two most-precise formats defined by 94 * the W3C Note 95 * [Date and Time Formats](http://www.w3.org/TR/NOTE-datetime-19980827). 96 * Both of these documents are profiles of ISO 8601. 97 * 98 * Use g_date_time_format() or g_strdup_printf() if a different 99 * variation of ISO 8601 format is required. 100 * 101 * Return: a newly allocated string containing an ISO 8601 date 102 * 103 * Since: 2.12 104 */ 105 public string toIso8601() 106 { 107 return Str.toString(g_time_val_to_iso8601(gTimeVal)); 108 } 109 110 /** 111 * Converts a string containing an ISO 8601 encoded date and time 112 * to a #GTimeVal and puts it into @time_. 113 * 114 * @iso_date must include year, month, day, hours, minutes, and 115 * seconds. It can optionally include fractions of a second and a time 116 * zone indicator. (In the absence of any time zone indication, the 117 * timestamp is assumed to be in local time.) 118 * 119 * Params: 120 * isoDate = an ISO 8601 encoded date string 121 * time = a #GTimeVal 122 * 123 * Return: %TRUE if the conversion was successful. 124 * 125 * Since: 2.12 126 */ 127 public static bool fromIso8601(string isoDate, out TimeVal time) 128 { 129 GTimeVal* outtime = gMalloc!GTimeVal(); 130 131 auto p = g_time_val_from_iso8601(Str.toStringz(isoDate), outtime) != 0; 132 133 time = new TimeVal(outtime); 134 135 return p; 136 } 137 138 /** 139 * Equivalent to the UNIX gettimeofday() function, but portable. 140 * 141 * You may find g_get_real_time() to be more convenient. 142 * 143 * Params: 144 * result = #GTimeVal structure in which to store current time. 145 */ 146 public static void getCurrentTime(TimeVal result) 147 { 148 g_get_current_time((result is null) ? null : result.getTimeValStruct()); 149 } 150 151 /** 152 * Queries the system monotonic time. 153 * 154 * The monotonic clock will always increase and doesn't suffer 155 * discontinuities when the user (or NTP) changes the system time. It 156 * may or may not continue to tick during times where the machine is 157 * suspended. 158 * 159 * We try to use the clock that corresponds as closely as possible to 160 * the passage of time as measured by system calls such as poll() but it 161 * may not always be possible to do this. 162 * 163 * Return: the monotonic time, in microseconds 164 * 165 * Since: 2.28 166 */ 167 public static long getMonotonicTime() 168 { 169 return g_get_monotonic_time(); 170 } 171 172 /** 173 * Queries the system wall-clock time. 174 * 175 * This call is functionally equivalent to g_get_current_time() except 176 * that the return value is often more convenient than dealing with a 177 * #GTimeVal. 178 * 179 * You should only use this call if you are actually interested in the real 180 * wall-clock time. g_get_monotonic_time() is probably more useful for 181 * measuring intervals. 182 * 183 * Return: the number of microseconds since January 1, 1970 UTC. 184 * 185 * Since: 2.28 186 */ 187 public static long getRealTime() 188 { 189 return g_get_real_time(); 190 } 191 192 /** 193 * Pauses the current thread for the given number of microseconds. 194 * 195 * There are 1 million microseconds per second (represented by the 196 * #G_USEC_PER_SEC macro). g_usleep() may have limited precision, 197 * depending on hardware and operating system; don't rely on the exact 198 * length of the sleep. 199 * 200 * Params: 201 * microseconds = number of microseconds to pause 202 */ 203 public static void usleep(gulong microseconds) 204 { 205 g_usleep(microseconds); 206 } 207 }