source: appstream-generator/build/girepo/glib/TimeVal.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 5.9 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.TimeVal;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.Str;
26
27
28/**
29 * Represents a precise time, with seconds and microseconds.
30 * Similar to the struct timeval returned by the gettimeofday()
31 * UNIX system call.
32 *
33 * GLib is attempting to unify around the use of 64bit integers to
34 * represent microsecond-precision time. As such, this type will be
35 * removed from a future version of GLib.
36 */
37public class TimeVal
38{
39        /** the main Gtk struct */
40        protected GTimeVal* gTimeVal;
41        protected bool ownedRef;
42
43        /** Get the main Gtk struct */
44        public GTimeVal* getTimeValStruct()
45        {
46                return gTimeVal;
47        }
48
49        /** the main Gtk struct as a void* */
50        protected void* getStruct()
51        {
52                return cast(void*)gTimeVal;
53        }
54
55        /**
56         * Sets our main struct and passes it to the parent class.
57         */
58        public this (GTimeVal* gTimeVal, bool ownedRef = false)
59        {
60                this.gTimeVal = gTimeVal;
61                this.ownedRef = ownedRef;
62        }
63
64
65        /**
66         * Adds the given number of microseconds to @time_. @microseconds can
67         * also be negative to decrease the value of @time_.
68         *
69         * Params:
70         *     microseconds = number of microseconds to add to @time
71         */
72        public void add(glong microseconds)
73        {
74                g_time_val_add(gTimeVal, microseconds);
75        }
76
77        /**
78         * Converts @time_ into an RFC 3339 encoded string, relative to the
79         * Coordinated Universal Time (UTC). This is one of the many formats
80         * allowed by ISO 8601.
81         *
82         * ISO 8601 allows a large number of date/time formats, with or without
83         * punctuation and optional elements. The format returned by this function
84         * is a complete date and time, with optional punctuation included, the
85         * UTC time zone represented as "Z", and the @tv_usec part included if
86         * and only if it is nonzero, i.e. either
87         * "YYYY-MM-DDTHH:MM:SSZ" or "YYYY-MM-DDTHH:MM:SS.fffffZ".
88         *
89         * This corresponds to the Internet date/time format defined by
90         * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt),
91         * and to either of the two most-precise formats defined by
92         * the W3C Note
93         * [Date and Time Formats](http://www.w3.org/TR/NOTE-datetime-19980827).
94         * Both of these documents are profiles of ISO 8601.
95         *
96         * Use g_date_time_format() or g_strdup_printf() if a different
97         * variation of ISO 8601 format is required.
98         *
99         * Returns: a newly allocated string containing an ISO 8601 date
100         *
101         * Since: 2.12
102         */
103        public string toIso8601()
104        {
105                auto retStr = g_time_val_to_iso8601(gTimeVal);
106               
107                scope(exit) Str.freeString(retStr);
108                return Str.toString(retStr);
109        }
110
111        /**
112         * Converts a string containing an ISO 8601 encoded date and time
113         * to a #GTimeVal and puts it into @time_.
114         *
115         * @iso_date must include year, month, day, hours, minutes, and
116         * seconds. It can optionally include fractions of a second and a time
117         * zone indicator. (In the absence of any time zone indication, the
118         * timestamp is assumed to be in local time.)
119         *
120         * Params:
121         *     isoDate = an ISO 8601 encoded date string
122         *     time = a #GTimeVal
123         *
124         * Returns: %TRUE if the conversion was successful.
125         *
126         * Since: 2.12
127         */
128        public static bool fromIso8601(string isoDate, out TimeVal time)
129        {
130                GTimeVal* outtime = gMalloc!GTimeVal();
131               
132                auto p = g_time_val_from_iso8601(Str.toStringz(isoDate), outtime) != 0;
133               
134                time = new TimeVal(outtime, true);
135               
136                return p;
137        }
138
139        /**
140         * Equivalent to the UNIX gettimeofday() function, but portable.
141         *
142         * You may find g_get_real_time() to be more convenient.
143         *
144         * Params:
145         *     result = #GTimeVal structure in which to store current time.
146         */
147        public static void getCurrentTime(TimeVal result)
148        {
149                g_get_current_time((result is null) ? null : result.getTimeValStruct());
150        }
151
152        /**
153         * Queries the system monotonic time.
154         *
155         * The monotonic clock will always increase and doesn't suffer
156         * discontinuities when the user (or NTP) changes the system time.  It
157         * may or may not continue to tick during times where the machine is
158         * suspended.
159         *
160         * We try to use the clock that corresponds as closely as possible to
161         * the passage of time as measured by system calls such as poll() but it
162         * may not always be possible to do this.
163         *
164         * Returns: the monotonic time, in microseconds
165         *
166         * Since: 2.28
167         */
168        public static long getMonotonicTime()
169        {
170                return g_get_monotonic_time();
171        }
172
173        /**
174         * Queries the system wall-clock time.
175         *
176         * This call is functionally equivalent to g_get_current_time() except
177         * that the return value is often more convenient than dealing with a
178         * #GTimeVal.
179         *
180         * You should only use this call if you are actually interested in the real
181         * wall-clock time.  g_get_monotonic_time() is probably more useful for
182         * measuring intervals.
183         *
184         * Returns: the number of microseconds since January 1, 1970 UTC.
185         *
186         * Since: 2.28
187         */
188        public static long getRealTime()
189        {
190                return g_get_real_time();
191        }
192
193        /**
194         * Pauses the current thread for the given number of microseconds.
195         *
196         * There are 1 million microseconds per second (represented by the
197         * #G_USEC_PER_SEC macro). g_usleep() may have limited precision,
198         * depending on hardware and operating system; don't rely on the exact
199         * length of the sleep.
200         *
201         * Params:
202         *     microseconds = number of microseconds to pause
203         */
204        public static void usleep(gulong microseconds)
205        {
206                g_usleep(microseconds);
207        }
208}
Note: See TracBrowser for help on using the repository browser.