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