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