Change LGPL-2.1+ to LGPL-2.1-or-later
[platform/upstream/glib.git] / glib / gdatetime.h
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
35 G_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  */
89 typedef gint64 GTimeSpan;
90
91 /**
92  * GDateTime:
93  *
94  * An opaque structure that represents a date and time, including a time zone.
95  *
96  * Since: 2.26
97  */
98 typedef struct _GDateTime GDateTime;
99
100 GLIB_AVAILABLE_IN_ALL
101 void                    g_date_time_unref                               (GDateTime      *datetime);
102 GLIB_AVAILABLE_IN_ALL
103 GDateTime *             g_date_time_ref                                 (GDateTime      *datetime);
104
105 GLIB_AVAILABLE_IN_ALL
106 GDateTime *             g_date_time_new_now                             (GTimeZone      *tz);
107 GLIB_AVAILABLE_IN_ALL
108 GDateTime *             g_date_time_new_now_local                       (void);
109 GLIB_AVAILABLE_IN_ALL
110 GDateTime *             g_date_time_new_now_utc                         (void);
111
112 GLIB_AVAILABLE_IN_ALL
113 GDateTime *             g_date_time_new_from_unix_local                 (gint64          t);
114 GLIB_AVAILABLE_IN_ALL
115 GDateTime *             g_date_time_new_from_unix_utc                   (gint64          t);
116
117 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
118 GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_local)
119 GDateTime *             g_date_time_new_from_timeval_local              (const GTimeVal *tv);
120 GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_utc)
121 GDateTime *             g_date_time_new_from_timeval_utc                (const GTimeVal *tv);
122 G_GNUC_END_IGNORE_DEPRECATIONS
123
124 GLIB_AVAILABLE_IN_2_56
125 GDateTime *             g_date_time_new_from_iso8601                    (const gchar    *text,
126                                                                          GTimeZone      *default_tz);
127
128 GLIB_AVAILABLE_IN_ALL
129 GDateTime *             g_date_time_new                                 (GTimeZone      *tz,
130                                                                          gint            year,
131                                                                          gint            month,
132                                                                          gint            day,
133                                                                          gint            hour,
134                                                                          gint            minute,
135                                                                          gdouble         seconds);
136 GLIB_AVAILABLE_IN_ALL
137 GDateTime *             g_date_time_new_local                           (gint            year,
138                                                                          gint            month,
139                                                                          gint            day,
140                                                                          gint            hour,
141                                                                          gint            minute,
142                                                                          gdouble         seconds);
143 GLIB_AVAILABLE_IN_ALL
144 GDateTime *             g_date_time_new_utc                             (gint            year,
145                                                                          gint            month,
146                                                                          gint            day,
147                                                                          gint            hour,
148                                                                          gint            minute,
149                                                                          gdouble         seconds);
150
151 GLIB_AVAILABLE_IN_ALL
152 G_GNUC_WARN_UNUSED_RESULT
153 GDateTime *             g_date_time_add                                 (GDateTime      *datetime,
154                                                                          GTimeSpan       timespan);
155
156 GLIB_AVAILABLE_IN_ALL
157 G_GNUC_WARN_UNUSED_RESULT
158 GDateTime *             g_date_time_add_years                           (GDateTime      *datetime,
159                                                                          gint            years);
160 GLIB_AVAILABLE_IN_ALL
161 G_GNUC_WARN_UNUSED_RESULT
162 GDateTime *             g_date_time_add_months                          (GDateTime      *datetime,
163                                                                          gint            months);
164 GLIB_AVAILABLE_IN_ALL
165 G_GNUC_WARN_UNUSED_RESULT
166 GDateTime *             g_date_time_add_weeks                           (GDateTime      *datetime,
167                                                                          gint            weeks);
168 GLIB_AVAILABLE_IN_ALL
169 G_GNUC_WARN_UNUSED_RESULT
170 GDateTime *             g_date_time_add_days                            (GDateTime      *datetime,
171                                                                          gint            days);
172
173 GLIB_AVAILABLE_IN_ALL
174 G_GNUC_WARN_UNUSED_RESULT
175 GDateTime *             g_date_time_add_hours                           (GDateTime      *datetime,
176                                                                          gint            hours);
177 GLIB_AVAILABLE_IN_ALL
178 G_GNUC_WARN_UNUSED_RESULT
179 GDateTime *             g_date_time_add_minutes                         (GDateTime      *datetime,
180                                                                          gint            minutes);
181 GLIB_AVAILABLE_IN_ALL
182 G_GNUC_WARN_UNUSED_RESULT
183 GDateTime *             g_date_time_add_seconds                         (GDateTime      *datetime,
184                                                                          gdouble         seconds);
185
186 GLIB_AVAILABLE_IN_ALL
187 G_GNUC_WARN_UNUSED_RESULT
188 GDateTime *             g_date_time_add_full                            (GDateTime      *datetime,
189                                                                          gint            years,
190                                                                          gint            months,
191                                                                          gint            days,
192                                                                          gint            hours,
193                                                                          gint            minutes,
194                                                                          gdouble         seconds);
195
196 GLIB_AVAILABLE_IN_ALL
197 gint                    g_date_time_compare                             (gconstpointer   dt1,
198                                                                          gconstpointer   dt2);
199 GLIB_AVAILABLE_IN_ALL
200 GTimeSpan               g_date_time_difference                          (GDateTime      *end,
201                                                                          GDateTime      *begin);
202 GLIB_AVAILABLE_IN_ALL
203 guint                   g_date_time_hash                                (gconstpointer   datetime);
204 GLIB_AVAILABLE_IN_ALL
205 gboolean                g_date_time_equal                               (gconstpointer   dt1,
206                                                                          gconstpointer   dt2);
207
208 GLIB_AVAILABLE_IN_ALL
209 void                    g_date_time_get_ymd                             (GDateTime      *datetime,
210                                                                          gint           *year,
211                                                                          gint           *month,
212                                                                          gint           *day);
213
214 GLIB_AVAILABLE_IN_ALL
215 gint                    g_date_time_get_year                            (GDateTime      *datetime);
216 GLIB_AVAILABLE_IN_ALL
217 gint                    g_date_time_get_month                           (GDateTime      *datetime);
218 GLIB_AVAILABLE_IN_ALL
219 gint                    g_date_time_get_day_of_month                    (GDateTime      *datetime);
220
221 GLIB_AVAILABLE_IN_ALL
222 gint                    g_date_time_get_week_numbering_year             (GDateTime      *datetime);
223 GLIB_AVAILABLE_IN_ALL
224 gint                    g_date_time_get_week_of_year                    (GDateTime      *datetime);
225 GLIB_AVAILABLE_IN_ALL
226 gint                    g_date_time_get_day_of_week                     (GDateTime      *datetime);
227
228 GLIB_AVAILABLE_IN_ALL
229 gint                    g_date_time_get_day_of_year                     (GDateTime      *datetime);
230
231 GLIB_AVAILABLE_IN_ALL
232 gint                    g_date_time_get_hour                            (GDateTime      *datetime);
233 GLIB_AVAILABLE_IN_ALL
234 gint                    g_date_time_get_minute                          (GDateTime      *datetime);
235 GLIB_AVAILABLE_IN_ALL
236 gint                    g_date_time_get_second                          (GDateTime      *datetime);
237 GLIB_AVAILABLE_IN_ALL
238 gint                    g_date_time_get_microsecond                     (GDateTime      *datetime);
239 GLIB_AVAILABLE_IN_ALL
240 gdouble                 g_date_time_get_seconds                         (GDateTime      *datetime);
241
242 GLIB_AVAILABLE_IN_ALL
243 gint64                  g_date_time_to_unix                             (GDateTime      *datetime);
244 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
245 GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_to_unix)
246 gboolean                g_date_time_to_timeval                          (GDateTime      *datetime,
247                                                                          GTimeVal       *tv);
248 G_GNUC_END_IGNORE_DEPRECATIONS
249
250 GLIB_AVAILABLE_IN_ALL
251 GTimeSpan               g_date_time_get_utc_offset                      (GDateTime      *datetime);
252 GLIB_AVAILABLE_IN_2_58
253 GTimeZone *             g_date_time_get_timezone                        (GDateTime      *datetime);
254 GLIB_AVAILABLE_IN_ALL
255 const gchar *           g_date_time_get_timezone_abbreviation           (GDateTime      *datetime);
256 GLIB_AVAILABLE_IN_ALL
257 gboolean                g_date_time_is_daylight_savings                 (GDateTime      *datetime);
258
259 GLIB_AVAILABLE_IN_ALL
260 GDateTime *             g_date_time_to_timezone                         (GDateTime      *datetime,
261                                                                          GTimeZone      *tz);
262 GLIB_AVAILABLE_IN_ALL
263 GDateTime *             g_date_time_to_local                            (GDateTime      *datetime);
264 GLIB_AVAILABLE_IN_ALL
265 GDateTime *             g_date_time_to_utc                              (GDateTime      *datetime);
266
267 GLIB_AVAILABLE_IN_ALL
268 gchar *                 g_date_time_format                              (GDateTime      *datetime,
269                                                                          const gchar    *format) G_GNUC_MALLOC;
270 GLIB_AVAILABLE_IN_2_62
271 gchar *                 g_date_time_format_iso8601                      (GDateTime      *datetime) G_GNUC_MALLOC;
272
273 G_END_DECLS
274
275 #endif /* __G_DATE_TIME_H__ */