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  * Conversion parameters:
26  * inFile  = glib-Date-and-Time-Functions.html
27  * outPack = glib
28  * outFile = TimeVal
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = TimeVal
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_time_val_
41  * 	- g_
42  * omit structs:
43  * omit prefixes:
44  * 	- g_date_
45  * omit code:
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * structWrap:
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.TimeVal;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 private import glib.Str;
63 
64 
65 
66 /**
67  * The GDate data structure represents a day between January 1, Year 1,
68  * and sometime a few thousand years in the future (right now it will go
69  * to the year 65535 or so, but g_date_set_parse() only parses up to the
70  * year 8000 or so - just count on "a few thousand"). GDate is meant to
71  * represent everyday dates, not astronomical dates or historical dates
72  * or ISO timestamps or the like. It extrapolates the current Gregorian
73  * calendar forward and backward in time; there is no attempt to change
74  * the calendar to match time periods or locations. GDate does not store
75  * time information; it represents a day.
76  *
77  * The GDate implementation has several nice features; it is only a
78  * 64-bit struct, so storing large numbers of dates is very efficient. It
79  * can keep both a Julian and day-month-year representation of the date,
80  * since some calculations are much easier with one representation or the
81  * other. A Julian representation is simply a count of days since some
82  * fixed day in the past; for GDate the fixed day is January 1, 1 AD.
83  * ("Julian" dates in the GDate API aren't really Julian dates in the
84  * technical sense; technically, Julian dates count from the start of the
85  * Julian period, Jan 1, 4713 BC).
86  *
87  * GDate is simple to use. First you need a "blank" date; you can get a
88  * dynamically allocated date from g_date_new(), or you can declare an
89  * automatic variable or array and initialize it to a sane state by
90  * calling g_date_clear(). A cleared date is sane; it's safe to call
91  * g_date_set_dmy() and the other mutator functions to initialize the
92  * value of a cleared date. However, a cleared date is initially
93  * invalid, meaning that it doesn't represent a day
94  * that exists. It is undefined to call any of the date calculation
95  * routines on an invalid date. If you obtain a date from a user or other
96  * unpredictable source, you should check its validity with the
97  * g_date_valid() predicate. g_date_valid() is also used to check for
98  * errors with g_date_set_parse() and other functions that can
99  * fail. Dates can be invalidated by calling g_date_clear() again.
100  *
101  * It is very important to use the API to access the GDate
102  * struct. Often only the day-month-year or only the Julian
103  * representation is valid. Sometimes neither is valid. Use the API.
104  *
105  * GLib also features GDateTime which represents a precise time.
106  */
107 public class TimeVal
108 {
109 	
110 	/**
111 	 */
112 	
113 	/**
114 	 * Equivalent to the UNIX gettimeofday() function, but portable.
115 	 * You may find g_get_real_time() to be more convenient.
116 	 * Params:
117 	 * result = GTimeVal structure in which to store current time.
118 	 */
119 	public static void getCurrentTime(out GTimeVal result)
120 	{
121 		// void g_get_current_time (GTimeVal *result);
122 		g_get_current_time(&result);
123 	}
124 	
125 	/**
126 	 * Pauses the current thread for the given number of microseconds.
127 	 * There are 1 million microseconds per second (represented by the
128 	 * G_USEC_PER_SEC macro). g_usleep() may have limited precision,
129 	 * depending on hardware and operating system; don't rely on the exact
130 	 * length of the sleep.
131 	 * Params:
132 	 * microseconds = number of microseconds to pause
133 	 */
134 	public static void usleep(gulong microseconds)
135 	{
136 		// void g_usleep (gulong microseconds);
137 		g_usleep(microseconds);
138 	}
139 	
140 	/**
141 	 * Adds the given number of microseconds to time_. microseconds can
142 	 * also be negative to decrease the value of time_.
143 	 * Params:
144 	 * time = a GTimeVal
145 	 * microseconds = number of microseconds to add to time
146 	 */
147 	public static void add(ref GTimeVal time, glong microseconds)
148 	{
149 		// void g_time_val_add (GTimeVal *time_,  glong microseconds);
150 		g_time_val_add(&time, microseconds);
151 	}
152 	
153 	/**
154 	 * Converts a string containing an ISO 8601 encoded date and time
155 	 * to a GTimeVal and puts it into time_.
156 	 * iso_date must include year, month, day, hours, minutes, and
157 	 * seconds. It can optionally include fractions of a second and a time
158 	 * zone indicator. (In the absence of any time zone indication, the
159 	 * timestamp is assumed to be in local time.)
160 	 * Since 2.12
161 	 * Params:
162 	 * isoDate = an ISO 8601 encoded date string
163 	 * time = a GTimeVal. [out]
164 	 * Returns: TRUE if the conversion was successful.
165 	 */
166 	public static int fromIso8601(string isoDate, out GTimeVal time)
167 	{
168 		// gboolean g_time_val_from_iso8601 (const gchar *iso_date,  GTimeVal *time_);
169 		return g_time_val_from_iso8601(Str.toStringz(isoDate), &time);
170 	}
171 	
172 	/**
173 	 * Converts time_ into an RFC 3339 encoded string, relative to the
174 	 * Coordinated Universal Time (UTC). This is one of the many formats
175 	 * allowed by ISO 8601.
176 	 * ISO 8601 allows a large number of date/time formats, with or without
177 	 * punctuation and optional elements. The format returned by this function
178 	 * is a complete date and time, with optional punctuation included, the
179 	 * UTC time zone represented as "Z", and the tv_usec part included if
180 	 * and only if it is nonzero, i.e. either
181 	 * "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS.fffffZ".
182 	 * This corresponds to the Internet date/time format defined by
183 	 * RFC 3339, and
184 	 * to either of the two most-precise formats defined by
185 	 * the W3C Note
186 	 * "Date and Time Formats". Both of these documents are profiles of
187 	 * ISO 8601.
188 	 * Use g_date_time_format() or g_strdup_printf() if a different
189 	 * variation of ISO 8601 format is required.
190 	 * Since 2.12
191 	 * Params:
192 	 * time = a GTimeVal
193 	 * Returns: a newly allocated string containing an ISO 8601 date
194 	 */
195 	public static string toIso8601(ref GTimeVal time)
196 	{
197 		// gchar * g_time_val_to_iso8601 (GTimeVal *time_);
198 		return Str.toString(g_time_val_to_iso8601(&time));
199 	}
200 	
201 	/**
202 	 * Queries the system monotonic time, if available.
203 	 * On POSIX systems with clock_gettime() and CLOCK_MONOTONIC this call
204 	 * is a very shallow wrapper for that. Otherwise, we make a best effort
205 	 * that probably involves returning the wall clock time (with at least
206 	 * microsecond accuracy, subject to the limitations of the OS kernel).
207 	 * It's important to note that POSIX CLOCK_MONOTONIC does
208 	 * not count time spent while the machine is suspended.
209 	 * On Windows, "limitations of the OS kernel" is a rather substantial
210 	 * statement. Depending on the configuration of the system, the wall
211 	 * clock time is updated as infrequently as 64 times a second (which
212 	 * is approximately every 16ms). Also, on XP (but not on Vista or later)
213 	 * the monotonic clock is locally monotonic, but may differ in exact
214 	 * value between processes due to timer wrap handling.
215 	 * Since 2.28
216 	 * Returns: the monotonic time, in microseconds
217 	 */
218 	public static long getMonotonicTime()
219 	{
220 		// gint64 g_get_monotonic_time (void);
221 		return g_get_monotonic_time();
222 	}
223 	
224 	/**
225 	 * Queries the system wall-clock time.
226 	 * This call is functionally equivalent to g_get_current_time() except
227 	 * that the return value is often more convenient than dealing with a
228 	 * GTimeVal.
229 	 * You should only use this call if you are actually interested in the real
230 	 * wall-clock time. g_get_monotonic_time() is probably more useful for
231 	 * measuring intervals.
232 	 * Since 2.28
233 	 * Returns: the number of microseconds since January 1, 1970 UTC.
234 	 */
235 	public static long getRealTime()
236 	{
237 		// gint64 g_get_real_time (void);
238 		return g_get_real_time();
239 	}
240 }