timelib.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2015-2022 Derick Rethans
  5. * Copyright (c) 2018,2021 MongoDB, Inc.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. #ifndef __TIMELIB_H__
  26. #define __TIMELIB_H__
  27. #ifdef HAVE_TIMELIB_CONFIG_H
  28. # include "timelib_config.h"
  29. #endif
  30. #define TIMELIB_VERSION 202117
  31. #define TIMELIB_EXTENDED_VERSION 20211701
  32. #define TIMELIB_ASCII_VERSION "2021.17"
  33. #include <stdlib.h>
  34. #include <stdbool.h>
  35. #include <limits.h>
  36. #include <inttypes.h>
  37. # ifndef HAVE_INT32_T
  38. # if SIZEOF_INT == 4
  39. typedef int int32_t;
  40. # elif SIZEOF_LONG == 4
  41. typedef long int int32_t;
  42. # endif
  43. # endif
  44. # ifndef HAVE_UINT32_T
  45. # if SIZEOF_INT == 4
  46. typedef unsigned int uint32_t;
  47. # elif SIZEOF_LONG == 4
  48. typedef unsigned long int uint32_t;
  49. # endif
  50. # endif
  51. #ifdef _WIN32
  52. # if _MSC_VER >= 1600
  53. # include <stdint.h>
  54. # endif
  55. # ifndef SIZEOF_INT
  56. # define SIZEOF_INT 4
  57. # endif
  58. # ifndef SIZEOF_LONG
  59. # define SIZEOF_LONG 4
  60. # endif
  61. # ifndef int32_t
  62. typedef __int32 int32_t;
  63. # endif
  64. # ifndef uint32_t
  65. typedef unsigned __int32 uint32_t;
  66. # endif
  67. # ifndef int64_t
  68. typedef __int64 int64_t;
  69. # endif
  70. # ifndef uint64_t
  71. typedef unsigned __int64 uint64_t;
  72. # endif
  73. # ifndef PRId32
  74. # define PRId32 "I32d"
  75. # endif
  76. # ifndef PRIu32
  77. # define PRIu32 "I32u"
  78. # endif
  79. # ifndef PRId64
  80. # define PRId64 "I64d"
  81. # endif
  82. # ifndef PRIu64
  83. # define PRIu64 "I64u"
  84. # endif
  85. # ifndef INT32_MAX
  86. #define INT32_MAX _I32_MAX
  87. # endif
  88. # ifndef INT32_MIN
  89. #define INT32_MIN ((int32_t)_I32_MIN)
  90. # endif
  91. # ifndef UINT32_MAX
  92. #define UINT32_MAX _UI32_MAX
  93. # endif
  94. # ifndef INT64_MIN
  95. #define INT64_MIN ((int64_t)_I64_MIN)
  96. # endif
  97. # ifndef INT64_MAX
  98. #define INT64_MAX _I64_MAX
  99. # endif
  100. # ifndef UINT64_MAX
  101. #define UINT64_MAX _UI64_MAX
  102. # endif
  103. #endif
  104. #if (defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)) && !defined(TIMELIB_FORCE_LONG32)
  105. typedef int64_t timelib_long;
  106. typedef uint64_t timelib_ulong;
  107. # define TIMELIB_LONG_MAX INT64_MAX
  108. # define TIMELIB_LONG_MIN INT64_MIN
  109. # define TIMELIB_ULONG_MAX UINT64_MAX
  110. # define TIMELIB_LONG_FMT "%" PRId64
  111. # define TIMELIB_ULONG_FMT "%" PRIu64
  112. #else
  113. typedef int32_t timelib_long;
  114. typedef uint32_t timelib_ulong;
  115. # define TIMELIB_LONG_MAX INT32_MAX
  116. # define TIMELIB_LONG_MIN INT32_MIN
  117. # define TIMELIB_ULONG_MAX UINT32_MAX
  118. # define TIMELIB_LONG_FMT "%" PRId32
  119. # define TIMELIB_ULONG_FMT "%" PRIu32
  120. #endif
  121. #if defined(_MSC_VER)
  122. typedef uint64_t timelib_ull;
  123. typedef int64_t timelib_sll;
  124. # define TIMELIB_LL_CONST(n) n ## i64
  125. #else
  126. typedef unsigned long long timelib_ull;
  127. typedef signed long long timelib_sll;
  128. # define TIMELIB_LL_CONST(n) n ## ll
  129. #endif
  130. typedef struct _ttinfo ttinfo;
  131. typedef struct _tlinfo tlinfo;
  132. typedef struct _tlocinfo
  133. {
  134. char country_code[3];
  135. double latitude;
  136. double longitude;
  137. char *comments;
  138. } tlocinfo;
  139. #define TIMELIB_POSIX_TRANS_TYPE_JULIAN_NO_FEB29 1
  140. #define TIMELIB_POSIX_TRANS_TYPE_JULIAN_FEB29 2
  141. #define TIMELIB_POSIX_TRANS_TYPE_MWD 3
  142. typedef struct _timelib_posix_trans_info
  143. {
  144. int type; // 1=Jn, 2=n, 3=Mm.w.d
  145. union {
  146. int days;
  147. struct {
  148. int month;
  149. int week;
  150. int dow;
  151. } mwd;
  152. };
  153. int hour;
  154. } timelib_posix_trans_info;
  155. typedef struct _timelib_posix_str
  156. {
  157. char *std;
  158. timelib_sll std_offset;
  159. char *dst;
  160. timelib_sll dst_offset;
  161. timelib_posix_trans_info *dst_begin;
  162. timelib_posix_trans_info *dst_end;
  163. int type_index_std_type; // index into tz->type
  164. int type_index_dst_type; // index into tz->type
  165. } timelib_posix_str;
  166. typedef struct _timelib_posix_transitions {
  167. size_t count;
  168. timelib_sll times[6];
  169. timelib_sll types[6];
  170. } timelib_posix_transitions;
  171. typedef struct _timelib_tzinfo
  172. {
  173. char *name;
  174. struct {
  175. uint32_t ttisgmtcnt;
  176. uint32_t ttisstdcnt;
  177. uint32_t leapcnt;
  178. uint32_t timecnt;
  179. uint32_t typecnt;
  180. uint32_t charcnt;
  181. } _bit32;
  182. struct {
  183. uint64_t ttisgmtcnt;
  184. uint64_t ttisstdcnt;
  185. uint64_t leapcnt;
  186. uint64_t timecnt;
  187. uint64_t typecnt;
  188. uint64_t charcnt;
  189. } bit64;
  190. int64_t *trans;
  191. unsigned char *trans_idx;
  192. ttinfo *type;
  193. char *timezone_abbr;
  194. tlinfo *leap_times;
  195. unsigned char bc;
  196. tlocinfo location;
  197. char *posix_string;
  198. timelib_posix_str *posix_info;
  199. } timelib_tzinfo;
  200. typedef struct _timelib_rel_time {
  201. timelib_sll y, m, d; /* Years, Months and Days */
  202. timelib_sll h, i, s; /* Hours, mInutes and Seconds */
  203. timelib_sll us; /* Microseconds */
  204. int weekday; /* Stores the day in 'next monday' */
  205. int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
  206. int first_last_day_of;
  207. int invert; /* Whether the difference should be inverted */
  208. timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
  209. struct {
  210. unsigned int type;
  211. timelib_sll amount;
  212. } special;
  213. unsigned int have_weekday_relative, have_special_relative;
  214. } timelib_rel_time;
  215. typedef struct _timelib_time_offset {
  216. int32_t offset;
  217. unsigned int leap_secs;
  218. unsigned int is_dst;
  219. char *abbr;
  220. timelib_sll transition_time;
  221. } timelib_time_offset;
  222. typedef struct _timelib_time {
  223. timelib_sll y, m, d; /* Year, Month, Day */
  224. timelib_sll h, i, s; /* Hour, mInute, Second */
  225. timelib_sll us; /* Microseconds */
  226. int z; /* UTC offset in seconds */
  227. char *tz_abbr; /* Timezone abbreviation (display only) */
  228. timelib_tzinfo *tz_info; /* Timezone structure */
  229. signed int dst; /* Flag if we were parsing a DST zone */
  230. timelib_rel_time relative;
  231. timelib_sll sse; /* Seconds since epoch */
  232. unsigned int have_time, have_date, have_zone, have_relative, have_weeknr_day;
  233. unsigned int sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
  234. unsigned int tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
  235. unsigned int is_localtime; /* 1 if the current struct represents localtime, 0 if it is in GMT */
  236. unsigned int zone_type; /* 1 time offset,
  237. * 3 TimeZone identifier,
  238. * 2 TimeZone abbreviation */
  239. } timelib_time;
  240. typedef struct _timelib_abbr_info {
  241. timelib_sll utc_offset;
  242. char *abbr;
  243. int dst;
  244. } timelib_abbr_info;
  245. #define TIMELIB_WARN_MASK 0x1ff
  246. #define TIMELIB_ERR_MASK 0x2ff
  247. #define TIMELIB_WARN_DOUBLE_TZ 0x101
  248. #define TIMELIB_WARN_INVALID_TIME 0x102
  249. #define TIMELIB_WARN_INVALID_DATE 0x103
  250. #define TIMELIB_WARN_TRAILING_DATA 0x11a
  251. #define TIMELIB_ERR_DOUBLE_TZ 0x201
  252. #define TIMELIB_ERR_TZID_NOT_FOUND 0x202
  253. #define TIMELIB_ERR_DOUBLE_TIME 0x203
  254. #define TIMELIB_ERR_DOUBLE_DATE 0x204
  255. #define TIMELIB_ERR_UNEXPECTED_CHARACTER 0x205
  256. #define TIMELIB_ERR_EMPTY_STRING 0x206
  257. #define TIMELIB_ERR_UNEXPECTED_DATA 0x207
  258. #define TIMELIB_ERR_NO_TEXTUAL_DAY 0x208
  259. #define TIMELIB_ERR_NO_TWO_DIGIT_DAY 0x209
  260. #define TIMELIB_ERR_NO_THREE_DIGIT_DAY_OF_YEAR 0x20a
  261. #define TIMELIB_ERR_NO_TWO_DIGIT_MONTH 0x20b
  262. #define TIMELIB_ERR_NO_TEXTUAL_MONTH 0x20c
  263. #define TIMELIB_ERR_NO_TWO_DIGIT_YEAR 0x20d
  264. #define TIMELIB_ERR_NO_FOUR_DIGIT_YEAR 0x20e
  265. #define TIMELIB_ERR_NO_TWO_DIGIT_HOUR 0x20f
  266. #define TIMELIB_ERR_HOUR_LARGER_THAN_12 0x210
  267. #define TIMELIB_ERR_MERIDIAN_BEFORE_HOUR 0x211
  268. #define TIMELIB_ERR_NO_MERIDIAN 0x212
  269. #define TIMELIB_ERR_NO_TWO_DIGIT_MINUTE 0x213
  270. #define TIMELIB_ERR_NO_TWO_DIGIT_SECOND 0x214
  271. #define TIMELIB_ERR_NO_SIX_DIGIT_MICROSECOND 0x215
  272. #define TIMELIB_ERR_NO_SEP_SYMBOL 0x216
  273. #define TIMELIB_ERR_EXPECTED_ESCAPE_CHAR 0x217
  274. #define TIMELIB_ERR_NO_ESCAPED_CHAR 0x218
  275. #define TIMELIB_ERR_WRONG_FORMAT_SEP 0x219
  276. #define TIMELIB_ERR_TRAILING_DATA 0x21a
  277. #define TIMELIB_ERR_DATA_MISSING 0x21b
  278. #define TIMELIB_ERR_NO_THREE_DIGIT_MILLISECOND 0x21c
  279. #define TIMELIB_ERR_NO_FOUR_DIGIT_YEAR_ISO 0x21d
  280. #define TIMELIB_ERR_NO_TWO_DIGIT_WEEK 0x21e
  281. #define TIMELIB_ERR_INVALID_WEEK 0x21f
  282. #define TIMELIB_ERR_NO_DAY_OF_WEEK 0x220
  283. #define TIMELIB_ERR_INVALID_DAY_OF_WEEK 0x221
  284. #define TIMELIB_ERR_INVALID_SPECIFIER 0x222
  285. #define TIMELIB_ERR_INVALID_TZ_OFFSET 0x223
  286. #define TIMELIB_ERR_FORMAT_LITERAL_MISMATCH 0x224
  287. #define TIMELIB_ERR_MIX_ISO_WITH_NATURAL 0x225
  288. #define TIMELIB_ZONETYPE_NONE 0
  289. #define TIMELIB_ZONETYPE_OFFSET 1
  290. #define TIMELIB_ZONETYPE_ABBR 2
  291. #define TIMELIB_ZONETYPE_ID 3
  292. typedef struct _timelib_error_message {
  293. int error_code;
  294. int position;
  295. char character;
  296. char *message;
  297. } timelib_error_message;
  298. typedef struct _timelib_error_container {
  299. timelib_error_message *error_messages;
  300. timelib_error_message *warning_messages;
  301. int error_count;
  302. int warning_count;
  303. } timelib_error_container;
  304. typedef struct _timelib_tz_lookup_table {
  305. const char *name;
  306. int type;
  307. float gmtoffset;
  308. const char *full_tz_name;
  309. } timelib_tz_lookup_table;
  310. typedef struct _timelib_tzdb_index_entry {
  311. char *id;
  312. unsigned int pos;
  313. } timelib_tzdb_index_entry;
  314. typedef struct _timelib_tzdb {
  315. const char *version;
  316. int index_size;
  317. const timelib_tzdb_index_entry *index;
  318. const unsigned char *data;
  319. } timelib_tzdb;
  320. #ifndef timelib_malloc
  321. # define timelib_malloc malloc
  322. # define timelib_realloc realloc
  323. # define timelib_calloc calloc
  324. # define timelib_strdup strdup
  325. # define timelib_free free
  326. # if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
  327. # define TIMELIB_USE_BUILTIN_STRNDUP 1
  328. # else
  329. # define TIMELIB_USE_BUILTIN_STRNDUP 0
  330. # define timelib_strndup strndup
  331. # endif
  332. #endif
  333. #define TIMELIB_NONE 0x00
  334. #define TIMELIB_OVERRIDE_TIME 0x01
  335. #define TIMELIB_NO_CLONE 0x02
  336. #define TIMELIB_UNSET -99999
  337. /* An entry for each of these error codes is also in the
  338. * timelib_error_messages array in timelib.c.
  339. * Codes 0x00, 0x07, and 0x09 are warnings only. */
  340. #define TIMELIB_ERROR_NO_ERROR 0x00
  341. #define TIMELIB_ERROR_CANNOT_ALLOCATE 0x01
  342. #define TIMELIB_ERROR_CORRUPT_TRANSITIONS_DONT_INCREASE 0x02
  343. #define TIMELIB_ERROR_CORRUPT_NO_64BIT_PREAMBLE 0x03
  344. #define TIMELIB_ERROR_CORRUPT_NO_ABBREVIATION 0x04
  345. #define TIMELIB_ERROR_UNSUPPORTED_VERSION 0x05
  346. #define TIMELIB_ERROR_NO_SUCH_TIMEZONE 0x06
  347. #define TIMELIB_ERROR_SLIM_FILE 0x07 /* Warns if the file is SLIM, but we can't read it */
  348. #define TIMELIB_ERROR_CORRUPT_POSIX_STRING 0x08
  349. #define TIMELIB_ERROR_EMPTY_POSIX_STRING 0x09 /* Warns if the POSIX string is empty, but still produces results */
  350. #ifdef __cplusplus
  351. extern "C" {
  352. #endif
  353. typedef enum _timelib_format_specifier_code {
  354. TIMELIB_FORMAT_ALLOW_EXTRA_CHARACTERS = 0,
  355. TIMELIB_FORMAT_ANY_SEPARATOR,
  356. TIMELIB_FORMAT_DAY_TWO_DIGIT,
  357. TIMELIB_FORMAT_DAY_TWO_DIGIT_PADDED,
  358. TIMELIB_FORMAT_DAY_OF_WEEK_ISO,
  359. TIMELIB_FORMAT_DAY_OF_WEEK,
  360. TIMELIB_FORMAT_DAY_OF_YEAR,
  361. TIMELIB_FORMAT_DAY_SUFFIX,
  362. TIMELIB_FORMAT_END,
  363. TIMELIB_FORMAT_EPOCH_SECONDS,
  364. TIMELIB_FORMAT_ESCAPE,
  365. TIMELIB_FORMAT_HOUR_TWO_DIGIT_12_MAX,
  366. TIMELIB_FORMAT_HOUR_TWO_DIGIT_12_MAX_PADDED,
  367. TIMELIB_FORMAT_HOUR_TWO_DIGIT_24_MAX,
  368. TIMELIB_FORMAT_HOUR_TWO_DIGIT_24_MAX_PADDED,
  369. TIMELIB_FORMAT_LITERAL,
  370. TIMELIB_FORMAT_MERIDIAN,
  371. TIMELIB_FORMAT_MICROSECOND_SIX_DIGIT,
  372. TIMELIB_FORMAT_MILLISECOND_THREE_DIGIT,
  373. TIMELIB_FORMAT_MINUTE_TWO_DIGIT,
  374. TIMELIB_FORMAT_MONTH_TWO_DIGIT,
  375. TIMELIB_FORMAT_MONTH_TWO_DIGIT_PADDED,
  376. TIMELIB_FORMAT_RANDOM_CHAR,
  377. TIMELIB_FORMAT_RESET_ALL,
  378. TIMELIB_FORMAT_RESET_ALL_WHEN_NOT_SET,
  379. TIMELIB_FORMAT_SECOND_TWO_DIGIT,
  380. TIMELIB_FORMAT_SEPARATOR,
  381. TIMELIB_FORMAT_SKIP_TO_SEPARATOR,
  382. TIMELIB_FORMAT_TEXTUAL_DAY_3_LETTER,
  383. TIMELIB_FORMAT_TEXTUAL_DAY_FULL,
  384. TIMELIB_FORMAT_TEXTUAL_MONTH_3_LETTER,
  385. TIMELIB_FORMAT_TEXTUAL_MONTH_FULL,
  386. TIMELIB_FORMAT_TIMEZONE_OFFSET,
  387. TIMELIB_FORMAT_TIMEZONE_OFFSET_MINUTES,
  388. TIMELIB_FORMAT_WEEK_OF_YEAR_ISO,
  389. TIMELIB_FORMAT_WEEK_OF_YEAR,
  390. TIMELIB_FORMAT_WHITESPACE,
  391. TIMELIB_FORMAT_YEAR_TWO_DIGIT,
  392. TIMELIB_FORMAT_YEAR_FOUR_DIGIT,
  393. TIMELIB_FORMAT_YEAR_ISO
  394. } timelib_format_specifier_code;
  395. typedef struct _timelib_format_specifier {
  396. char specifier;
  397. timelib_format_specifier_code code;
  398. } timelib_format_specifier;
  399. typedef struct _timelib_format_config {
  400. const timelib_format_specifier *format_map;
  401. /* Format speciifiers must be preceded by 'prefix_char' if not '\0'. */
  402. char prefix_char;
  403. } timelib_format_config;
  404. /* Function pointers */
  405. typedef timelib_tzinfo* (*timelib_tz_get_wrapper)(const char *tzname, const timelib_tzdb *tzdb, int *error_code);
  406. /* From dow.c */
  407. /* Calculates the day of the week from y, m, and d. 0=Sunday..6=Saturday */
  408. timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d);
  409. /* Calculates the day of the ISO week from y, m, and d. 1=Monday, 7=Sunday */
  410. timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d);
  411. /* Calculates the day of the year according to y-m-d. 0=Jan 1st..364/365=Dec
  412. * 31st */
  413. timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d);
  414. /* Calculates the day of the year according to y-w-dow. 0..364/365 */
  415. timelib_sll timelib_daynr_from_weeknr(timelib_sll iy, timelib_sll iw, timelib_sll id);
  416. /* Calculates the number of days in month m for year y. 28..31 */
  417. timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m);
  418. /* Calculates the ISO year and week from y, m, and d, into iw and iy */
  419. void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy);
  420. /* Calculates the ISO year, week, and day of week from y, m, and d, into iy,
  421. * iw, and id */
  422. void timelib_isodate_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iy, timelib_sll *iw, timelib_sll *id);
  423. /* Calculates the year, month, and day from iy, iw, and iw, into y, m, and d */
  424. void timelib_date_from_isodate(timelib_sll iy, timelib_sll iw, timelib_sll id, timelib_sll *y, timelib_sll *m, timelib_sll *d);
  425. /* Returns true if h, i and s fit in the range 00:00:00..23:59:59, false
  426. * otherwise */
  427. int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s);
  428. /* Returns true if m fits in the range 1..12, and d fits in the range
  429. * 1..<days-in-month> for year y */
  430. int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d);
  431. /* From parse_date.re */
  432. /* Parses the date/time string in 's' with length 'len' into the constituent
  433. * parts of timelib_time*.
  434. *
  435. * Depending on the contents of the string 's', not all elements might be
  436. * filled. You can check whether a specific element has been parsed by
  437. * comparing with the TIMELIB_UNSET define.
  438. *
  439. * If errors occur, this function keeps already parsed elements in the
  440. * returned timelib_time* value.
  441. *
  442. * If the **errors points to a timelib_error_container variable, warnings
  443. * and errors will be recorded. You are responsible for freeing the stored
  444. * information with timelib_error_container_dtor(). To see whether errors have
  445. * occurred, inspect errors->errors_count. To see whether warnings have occurred,
  446. * inspect errors->warnings_count.
  447. *
  448. * The returned timelib_time* value is dynamically allocated and should be
  449. * freed with timelib_time_dtor().
  450. */
  451. timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper);
  452. /* Parses the date/time string in 's' with length 'len' into the constituent
  453. * parts of timelib_time* according to the format in 'format'.
  454. *
  455. * Depending on the contents of the string 's', not all elements might be
  456. * filled. You can check whether a specific element has been parsed by
  457. * comparing with the TIMELIB_UNSET define.
  458. *
  459. * If errors occur, this function keeps already parsed elements in the
  460. * returned timelib_time* value.
  461. *
  462. * If the **errors points to a timelib_error_container variable, warnings
  463. * and errors will be recorded. You are responsible for freeing the stored
  464. * information with timelib_error_container_dtor(). To see whether errors have
  465. * occurred, inspect errors->errors_count. To see whether warnings have occurred,
  466. * inspect errors->warnings_count.
  467. *
  468. * The returned timelib_time* value is dynamically allocated and should be
  469. * freed with timelib_time_dtor().
  470. */
  471. timelib_time *timelib_parse_from_format(const char *format, const char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper);
  472. /* Parses the date/time string in 's' with length 'len' into the constituent
  473. * parts of timelib_time* according to the format in 'format' with format
  474. * specifier configuration 'format_config'.
  475. *
  476. * 'format_map' is an array of pairs, with the first element being the format
  477. * specifier as a character and the second element corresponds to the
  478. * representation of the specifier from the enum list
  479. * 'timelib_format_specifier_code'.
  480. *
  481. * Note: 'format_map' must be terminated with specifier '\0' to indicate to the
  482. * parser that there are no more format specifiers in the list.
  483. */
  484. timelib_time *timelib_parse_from_format_with_map(const char *format, const char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper, const timelib_format_config* format_config);
  485. /* Fills the gaps in the parsed timelib_time with information from the reference date/time in 'now'
  486. *
  487. * If any of the 'parsed' y, m, d, h, i or s parameters is unset (TIMELIB_UNSET):
  488. * - if microtime (us) is unset, then the us of the parsed time is set to 0.
  489. * - else if microtime (us) is unset and 'now'->'us' is set, use it, otherwise use 0.
  490. *
  491. * For either of the 'parsed' y, m, d, h, i, s, z (utc offset in seconds) or
  492. * dst is unset, set it to the corresponding value in 'now' if set, otherwise
  493. * set it to 0.
  494. *
  495. * It duplicates tz_abbr if unset in 'parsed' but set in 'now'.
  496. *
  497. * It duplicates tz_info if unset in 'parsed', but set in 'now' unless
  498. * TIMELIB_NO_CLONE is passed, in which case only the pointer in 'parsed' is
  499. * set to 'now'.
  500. *
  501. * If the option TIMELIB_OVERRIDE_TIME is passed and the parsed date/time has
  502. * no time portion, the function will ignore the time aspect in 'now' and
  503. * instead fill it with zeros.
  504. */
  505. void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
  506. /* Tries to convert a time zone abbreviation, gmtoffset and/or isdst flag
  507. * combination to a time zone identifier.
  508. *
  509. * If 'abbr' is either 'utc' or 'gmt' (case insensitve) then "UTC" is
  510. * returned.
  511. *
  512. * It first uses the data in the timezonemap.h file to find a matching
  513. * abbreviation/GMT offset combination. If not found, it uses the data in
  514. * fallbackmap.h to match only the GMT offset/isdst flag to try to find a
  515. * match. If nothing is found, NULL is returned.
  516. *
  517. * The returned char* is not duplicated, and should not be freed.
  518. */
  519. const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
  520. /* Returns an array of known time zone abbreviations
  521. *
  522. * This file is generated from the time zone database through the
  523. * gettzmapping.php scripts, which requires that an up-to-date time zone
  524. * database is used with the PHP binary that runs the script.
  525. *
  526. * Each item in the returned list contains the abbreviation, a flag whether
  527. * it's an abbreviation used with DST, the UTC offset in seconds, and the name
  528. * of the time zone identifier that this abbreviation belongs to.
  529. *
  530. * The order for each specific abbreviation is controlled through the
  531. * preference list in the gettzmapping.php script. Time zones that match the
  532. * pattern ±\d{2,4} are excluded
  533. */
  534. const timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void);
  535. /**
  536. * DEPRECATED, but still used by PHP.
  537. */
  538. timelib_long timelib_parse_zone(const char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper);
  539. /* From parse_iso_intervals.re */
  540. /**
  541. * Parses a subset of an ISO 8601 intervals specification string into its
  542. * constituent parts.
  543. *
  544. * If the **errors points to a timelib_error_container variable, warnings
  545. * and errors will be recorded. You are responsible for freeing the stored
  546. * information with timelib_error_container_dtor(). To see whether errors have
  547. * occurred, inspect errors->errors_count. To see whether warnings have occurred,
  548. * inspect errors->warnings_count.
  549. */
  550. void timelib_strtointerval(const char *s, size_t len,
  551. timelib_time **begin, timelib_time **end,
  552. timelib_rel_time **period, int *recurrences,
  553. timelib_error_container **errors);
  554. /* From tm2unixtime.c */
  555. /**
  556. * Uses the y/m/d/h/i/s fields to calculate and store the equivalent timestamp
  557. * in the sse field.
  558. *
  559. * It uses the time zone information associated with 'time' to account for the
  560. * right UTC offset and/or DST rules. You can associate time zone information
  561. * with the timelib_set_timezone_* functions (see below).
  562. *
  563. * If the type is 'TIMELIB_ZONETYPE_ID' and there is no associated tzinfo, it
  564. * will use the second argument 'tzi' to provide the rules necessary to
  565. * calculate the right timestamp.
  566. */
  567. void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi);
  568. /**
  569. * Returns the number of days from the y/m/d fields of 'time' since the Unix
  570. * Epoch.
  571. */
  572. timelib_sll timelib_epoch_days_from_time(timelib_time *time);
  573. /**
  574. * Takes the information from the y/m/d/h/i/s fields and makes sure their
  575. * values are in the right range.
  576. *
  577. * If a value under- or overflows it will adjust the larger measure up (or
  578. * down). It also takes into account leap days.
  579. */
  580. void timelib_do_normalize(timelib_time *base);
  581. /**
  582. * Takes the information from the y/m/d/h/i/s fields of 'rt' and makes sure
  583. * their values are in the right range.
  584. *
  585. * If a value under- or overflows it will adjust the larger measure up (or
  586. * down). As this function operates on a *relative date/time*, it also takes
  587. * into account leap days and correctly accounts for the difference depending
  588. * on the base date/time in 'base'.
  589. */
  590. void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt);
  591. /* From unixtime2tm.c */
  592. /**
  593. * Takes the unix timestamp in seconds from 'ts', and calculates y, m, and d,
  594. * in the proleptic Gregorian calendar.
  595. *
  596. * It uses the algorithm from howardhinnant.github.io/date_algorithms.html
  597. */
  598. void timelib_unixtime2date(timelib_sll ts, timelib_sll *y, timelib_sll *m, timelib_sll *d);
  599. /**
  600. * Takes the unix timestamp in seconds from 'ts' and populates the y/m/d/h/i/s
  601. * fields of 'tm' without taking time zones into account
  602. */
  603. void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts);
  604. /**
  605. * Takes the Unix timestamp from 'ts', and calculates the y/m/d/h/i/s fields
  606. * according to the time zone information attached to 'tm'.
  607. */
  608. void timelib_unixtime2local(timelib_time *tm, timelib_sll ts);
  609. /**
  610. * Takes the Unix timestamp stored in 'tm', and calculates the y/m/d/h/i/s
  611. * fields according to the time zone information attached to 'tm'.
  612. */
  613. void timelib_update_from_sse(timelib_time *tm);
  614. /**
  615. * Attaches the UTC offset as time zone information to 't'.
  616. *
  617. * 'utc_offset' is in seconds East of UTC.
  618. */
  619. void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset);
  620. /**
  621. * Attaches the information from 'abbr_info' as time zone information to 't'.
  622. *
  623. * The timelib_abbr_info struct contains an abbreviation ('abbr') which string
  624. * value is duplicated, as well as a 'utc_offset' and 'dst' flag. It only
  625. * supports a 'dst' change over of 1 hour.
  626. */
  627. void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info);
  628. /**
  629. * Attaches the time zone information in 'tz' to to 't'.
  630. *
  631. * It fetches the right UTC offset that is currently stored in the time
  632. * stamp field in 't' ('sse'), and assigns that to the 'z' field and 'dst'
  633. * field (whether DST is in effect at the time). It also sets the current
  634. * abbreviation to the 'tz_addr' field, making sure that if a value was already
  635. * set it was freed.
  636. *
  637. * The time zone information in 'tz' is *not* duplicated into the 't' field so
  638. * it should not be freed until all timelib_time* variables have been freed as
  639. * well.
  640. */
  641. void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz);
  642. /* From parse_tz.c */
  643. /**
  644. * Returns whether the time zone ID 'timezone' is available in the time zone
  645. * database as pointed to be 'tzdb'.
  646. */
  647. int timelib_timezone_id_is_valid(const char *timezone, const timelib_tzdb *tzdb);
  648. /**
  649. * Converts the binary stored time zone information from 'tzdb' for the time
  650. * zone 'timezone' into a structure the library can use for calculations.
  651. *
  652. * The function can be used on both timelib_builtin_db as well as a time zone
  653. * db as opened by timelib_zoneinfo.
  654. *
  655. * 'error_code' must not be a null pointer, and will always be written to. If
  656. * the value is TIMELIB_ERROR_NO_ERROR then the file was parsed without
  657. * problems.
  658. *
  659. * The function will return null upon failure, and also set an error code
  660. * through 'error_code'.
  661. *
  662. * The error code is one of the TIMELIB_ERROR_* constants as listed above.
  663. * These error constants can be converted into a string by
  664. * timelib_get_error_message.
  665. *
  666. * If the function returns not-null, the 'error_code' might have a non-null
  667. * value that can be used to detect incompatibilities. The only one that is
  668. * currently detected is whether the file is a 'slim' file, in which case
  669. * 'error_code' will be set to TIMELIB_ERROR_SLIM_FILE.
  670. *
  671. * This function allocates memory for the new time zone structure, which must
  672. * be freed after use. Although it is recommended that a cache of each used
  673. * time zone is kept.
  674. */
  675. timelib_tzinfo *timelib_parse_tzfile(const char *timezone, const timelib_tzdb *tzdb, int *error_code);
  676. /**
  677. * Frees up the resources allocated by 'timelib_parse_tzfile'.
  678. */
  679. void timelib_tzinfo_dtor(timelib_tzinfo *tz);
  680. /**
  681. * Deep-clones a timelib_tzinfo structure.
  682. *
  683. * This allocates resources that need to be freed with 'timelib_tzinfo_dtor'
  684. */
  685. timelib_tzinfo* timelib_tzinfo_clone(timelib_tzinfo *tz);
  686. /**
  687. * Returns whether DST is active with time zone 'tz' for the time stamp 'ts'.
  688. *
  689. * Returns 0 if DST is not active, 1 if DST is active, or -1 if no transitions
  690. * were available through 'tz'.
  691. */
  692. int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz);
  693. /**
  694. * Returns offset information with time zone 'tz' for the time stamp 'ts'.
  695. *
  696. * The returned information contains: the offset in seconds East of UTC (in
  697. * 'offset'), whether DST is active ('is_dst'), what the current time zone
  698. * abbreviation is ('abbr') and the transition time that got to this state (in
  699. * 'transition_time');
  700. */
  701. timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz);
  702. /**
  703. * Returns the UTC offset currently applicable for the information stored in 't'.
  704. *
  705. * The value returned is the UTC offset in seconds East.
  706. */
  707. timelib_sll timelib_get_current_offset(timelib_time *t);
  708. /**
  709. * Returns whether the timezone information in *one and *two are the same
  710. *
  711. * A timezone is considered the same if:
  712. * - the ->zone_type values are the same for *one and *two
  713. * - for TYPE_ABBR and TYPE_OFFSET, ->z + (->dst * 3600), is the same
  714. * - for TYPE_ID, the zone's names are the same
  715. */
  716. int timelib_same_timezone(timelib_time *one, timelib_time *two);
  717. /**
  718. * Displays debugging information about the time zone information in 'tz'.
  719. */
  720. void timelib_dump_tzinfo(timelib_tzinfo *tz);
  721. /**
  722. * Returns a pointer to the built-in time zone database.
  723. *
  724. * You must *not* free the returned pointer as it is part of the text segment.
  725. */
  726. const timelib_tzdb *timelib_builtin_db(void);
  727. /**
  728. * Returns a pointer to the start of an array containing a list of timezone identifiers.
  729. *
  730. * The amount of entries in the array is returned through the 'count' OUT parameter.
  731. *
  732. * Each entry contains the time zone ID ('id' field), and the position within the time zone
  733. * information ('pos' field). The pos field should not be used.
  734. */
  735. const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(const timelib_tzdb *tzdb, int *count);
  736. /* From parse_zoneinfo.c */
  737. /**
  738. * Scans the directory and subdirectories of 'directory' for valid time zone files and builds
  739. * a time zone database out of these files.
  740. *
  741. * Typically, the directory should point to '/usr/share/zoneinfo'.
  742. *
  743. * Unlike 'timelib_builtin_db', the return value of this function must be freed
  744. * with the 'timelib_zoneinfo_dtor' function.
  745. */
  746. timelib_tzdb *timelib_zoneinfo(const char *directory);
  747. /**
  748. * Frees up the resources as created through 'timelib_zoneinfo'.
  749. *
  750. * This function must be used to free up all the resources that have been
  751. * allocated while calling 'timelib_zoneinfo'.
  752. */
  753. void timelib_zoneinfo_dtor(timelib_tzdb *tzdb);
  754. /* From timelib.c */
  755. /**
  756. * Returns a static string containing an error message belonging to a specific
  757. * error code.
  758. */
  759. const char *timelib_get_error_message(int error_code);
  760. /**
  761. * Allocates resources for the relative time structure.
  762. *
  763. * Must be freed with 'timelib_rel_time_dtor'.
  764. */
  765. timelib_rel_time* timelib_rel_time_ctor(void);
  766. /**
  767. * Frees up the resources as allocated through 'timelib_rel_time_ctor'.
  768. */
  769. void timelib_rel_time_dtor(timelib_rel_time* t);
  770. /**
  771. * Creates a new timelib_rel_time resource and copies over the information
  772. * from 'tz'.
  773. *
  774. * Must be freed with 'timelib_rel_time_dtor'.
  775. */
  776. timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *tz);
  777. /**
  778. * Allocates resources for the time structure.
  779. *
  780. * Must be freed with 'timelib_time_dtor'.
  781. */
  782. timelib_time* timelib_time_ctor(void);
  783. /**
  784. * Frees up the resources as allocated through 'timelib_time_ctor'.
  785. */
  786. void timelib_time_dtor(timelib_time* t);
  787. /**
  788. * Creates a new timelib_time resource and copies over the information
  789. * from 'orig'.
  790. *
  791. * Must be freed with 'timelib_time_dtor'.
  792. */
  793. timelib_time* timelib_time_clone(timelib_time* orig);
  794. /**
  795. * Compares two timelib_time structures and returns which one is earlier in
  796. * time.
  797. *
  798. * To decide which comes earlier it uses the 'sse' (Seconds Since Epoch) and
  799. * 'us' (microseconds) fields.
  800. *
  801. * Returns -1 if t1 < t2, 0 if t1 == t2, and -1 if t1 > t2.
  802. */
  803. int timelib_time_compare(timelib_time *t1, timelib_time *t2);
  804. /**
  805. * Allocates resources for the time offset structure.
  806. *
  807. * Must be freed with 'timelib_time_offset_dtor'.
  808. */
  809. timelib_time_offset* timelib_time_offset_ctor(void);
  810. /**
  811. * Frees up the resources as allocated through 'timelib_time_offset_ctor'.
  812. */
  813. void timelib_time_offset_dtor(timelib_time_offset* t);
  814. /**
  815. * Frees up the resources allocated while converting strings to timelib_time
  816. * structures with the timelib_strtotime and timelib_strtointerval functions.
  817. */
  818. void timelib_error_container_dtor(timelib_error_container *errors);
  819. /**
  820. * Converts the 'sse' value of 'd' to a timelib_long type.
  821. *
  822. * If the value fits in the TIMELIB_LONG_MIN and TIMELIB_LONG_MAX range, the
  823. * value is cast to (timelib_long) and returned. If *error is not a NULL
  824. * pointer, it will be set to 0.
  825. *
  826. * If the value does *not* fit in the range, the function returns 0 and if
  827. * *error is not a NULL pointer, it will be set to 1.
  828. *
  829. * timelib_long is a 32 bit signed long integer on 32 bit platforms, and a 64
  830. * bit signed long long integer on 64 bit platforms. In other words, it makes
  831. * sure that the value in 'sse' (which is always a signed long long 64 bit
  832. * integer) can be used safely outside of the library.
  833. */
  834. timelib_long timelib_date_to_int(timelib_time *d, int *error);
  835. /**
  836. * Displays debugging information about the date/time information stored in 'd'.
  837. *
  838. * 'options' is a bit field, where:
  839. * - 1 controls whether the relative time portion is shown.
  840. * - 2 controls whether the zone type is shown.
  841. */
  842. void timelib_dump_date(timelib_time *d, int options);
  843. /**
  844. * Displays debugging information about the relative time information stored
  845. * in 'd'.
  846. */
  847. void timelib_dump_rel_time(timelib_rel_time *d);
  848. /**
  849. * Converts a decimal hour into hour/min/sec components
  850. */
  851. void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec);
  852. /**
  853. * Converts hour/min/sec values into a decimal hour
  854. */
  855. void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h);
  856. /**
  857. * Converts hour/min/sec/micro sec values into a decimal hour
  858. */
  859. void timelib_hmsf_to_decimal_hour(int hour, int min, int sec, int us, double *h);
  860. /**
  861. * Converts hour/min/sec values into seconds
  862. */
  863. timelib_sll timelib_hms_to_seconds(timelib_sll h, timelib_sll m, timelib_sll s);
  864. /* from astro.c */
  865. /**
  866. * Converts the Unix Epoch time stamp 'ts' to a Julian Day
  867. *
  868. * The value returned is the number of whole days since -4714-11-24T12:00:00 UTC
  869. * (in the proleptic Gregorian calendar):
  870. * https://en.wikipedia.org/wiki/Julian_day
  871. */
  872. double timelib_ts_to_julianday(timelib_sll ts);
  873. /**
  874. * Converts the Unix Epoch time stamp 'ts' to the J2000 epoch
  875. *
  876. * The value returned is the number of whole days since 2000-01-01T12:00:00
  877. * UTC: https://en.wikipedia.org/wiki/Epoch_(astronomy)#Julian_years_and_J2000
  878. */
  879. double timelib_ts_to_j2000(timelib_sll ts);
  880. /**
  881. * Calculates when the Sun is above a certain latitude.
  882. *
  883. * Parameters:
  884. * - time: A timelib_time time describing that needs to specific midnight for a
  885. * specific day.
  886. * - lon: The longitude of the observer (East positive, West negative).
  887. * - lat: The latitude of the observer (North positive, South negative).
  888. * - altit: The altitude. Set to -35/60 for rise/set, -6 for civil twilight,
  889. * -12 for nautical, and -18 for astronomical twilight.
  890. * - upper_limb: set to non-zero for rise/set calculations, and 0 for twilight
  891. * calculations.
  892. *
  893. * Out Parameters:
  894. * - h_rise: The decimal hour when the Sun rises
  895. * - h_set: The decimal hour when the Sun sets
  896. * - ts_rise: The Unix timestamp of the Sun rising
  897. * - ts_set: The Unix timestamp of the Sun setting
  898. * - ts_transit: The Unix timestmap of the Sun transitting through South
  899. *
  900. * Return Values:
  901. * - 0: The Sun rises and sets.
  902. * - +1: The Sun is always above the horizon. (ts_rise is set to ts_transit -
  903. * (12 * 3600); ts_set is set to ts_transit + (12 * 3600).
  904. * - -1: The Sun is awlays below the horizon. (ts_rise and ts_set are set
  905. * to ts_transit)
  906. */
  907. int timelib_astro_rise_set_altitude(timelib_time *time, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit);
  908. /* from interval.c */
  909. /**
  910. * Calculates the difference between two times
  911. *
  912. * The result is a timelib_rel_time structure that describes how you can
  913. * convert from 'one' to 'two' with 'timelib_add'. This does *not* necessarily
  914. * mean that you can go from 'two' to 'one' by using 'timelib_sub' due to the
  915. * way months and days are calculated.
  916. */
  917. timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two);
  918. /**
  919. * Calculates the difference in full days between two times
  920. *
  921. * The result is the number of full days between 'one' and 'two'. It does take
  922. * into account 23 and 25 hour (and variants) days when the zone_type
  923. * is TIMELIB_ZONETYPE_ID and have the same TZID for 'one' and 'two'.
  924. */
  925. int timelib_diff_days(timelib_time *one, timelib_time *two);
  926. /**
  927. * Adds the relative time information 'interval' to the base time 't'.
  928. *
  929. * This can be a relative time as created by 'timelib_diff', but also by more
  930. * complex statements such as "next workday".
  931. */
  932. timelib_time *timelib_add(timelib_time *t, timelib_rel_time *interval);
  933. timelib_time *timelib_add_wall(timelib_time *t, timelib_rel_time *interval);
  934. /**
  935. * Subtracts the relative time information 'interval' to the base time 't'.
  936. *
  937. * This can be a relative time as created by 'timelib_diff'. Unlike with
  938. * 'timelib_add', this does not support more complex statements such as "next
  939. * workday".
  940. */
  941. timelib_time *timelib_sub(timelib_time *t, timelib_rel_time *interval);
  942. timelib_time *timelib_sub_wall(timelib_time *t, timelib_rel_time *interval);
  943. /* from parse_posix.c */
  944. void timelib_posix_str_dtor(timelib_posix_str *ps);
  945. timelib_posix_str* timelib_parse_posix_str(const char *posix);
  946. /**
  947. * Calculate the two yearly to/from DST
  948. */
  949. void timelib_get_transitions_for_year(timelib_tzinfo *tz, timelib_sll year, timelib_posix_transitions *transitions);
  950. #ifdef __cplusplus
  951. } /* extern "C" */
  952. #endif
  953. #endif