PageRenderTime 91ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/generated/gtkd/glib/TimeVal.d

http://github.com/gtkd-developers/GtkD
D | 293 lines | 81 code | 26 blank | 186 comment | 4 complexity | e31c12fdf8f3bae4240400885fef57bf MD5 | raw file
Possible License(s): LGPL-3.0
  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. // generated automatically - do not change
  20. // find conversion definition on APILookup.txt
  21. // implement new conversion functionalities on the wrap.utils pakage
  22. module glib.TimeVal;
  23. private import glib.MemorySlice;
  24. private import glib.Str;
  25. private import glib.c.functions;
  26. public import glib.c.types;
  27. public import gtkc.glibtypes;
  28. private import gtkd.Loader;
  29. /**
  30. * Represents a precise time, with seconds and microseconds.
  31. *
  32. * Similar to the struct timeval returned by the `gettimeofday()`
  33. * UNIX system call.
  34. *
  35. * GLib is attempting to unify around the use of 64-bit integers to
  36. * represent microsecond-precision time. As such, this type will be
  37. * removed from a future version of GLib. A consequence of using `glong` for
  38. * `tv_sec` is that on 32-bit systems `GTimeVal` is subject to the year 2038
  39. * problem.
  40. *
  41. * Deprecated: Use #GDateTime or #guint64 instead.
  42. */
  43. public final class TimeVal
  44. {
  45. /** the main Gtk struct */
  46. protected GTimeVal* gTimeVal;
  47. protected bool ownedRef;
  48. /** Get the main Gtk struct */
  49. public GTimeVal* getTimeValStruct(bool transferOwnership = false)
  50. {
  51. if (transferOwnership)
  52. ownedRef = false;
  53. return gTimeVal;
  54. }
  55. /** the main Gtk struct as a void* */
  56. protected void* getStruct()
  57. {
  58. return cast(void*)gTimeVal;
  59. }
  60. /**
  61. * Sets our main struct and passes it to the parent class.
  62. */
  63. public this (GTimeVal* gTimeVal, bool ownedRef = false)
  64. {
  65. this.gTimeVal = gTimeVal;
  66. this.ownedRef = ownedRef;
  67. }
  68. ~this ()
  69. {
  70. if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
  71. sliceFree(gTimeVal);
  72. }
  73. /**
  74. * seconds
  75. */
  76. public @property glong tvSec()
  77. {
  78. return gTimeVal.tvSec;
  79. }
  80. /** Ditto */
  81. public @property void tvSec(glong value)
  82. {
  83. gTimeVal.tvSec = value;
  84. }
  85. /**
  86. * microseconds
  87. */
  88. public @property glong tvUsec()
  89. {
  90. return gTimeVal.tvUsec;
  91. }
  92. /** Ditto */
  93. public @property void tvUsec(glong value)
  94. {
  95. gTimeVal.tvUsec = value;
  96. }
  97. /**
  98. * Adds the given number of microseconds to @time_. @microseconds can
  99. * also be negative to decrease the value of @time_.
  100. *
  101. * Deprecated: #GTimeVal is not year-2038-safe. Use `guint64` for
  102. * representing microseconds since the epoch, or use #GDateTime.
  103. *
  104. * Params:
  105. * microseconds = number of microseconds to add to @time
  106. */
  107. public void add(glong microseconds)
  108. {
  109. g_time_val_add(gTimeVal, microseconds);
  110. }
  111. /**
  112. * Converts @time_ into an RFC 3339 encoded string, relative to the
  113. * Coordinated Universal Time (UTC). This is one of the many formats
  114. * allowed by ISO 8601.
  115. *
  116. * ISO 8601 allows a large number of date/time formats, with or without
  117. * punctuation and optional elements. The format returned by this function
  118. * is a complete date and time, with optional punctuation included, the
  119. * UTC time zone represented as "Z", and the @tv_usec part included if
  120. * and only if it is nonzero, i.e. either
  121. * "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS.fffffZ".
  122. *
  123. * This corresponds to the Internet date/time format defined by
  124. * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt),
  125. * and to either of the two most-precise formats defined by
  126. * the W3C Note
  127. * [Date and Time Formats](http://www.w3.org/TR/NOTE-datetime-19980827).
  128. * Both of these documents are profiles of ISO 8601.
  129. *
  130. * Use g_date_time_format() or g_strdup_printf() if a different
  131. * variation of ISO 8601 format is required.
  132. *
  133. * If @time_ represents a date which is too large to fit into a `struct tm`,
  134. * %NULL will be returned. This is platform dependent. Note also that since
  135. * `GTimeVal` stores the number of seconds as a `glong`, on 32-bit systems it
  136. * is subject to the year 2038 problem. Accordingly, since GLib 2.62, this
  137. * function has been deprecated. Equivalent functionality is available using:
  138. * |[
  139. * GDateTime *dt = g_date_time_new_from_unix_utc (time_val);
  140. * iso8601_string = g_date_time_format_iso8601 (dt);
  141. * g_date_time_unref (dt);
  142. * ]|
  143. *
  144. * The return value of g_time_val_to_iso8601() has been nullable since GLib
  145. * 2.54; before then, GLib would crash under the same conditions.
  146. *
  147. * Deprecated: #GTimeVal is not year-2038-safe. Use
  148. * g_date_time_format_iso8601(dt) instead.
  149. *
  150. * Returns: a newly allocated string containing an ISO 8601 date,
  151. * or %NULL if @time_ was too large
  152. *
  153. * Since: 2.12
  154. */
  155. public string toIso8601()
  156. {
  157. auto retStr = g_time_val_to_iso8601(gTimeVal);
  158. scope(exit) Str.freeString(retStr);
  159. return Str.toString(retStr);
  160. }
  161. /**
  162. * Converts a string containing an ISO 8601 encoded date and time
  163. * to a #GTimeVal and puts it into @time_.
  164. *
  165. * @iso_date must include year, month, day, hours, minutes, and
  166. * seconds. It can optionally include fractions of a second and a time
  167. * zone indicator. (In the absence of any time zone indication, the
  168. * timestamp is assumed to be in local time.)
  169. *
  170. * Any leading or trailing space in @iso_date is ignored.
  171. *
  172. * This function was deprecated, along with #GTimeVal itself, in GLib 2.62.
  173. * Equivalent functionality is available using code like:
  174. * |[
  175. * GDateTime *dt = g_date_time_new_from_iso8601 (iso8601_string, NULL);
  176. * gint64 time_val = g_date_time_to_unix (dt);
  177. * g_date_time_unref (dt);
  178. * ]|
  179. *
  180. * Deprecated: #GTimeVal is not year-2038-safe. Use
  181. * g_date_time_new_from_iso8601() instead.
  182. *
  183. * Params:
  184. * isoDate = an ISO 8601 encoded date string
  185. * time = a #GTimeVal
  186. *
  187. * Returns: %TRUE if the conversion was successful.
  188. *
  189. * Since: 2.12
  190. */
  191. public static bool fromIso8601(string isoDate, out TimeVal time)
  192. {
  193. GTimeVal* outtime = sliceNew!GTimeVal();
  194. auto __p = g_time_val_from_iso8601(Str.toStringz(isoDate), outtime) != 0;
  195. time = new TimeVal(outtime, true);
  196. return __p;
  197. }
  198. /**
  199. * Equivalent to the UNIX gettimeofday() function, but portable.
  200. *
  201. * You may find g_get_real_time() to be more convenient.
  202. *
  203. * Deprecated: #GTimeVal is not year-2038-safe. Use g_get_real_time()
  204. * instead.
  205. *
  206. * Params:
  207. * result = #GTimeVal structure in which to store current time.
  208. */
  209. public static void getCurrentTime(TimeVal result)
  210. {
  211. g_get_current_time((result is null) ? null : result.getTimeValStruct());
  212. }
  213. /**
  214. * Queries the system monotonic time.
  215. *
  216. * The monotonic clock will always increase and doesn't suffer
  217. * discontinuities when the user (or NTP) changes the system time. It
  218. * may or may not continue to tick during times where the machine is
  219. * suspended.
  220. *
  221. * We try to use the clock that corresponds as closely as possible to
  222. * the passage of time as measured by system calls such as poll() but it
  223. * may not always be possible to do this.
  224. *
  225. * Returns: the monotonic time, in microseconds
  226. *
  227. * Since: 2.28
  228. */
  229. public static long getMonotonicTime()
  230. {
  231. return g_get_monotonic_time();
  232. }
  233. /**
  234. * Queries the system wall-clock time.
  235. *
  236. * This call is functionally equivalent to g_get_current_time() except
  237. * that the return value is often more convenient than dealing with a
  238. * #GTimeVal.
  239. *
  240. * You should only use this call if you are actually interested in the real
  241. * wall-clock time. g_get_monotonic_time() is probably more useful for
  242. * measuring intervals.
  243. *
  244. * Returns: the number of microseconds since January 1, 1970 UTC.
  245. *
  246. * Since: 2.28
  247. */
  248. public static long getRealTime()
  249. {
  250. return g_get_real_time();
  251. }
  252. /**
  253. * Pauses the current thread for the given number of microseconds.
  254. *
  255. * There are 1 million microseconds per second (represented by the
  256. * %G_USEC_PER_SEC macro). g_usleep() may have limited precision,
  257. * depending on hardware and operating system; don't rely on the exact
  258. * length of the sleep.
  259. *
  260. * Params:
  261. * microseconds = number of microseconds to pause
  262. */
  263. public static void usleep(gulong microseconds)
  264. {
  265. g_usleep(microseconds);
  266. }
  267. }