1/*
2 * Copyright (C) 2009-2010 Christian Hergert <chris@dronelabs.com>
3 * Copyright © 2010 Codethink Limited
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 *
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.
11 *
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.
16 *
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/>.
19 *
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>
24 */
25
26#ifndef __G_DATE_TIME_H__
27#define __G_DATE_TIME_H__
28
29#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
30#error "Only <glib.h> can be included directly."
31#endif
32
33#include <glib/gtimezone.h>
34
35G_BEGIN_DECLS
36
37/**
38 * G_TIME_SPAN_DAY:
39 *
40 * Evaluates to a time span of one day.
41 *
42 * Since: 2.26
43 */
44#define G_TIME_SPAN_DAY (G_GINT64_CONSTANT (86400000000))
45
46/**
47 * G_TIME_SPAN_HOUR:
48 *
49 * Evaluates to a time span of one hour.
50 *
51 * Since: 2.26
52 */
53#define G_TIME_SPAN_HOUR (G_GINT64_CONSTANT (3600000000))
54
55/**
56 * G_TIME_SPAN_MINUTE:
57 *
58 * Evaluates to a time span of one minute.
59 *
60 * Since: 2.26
61 */
62#define G_TIME_SPAN_MINUTE (G_GINT64_CONSTANT (60000000))
63
64/**
65 * G_TIME_SPAN_SECOND:
66 *
67 * Evaluates to a time span of one second.
68 *
69 * Since: 2.26
70 */
71#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT (1000000))
72
73/**
74 * G_TIME_SPAN_MILLISECOND:
75 *
76 * Evaluates to a time span of one millisecond.
77 *
78 * Since: 2.26
79 */
80#define G_TIME_SPAN_MILLISECOND (G_GINT64_CONSTANT (1000))
81
82/**
83 * GTimeSpan:
84 *
85 * A value representing an interval of time, in microseconds.
86 *
87 * Since: 2.26
88 */
89typedef gint64 GTimeSpan;
90
91/**
92 * GDateTime:
93 *
94 * `GDateTime` is a structure that combines a Gregorian date and time
95 * into a single structure.
96 *
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
101 * seconds.
102 *
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.
107 *
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.
112 *
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).
119 *
120 * Since: 2.26
121 */
122typedef struct _GDateTime GDateTime;
123
124GLIB_AVAILABLE_IN_ALL
125void g_date_time_unref (GDateTime *datetime);
126GLIB_AVAILABLE_IN_ALL
127GDateTime * g_date_time_ref (GDateTime *datetime);
128
129GLIB_AVAILABLE_IN_ALL
130GDateTime * g_date_time_new_now (GTimeZone *tz);
131GLIB_AVAILABLE_IN_ALL
132GDateTime * g_date_time_new_now_local (void);
133GLIB_AVAILABLE_IN_ALL
134GDateTime * g_date_time_new_now_utc (void);
135
136GLIB_AVAILABLE_IN_ALL
137GDateTime * g_date_time_new_from_unix_local (gint64 t);
138GLIB_AVAILABLE_IN_ALL
139GDateTime * g_date_time_new_from_unix_utc (gint64 t);
140
141GLIB_AVAILABLE_IN_2_80
142GDateTime * g_date_time_new_from_unix_local_usec (gint64 usecs);
143GLIB_AVAILABLE_IN_2_80
144GDateTime * g_date_time_new_from_unix_utc_usec (gint64 usecs);
145
146G_GNUC_BEGIN_IGNORE_DEPRECATIONS
147GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_local)
148GDateTime * g_date_time_new_from_timeval_local (const GTimeVal *tv);
149GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_utc)
150GDateTime * g_date_time_new_from_timeval_utc (const GTimeVal *tv);
151G_GNUC_END_IGNORE_DEPRECATIONS
152
153GLIB_AVAILABLE_IN_2_56
154GDateTime * g_date_time_new_from_iso8601 (const gchar *text,
155 GTimeZone *default_tz);
156
157GLIB_AVAILABLE_IN_ALL
158GDateTime * g_date_time_new (GTimeZone *tz,
159 gint year,
160 gint month,
161 gint day,
162 gint hour,
163 gint minute,
164 gdouble seconds);
165GLIB_AVAILABLE_IN_ALL
166GDateTime * g_date_time_new_local (gint year,
167 gint month,
168 gint day,
169 gint hour,
170 gint minute,
171 gdouble seconds);
172GLIB_AVAILABLE_IN_ALL
173GDateTime * g_date_time_new_utc (gint year,
174 gint month,
175 gint day,
176 gint hour,
177 gint minute,
178 gdouble seconds);
179
180GLIB_AVAILABLE_IN_ALL
181G_GNUC_WARN_UNUSED_RESULT
182GDateTime * g_date_time_add (GDateTime *datetime,
183 GTimeSpan timespan);
184
185GLIB_AVAILABLE_IN_ALL
186G_GNUC_WARN_UNUSED_RESULT
187GDateTime * g_date_time_add_years (GDateTime *datetime,
188 gint years);
189GLIB_AVAILABLE_IN_ALL
190G_GNUC_WARN_UNUSED_RESULT
191GDateTime * g_date_time_add_months (GDateTime *datetime,
192 gint months);
193GLIB_AVAILABLE_IN_ALL
194G_GNUC_WARN_UNUSED_RESULT
195GDateTime * g_date_time_add_weeks (GDateTime *datetime,
196 gint weeks);
197GLIB_AVAILABLE_IN_ALL
198G_GNUC_WARN_UNUSED_RESULT
199GDateTime * g_date_time_add_days (GDateTime *datetime,
200 gint days);
201
202GLIB_AVAILABLE_IN_ALL
203G_GNUC_WARN_UNUSED_RESULT
204GDateTime * g_date_time_add_hours (GDateTime *datetime,
205 gint hours);
206GLIB_AVAILABLE_IN_ALL
207G_GNUC_WARN_UNUSED_RESULT
208GDateTime * g_date_time_add_minutes (GDateTime *datetime,
209 gint minutes);
210GLIB_AVAILABLE_IN_ALL
211G_GNUC_WARN_UNUSED_RESULT
212GDateTime * g_date_time_add_seconds (GDateTime *datetime,
213 gdouble seconds);
214
215GLIB_AVAILABLE_IN_ALL
216G_GNUC_WARN_UNUSED_RESULT
217GDateTime * g_date_time_add_full (GDateTime *datetime,
218 gint years,
219 gint months,
220 gint days,
221 gint hours,
222 gint minutes,
223 gdouble seconds);
224
225GLIB_AVAILABLE_IN_ALL
226gint g_date_time_compare (gconstpointer dt1,
227 gconstpointer dt2);
228GLIB_AVAILABLE_IN_ALL
229GTimeSpan g_date_time_difference (GDateTime *end,
230 GDateTime *begin);
231GLIB_AVAILABLE_IN_ALL
232guint g_date_time_hash (gconstpointer datetime);
233GLIB_AVAILABLE_IN_ALL
234gboolean g_date_time_equal (gconstpointer dt1,
235 gconstpointer dt2);
236
237GLIB_AVAILABLE_IN_ALL
238void g_date_time_get_ymd (GDateTime *datetime,
239 gint *year,
240 gint *month,
241 gint *day);
242
243GLIB_AVAILABLE_IN_ALL
244gint g_date_time_get_year (GDateTime *datetime);
245GLIB_AVAILABLE_IN_ALL
246gint g_date_time_get_month (GDateTime *datetime);
247GLIB_AVAILABLE_IN_ALL
248gint g_date_time_get_day_of_month (GDateTime *datetime);
249
250GLIB_AVAILABLE_IN_ALL
251gint g_date_time_get_week_numbering_year (GDateTime *datetime);
252GLIB_AVAILABLE_IN_ALL
253gint g_date_time_get_week_of_year (GDateTime *datetime);
254GLIB_AVAILABLE_IN_ALL
255gint g_date_time_get_day_of_week (GDateTime *datetime);
256
257GLIB_AVAILABLE_IN_ALL
258gint g_date_time_get_day_of_year (GDateTime *datetime);
259
260GLIB_AVAILABLE_IN_ALL
261gint g_date_time_get_hour (GDateTime *datetime);
262GLIB_AVAILABLE_IN_ALL
263gint g_date_time_get_minute (GDateTime *datetime);
264GLIB_AVAILABLE_IN_ALL
265gint g_date_time_get_second (GDateTime *datetime);
266GLIB_AVAILABLE_IN_ALL
267gint g_date_time_get_microsecond (GDateTime *datetime);
268GLIB_AVAILABLE_IN_ALL
269gdouble g_date_time_get_seconds (GDateTime *datetime);
270
271GLIB_AVAILABLE_IN_ALL
272gint64 g_date_time_to_unix (GDateTime *datetime);
273GLIB_AVAILABLE_IN_2_80
274gint64 g_date_time_to_unix_usec (GDateTime *datetime);
275
276G_GNUC_BEGIN_IGNORE_DEPRECATIONS
277GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_to_unix)
278gboolean g_date_time_to_timeval (GDateTime *datetime,
279 GTimeVal *tv);
280G_GNUC_END_IGNORE_DEPRECATIONS
281
282GLIB_AVAILABLE_IN_ALL
283GTimeSpan g_date_time_get_utc_offset (GDateTime *datetime);
284GLIB_AVAILABLE_IN_2_58
285GTimeZone * g_date_time_get_timezone (GDateTime *datetime);
286GLIB_AVAILABLE_IN_ALL
287const gchar * g_date_time_get_timezone_abbreviation (GDateTime *datetime);
288GLIB_AVAILABLE_IN_ALL
289gboolean g_date_time_is_daylight_savings (GDateTime *datetime);
290
291GLIB_AVAILABLE_IN_ALL
292GDateTime * g_date_time_to_timezone (GDateTime *datetime,
293 GTimeZone *tz);
294GLIB_AVAILABLE_IN_ALL
295GDateTime * g_date_time_to_local (GDateTime *datetime);
296GLIB_AVAILABLE_IN_ALL
297GDateTime * g_date_time_to_utc (GDateTime *datetime);
298
299GLIB_AVAILABLE_IN_ALL
300gchar * g_date_time_format (GDateTime *datetime,
301 const gchar *format) G_GNUC_MALLOC;
302GLIB_AVAILABLE_IN_2_62
303gchar * g_date_time_format_iso8601 (GDateTime *datetime) G_GNUC_MALLOC;
304
305G_END_DECLS
306
307#endif /* __G_DATE_TIME_H__ */
308