PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/generated/gtkd/glib/TimeVal.d

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