2 * Copyright (C) 2009-2010 Christian Hergert <chris@dronelabs.com>
3 * Copyright © 2010 Codethink Limited
5 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of the
10 * licence, or (at your option) any later version.
12 * This is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Authors: Christian Hergert <chris@dronelabs.com>
21 * Thiago Santos <thiago.sousa.santos@collabora.co.uk>
22 * Emmanuele Bassi <ebassi@linux.intel.com>
23 * Ryan Lortie <desrt@desrt.ca>
26 #ifndef __G_DATE_TIME_H__
27 #define __G_DATE_TIME_H__
29 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
30 #error "Only <glib.h> can be included directly."
33 #include <glib/gtimezone.h>
40 * Evaluates to a time span of one day.
44 #define G_TIME_SPAN_DAY (G_GINT64_CONSTANT (86400000000))
49 * Evaluates to a time span of one hour.
53 #define G_TIME_SPAN_HOUR (G_GINT64_CONSTANT (3600000000))
58 * Evaluates to a time span of one minute.
62 #define G_TIME_SPAN_MINUTE (G_GINT64_CONSTANT (60000000))
67 * Evaluates to a time span of one second.
71 #define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT (1000000))
74 * G_TIME_SPAN_MILLISECOND:
76 * Evaluates to a time span of one millisecond.
80 #define G_TIME_SPAN_MILLISECOND (G_GINT64_CONSTANT (1000))
85 * A value representing an interval of time, in microseconds.
89 typedef gint64 GTimeSpan;
94 * `GDateTime` is a structure that combines a Gregorian date and time
95 * into a single structure.
97 * `GDateTime` provides many conversion and methods to manipulate dates and times.
98 * Time precision is provided down to microseconds and the time can range
99 * (proleptically) from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999.
100 * `GDateTime` follows POSIX time in the sense that it is oblivious to leap
103 * `GDateTime` is an immutable object; once it has been created it cannot
104 * be modified further. All modifiers will create a new `GDateTime`.
105 * Nearly all such functions can fail due to the date or time going out
106 * of range, in which case %NULL will be returned.
108 * `GDateTime` is reference counted: the reference count is increased by calling
109 * [method@GLib.DateTime.ref] and decreased by calling [method@GLib.DateTime.unref].
110 * When the reference count drops to 0, the resources allocated by the `GDateTime`
111 * structure are released.
113 * Many parts of the API may produce non-obvious results. As an
114 * example, adding two months to January 31st will yield March 31st
115 * whereas adding one month and then one month again will yield either
116 * March 28th or March 29th. Also note that adding 24 hours is not
117 * always the same as adding one day (since days containing daylight
118 * savings time transitions are either 23 or 25 hours in length).
122 typedef struct _GDateTime GDateTime;
124 GLIB_AVAILABLE_IN_ALL
125 void g_date_time_unref (GDateTime *datetime);
126 GLIB_AVAILABLE_IN_ALL
127 GDateTime * g_date_time_ref (GDateTime *datetime);
129 GLIB_AVAILABLE_IN_ALL
130 GDateTime * g_date_time_new_now (GTimeZone *tz);
131 GLIB_AVAILABLE_IN_ALL
132 GDateTime * g_date_time_new_now_local (void);
133 GLIB_AVAILABLE_IN_ALL
134 GDateTime * g_date_time_new_now_utc (void);
136 GLIB_AVAILABLE_IN_ALL
137 GDateTime * g_date_time_new_from_unix_local (gint64 t);
138 GLIB_AVAILABLE_IN_ALL
139 GDateTime * g_date_time_new_from_unix_utc (gint64 t);
141 GLIB_AVAILABLE_IN_2_80
142 GDateTime * g_date_time_new_from_unix_local_usec (gint64 usecs);
143 GLIB_AVAILABLE_IN_2_80
144 GDateTime * g_date_time_new_from_unix_utc_usec (gint64 usecs);
146 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
147 GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_local)
148 GDateTime * g_date_time_new_from_timeval_local (const GTimeVal *tv);
149 GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_utc)
150 GDateTime * g_date_time_new_from_timeval_utc (const GTimeVal *tv);
151 G_GNUC_END_IGNORE_DEPRECATIONS
153 GLIB_AVAILABLE_IN_2_56
154 GDateTime * g_date_time_new_from_iso8601 (const gchar *text,
155 GTimeZone *default_tz);
157 GLIB_AVAILABLE_IN_ALL
158 GDateTime * g_date_time_new (GTimeZone *tz,
165 GLIB_AVAILABLE_IN_ALL
166 GDateTime * g_date_time_new_local (gint year,
172 GLIB_AVAILABLE_IN_ALL
173 GDateTime * g_date_time_new_utc (gint year,
180 GLIB_AVAILABLE_IN_ALL
181 G_GNUC_WARN_UNUSED_RESULT
182 GDateTime * g_date_time_add (GDateTime *datetime,
185 GLIB_AVAILABLE_IN_ALL
186 G_GNUC_WARN_UNUSED_RESULT
187 GDateTime * g_date_time_add_years (GDateTime *datetime,
189 GLIB_AVAILABLE_IN_ALL
190 G_GNUC_WARN_UNUSED_RESULT
191 GDateTime * g_date_time_add_months (GDateTime *datetime,
193 GLIB_AVAILABLE_IN_ALL
194 G_GNUC_WARN_UNUSED_RESULT
195 GDateTime * g_date_time_add_weeks (GDateTime *datetime,
197 GLIB_AVAILABLE_IN_ALL
198 G_GNUC_WARN_UNUSED_RESULT
199 GDateTime * g_date_time_add_days (GDateTime *datetime,
202 GLIB_AVAILABLE_IN_ALL
203 G_GNUC_WARN_UNUSED_RESULT
204 GDateTime * g_date_time_add_hours (GDateTime *datetime,
206 GLIB_AVAILABLE_IN_ALL
207 G_GNUC_WARN_UNUSED_RESULT
208 GDateTime * g_date_time_add_minutes (GDateTime *datetime,
210 GLIB_AVAILABLE_IN_ALL
211 G_GNUC_WARN_UNUSED_RESULT
212 GDateTime * g_date_time_add_seconds (GDateTime *datetime,
215 GLIB_AVAILABLE_IN_ALL
216 G_GNUC_WARN_UNUSED_RESULT
217 GDateTime * g_date_time_add_full (GDateTime *datetime,
225 GLIB_AVAILABLE_IN_ALL
226 gint g_date_time_compare (gconstpointer dt1,
228 GLIB_AVAILABLE_IN_ALL
229 GTimeSpan g_date_time_difference (GDateTime *end,
231 GLIB_AVAILABLE_IN_ALL
232 guint g_date_time_hash (gconstpointer datetime);
233 GLIB_AVAILABLE_IN_ALL
234 gboolean g_date_time_equal (gconstpointer dt1,
237 GLIB_AVAILABLE_IN_ALL
238 void g_date_time_get_ymd (GDateTime *datetime,
243 GLIB_AVAILABLE_IN_ALL
244 gint g_date_time_get_year (GDateTime *datetime);
245 GLIB_AVAILABLE_IN_ALL
246 gint g_date_time_get_month (GDateTime *datetime);
247 GLIB_AVAILABLE_IN_ALL
248 gint g_date_time_get_day_of_month (GDateTime *datetime);
250 GLIB_AVAILABLE_IN_ALL
251 gint g_date_time_get_week_numbering_year (GDateTime *datetime);
252 GLIB_AVAILABLE_IN_ALL
253 gint g_date_time_get_week_of_year (GDateTime *datetime);
254 GLIB_AVAILABLE_IN_ALL
255 gint g_date_time_get_day_of_week (GDateTime *datetime);
257 GLIB_AVAILABLE_IN_ALL
258 gint g_date_time_get_day_of_year (GDateTime *datetime);
260 GLIB_AVAILABLE_IN_ALL
261 gint g_date_time_get_hour (GDateTime *datetime);
262 GLIB_AVAILABLE_IN_ALL
263 gint g_date_time_get_minute (GDateTime *datetime);
264 GLIB_AVAILABLE_IN_ALL
265 gint g_date_time_get_second (GDateTime *datetime);
266 GLIB_AVAILABLE_IN_ALL
267 gint g_date_time_get_microsecond (GDateTime *datetime);
268 GLIB_AVAILABLE_IN_ALL
269 gdouble g_date_time_get_seconds (GDateTime *datetime);
271 GLIB_AVAILABLE_IN_ALL
272 gint64 g_date_time_to_unix (GDateTime *datetime);
273 GLIB_AVAILABLE_IN_2_80
274 gint64 g_date_time_to_unix_usec (GDateTime *datetime);
276 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
277 GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_to_unix)
278 gboolean g_date_time_to_timeval (GDateTime *datetime,
280 G_GNUC_END_IGNORE_DEPRECATIONS
282 GLIB_AVAILABLE_IN_ALL
283 GTimeSpan g_date_time_get_utc_offset (GDateTime *datetime);
284 GLIB_AVAILABLE_IN_2_58
285 GTimeZone * g_date_time_get_timezone (GDateTime *datetime);
286 GLIB_AVAILABLE_IN_ALL
287 const gchar * g_date_time_get_timezone_abbreviation (GDateTime *datetime);
288 GLIB_AVAILABLE_IN_ALL
289 gboolean g_date_time_is_daylight_savings (GDateTime *datetime);
291 GLIB_AVAILABLE_IN_ALL
292 GDateTime * g_date_time_to_timezone (GDateTime *datetime,
294 GLIB_AVAILABLE_IN_ALL
295 GDateTime * g_date_time_to_local (GDateTime *datetime);
296 GLIB_AVAILABLE_IN_ALL
297 GDateTime * g_date_time_to_utc (GDateTime *datetime);
299 GLIB_AVAILABLE_IN_ALL
300 gchar * g_date_time_format (GDateTime *datetime,
301 const gchar *format) G_GNUC_MALLOC;
302 GLIB_AVAILABLE_IN_2_62
303 gchar * g_date_time_format_iso8601 (GDateTime *datetime) G_GNUC_MALLOC;
307 #endif /* __G_DATE_TIME_H__ */