gdatetime.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. #ifndef __G_DATE_TIME_H__
  26. #define __G_DATE_TIME_H__
  27. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  28. #error "Only <glib.h> can be included directly."
  29. #endif
  30. #include <glib/gtimezone.h>
  31. G_BEGIN_DECLS
  32. /**
  33. * G_TIME_SPAN_DAY:
  34. *
  35. * Evaluates to a time span of one day.
  36. *
  37. * Since: 2.26
  38. */
  39. #define G_TIME_SPAN_DAY (G_GINT64_CONSTANT (86400000000))
  40. /**
  41. * G_TIME_SPAN_HOUR:
  42. *
  43. * Evaluates to a time span of one hour.
  44. *
  45. * Since: 2.26
  46. */
  47. #define G_TIME_SPAN_HOUR (G_GINT64_CONSTANT (3600000000))
  48. /**
  49. * G_TIME_SPAN_MINUTE:
  50. *
  51. * Evaluates to a time span of one minute.
  52. *
  53. * Since: 2.26
  54. */
  55. #define G_TIME_SPAN_MINUTE (G_GINT64_CONSTANT (60000000))
  56. /**
  57. * G_TIME_SPAN_SECOND:
  58. *
  59. * Evaluates to a time span of one second.
  60. *
  61. * Since: 2.26
  62. */
  63. #define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT (1000000))
  64. /**
  65. * G_TIME_SPAN_MILLISECOND:
  66. *
  67. * Evaluates to a time span of one millisecond.
  68. *
  69. * Since: 2.26
  70. */
  71. #define G_TIME_SPAN_MILLISECOND (G_GINT64_CONSTANT (1000))
  72. /**
  73. * GTimeSpan:
  74. *
  75. * A value representing an interval of time, in microseconds.
  76. *
  77. * Since: 2.26
  78. */
  79. typedef gint64 GTimeSpan;
  80. /**
  81. * GDateTime:
  82. *
  83. * `GDateTime` is a structure that combines a Gregorian date and time
  84. * into a single structure.
  85. *
  86. * `GDateTime` provides many conversion and methods to manipulate dates and times.
  87. * Time precision is provided down to microseconds and the time can range
  88. * (proleptically) from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999.
  89. * `GDateTime` follows POSIX time in the sense that it is oblivious to leap
  90. * seconds.
  91. *
  92. * `GDateTime` is an immutable object; once it has been created it cannot
  93. * be modified further. All modifiers will create a new `GDateTime`.
  94. * Nearly all such functions can fail due to the date or time going out
  95. * of range, in which case %NULL will be returned.
  96. *
  97. * `GDateTime` is reference counted: the reference count is increased by calling
  98. * [method@GLib.DateTime.ref] and decreased by calling [method@GLib.DateTime.unref].
  99. * When the reference count drops to 0, the resources allocated by the `GDateTime`
  100. * structure are released.
  101. *
  102. * Many parts of the API may produce non-obvious results. As an
  103. * example, adding two months to January 31st will yield March 31st
  104. * whereas adding one month and then one month again will yield either
  105. * March 28th or March 29th. Also note that adding 24 hours is not
  106. * always the same as adding one day (since days containing daylight
  107. * savings time transitions are either 23 or 25 hours in length).
  108. *
  109. * Since: 2.26
  110. */
  111. typedef struct _GDateTime GDateTime;
  112. GLIB_AVAILABLE_IN_ALL
  113. void g_date_time_unref (GDateTime *datetime);
  114. GLIB_AVAILABLE_IN_ALL
  115. GDateTime * g_date_time_ref (GDateTime *datetime);
  116. GLIB_AVAILABLE_IN_ALL
  117. GDateTime * g_date_time_new_now (GTimeZone *tz);
  118. GLIB_AVAILABLE_IN_ALL
  119. GDateTime * g_date_time_new_now_local (void);
  120. GLIB_AVAILABLE_IN_ALL
  121. GDateTime * g_date_time_new_now_utc (void);
  122. GLIB_AVAILABLE_IN_ALL
  123. GDateTime * g_date_time_new_from_unix_local (gint64 t);
  124. GLIB_AVAILABLE_IN_ALL
  125. GDateTime * g_date_time_new_from_unix_utc (gint64 t);
  126. GLIB_AVAILABLE_IN_2_80
  127. GDateTime * g_date_time_new_from_unix_local_usec (gint64 usecs);
  128. GLIB_AVAILABLE_IN_2_80
  129. GDateTime * g_date_time_new_from_unix_utc_usec (gint64 usecs);
  130. G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  131. GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_local)
  132. GDateTime * g_date_time_new_from_timeval_local (const GTimeVal *tv);
  133. GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_new_from_unix_utc)
  134. GDateTime * g_date_time_new_from_timeval_utc (const GTimeVal *tv);
  135. G_GNUC_END_IGNORE_DEPRECATIONS
  136. GLIB_AVAILABLE_IN_2_56
  137. GDateTime * g_date_time_new_from_iso8601 (const gchar *text,
  138. GTimeZone *default_tz);
  139. GLIB_AVAILABLE_IN_ALL
  140. GDateTime * g_date_time_new (GTimeZone *tz,
  141. gint year,
  142. gint month,
  143. gint day,
  144. gint hour,
  145. gint minute,
  146. gdouble seconds);
  147. GLIB_AVAILABLE_IN_ALL
  148. GDateTime * g_date_time_new_local (gint year,
  149. gint month,
  150. gint day,
  151. gint hour,
  152. gint minute,
  153. gdouble seconds);
  154. GLIB_AVAILABLE_IN_ALL
  155. GDateTime * g_date_time_new_utc (gint year,
  156. gint month,
  157. gint day,
  158. gint hour,
  159. gint minute,
  160. gdouble seconds);
  161. GLIB_AVAILABLE_IN_ALL
  162. G_GNUC_WARN_UNUSED_RESULT
  163. GDateTime * g_date_time_add (GDateTime *datetime,
  164. GTimeSpan timespan);
  165. GLIB_AVAILABLE_IN_ALL
  166. G_GNUC_WARN_UNUSED_RESULT
  167. GDateTime * g_date_time_add_years (GDateTime *datetime,
  168. gint years);
  169. GLIB_AVAILABLE_IN_ALL
  170. G_GNUC_WARN_UNUSED_RESULT
  171. GDateTime * g_date_time_add_months (GDateTime *datetime,
  172. gint months);
  173. GLIB_AVAILABLE_IN_ALL
  174. G_GNUC_WARN_UNUSED_RESULT
  175. GDateTime * g_date_time_add_weeks (GDateTime *datetime,
  176. gint weeks);
  177. GLIB_AVAILABLE_IN_ALL
  178. G_GNUC_WARN_UNUSED_RESULT
  179. GDateTime * g_date_time_add_days (GDateTime *datetime,
  180. gint days);
  181. GLIB_AVAILABLE_IN_ALL
  182. G_GNUC_WARN_UNUSED_RESULT
  183. GDateTime * g_date_time_add_hours (GDateTime *datetime,
  184. gint hours);
  185. GLIB_AVAILABLE_IN_ALL
  186. G_GNUC_WARN_UNUSED_RESULT
  187. GDateTime * g_date_time_add_minutes (GDateTime *datetime,
  188. gint minutes);
  189. GLIB_AVAILABLE_IN_ALL
  190. G_GNUC_WARN_UNUSED_RESULT
  191. GDateTime * g_date_time_add_seconds (GDateTime *datetime,
  192. gdouble seconds);
  193. GLIB_AVAILABLE_IN_ALL
  194. G_GNUC_WARN_UNUSED_RESULT
  195. GDateTime * g_date_time_add_full (GDateTime *datetime,
  196. gint years,
  197. gint months,
  198. gint days,
  199. gint hours,
  200. gint minutes,
  201. gdouble seconds);
  202. GLIB_AVAILABLE_IN_ALL
  203. gint g_date_time_compare (gconstpointer dt1,
  204. gconstpointer dt2);
  205. GLIB_AVAILABLE_IN_ALL
  206. GTimeSpan g_date_time_difference (GDateTime *end,
  207. GDateTime *begin);
  208. GLIB_AVAILABLE_IN_ALL
  209. guint g_date_time_hash (gconstpointer datetime);
  210. GLIB_AVAILABLE_IN_ALL
  211. gboolean g_date_time_equal (gconstpointer dt1,
  212. gconstpointer dt2);
  213. GLIB_AVAILABLE_IN_ALL
  214. void g_date_time_get_ymd (GDateTime *datetime,
  215. gint *year,
  216. gint *month,
  217. gint *day);
  218. GLIB_AVAILABLE_IN_ALL
  219. gint g_date_time_get_year (GDateTime *datetime);
  220. GLIB_AVAILABLE_IN_ALL
  221. gint g_date_time_get_month (GDateTime *datetime);
  222. GLIB_AVAILABLE_IN_ALL
  223. gint g_date_time_get_day_of_month (GDateTime *datetime);
  224. GLIB_AVAILABLE_IN_ALL
  225. gint g_date_time_get_week_numbering_year (GDateTime *datetime);
  226. GLIB_AVAILABLE_IN_ALL
  227. gint g_date_time_get_week_of_year (GDateTime *datetime);
  228. GLIB_AVAILABLE_IN_ALL
  229. gint g_date_time_get_day_of_week (GDateTime *datetime);
  230. GLIB_AVAILABLE_IN_ALL
  231. gint g_date_time_get_day_of_year (GDateTime *datetime);
  232. GLIB_AVAILABLE_IN_ALL
  233. gint g_date_time_get_hour (GDateTime *datetime);
  234. GLIB_AVAILABLE_IN_ALL
  235. gint g_date_time_get_minute (GDateTime *datetime);
  236. GLIB_AVAILABLE_IN_ALL
  237. gint g_date_time_get_second (GDateTime *datetime);
  238. GLIB_AVAILABLE_IN_ALL
  239. gint g_date_time_get_microsecond (GDateTime *datetime);
  240. GLIB_AVAILABLE_IN_ALL
  241. gdouble g_date_time_get_seconds (GDateTime *datetime);
  242. GLIB_AVAILABLE_IN_ALL
  243. gint64 g_date_time_to_unix (GDateTime *datetime);
  244. GLIB_AVAILABLE_IN_2_80
  245. gint64 g_date_time_to_unix_usec (GDateTime *datetime);
  246. G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  247. GLIB_DEPRECATED_IN_2_62_FOR(g_date_time_to_unix)
  248. gboolean g_date_time_to_timeval (GDateTime *datetime,
  249. GTimeVal *tv);
  250. G_GNUC_END_IGNORE_DEPRECATIONS
  251. GLIB_AVAILABLE_IN_ALL
  252. GTimeSpan g_date_time_get_utc_offset (GDateTime *datetime);
  253. GLIB_AVAILABLE_IN_2_58
  254. GTimeZone * g_date_time_get_timezone (GDateTime *datetime);
  255. GLIB_AVAILABLE_IN_ALL
  256. const gchar * g_date_time_get_timezone_abbreviation (GDateTime *datetime);
  257. GLIB_AVAILABLE_IN_ALL
  258. gboolean g_date_time_is_daylight_savings (GDateTime *datetime);
  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. GLIB_AVAILABLE_IN_ALL
  267. gchar * g_date_time_format (GDateTime *datetime,
  268. const gchar *format) G_GNUC_MALLOC;
  269. GLIB_AVAILABLE_IN_2_62
  270. gchar * g_date_time_format_iso8601 (GDateTime *datetime) G_GNUC_MALLOC;
  271. G_END_DECLS
  272. #endif /* __G_DATE_TIME_H__ */