timelib.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2015 Derick Rethans
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef __TIMELIB_H__
  25. #define __TIMELIB_H__
  26. #include "timelib_structs.h"
  27. #if HAVE_LIMITS_H
  28. #include <limits.h>
  29. #endif
  30. #ifndef timelib_malloc
  31. # define timelib_malloc malloc
  32. # define timelib_realloc realloc
  33. # define timelib_calloc calloc
  34. # define timelib_strdup strdup
  35. # define timelib_free free
  36. #endif
  37. #define TIMELIB_VERSION 201602
  38. #define TIMELIB_ASCII_VERSION "2016.02"
  39. #define TIMELIB_NONE 0x00
  40. #define TIMELIB_OVERRIDE_TIME 0x01
  41. #define TIMELIB_NO_CLONE 0x02
  42. #define TIMELIB_UNSET -99999
  43. #define TIMELIB_SPECIAL_WEEKDAY 0x01
  44. #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02
  45. #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03
  46. #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01
  47. #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02
  48. #ifndef LONG_MAX
  49. #define LONG_MAX 2147483647L
  50. #endif
  51. #ifndef LONG_MIN
  52. #define LONG_MIN (- LONG_MAX - 1)
  53. #endif
  54. #if defined(_MSC_VER) && !defined(strcasecmp)
  55. #define strcasecmp stricmp
  56. #endif
  57. #if defined(_MSC_VER) && !defined(strncasecmp)
  58. #define strncasecmp strnicmp
  59. #endif
  60. /* Function pointers */
  61. typedef timelib_tzinfo* (*timelib_tz_get_wrapper)(char *tzname, const timelib_tzdb *tzdb);
  62. /* From dow.c */
  63. timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d);
  64. timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d);
  65. timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d);
  66. timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d);
  67. timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m);
  68. void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy);
  69. int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s);
  70. int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d);
  71. /* From parse_date.re */
  72. timelib_time *timelib_strtotime(char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper);
  73. timelib_time *timelib_parse_from_format(char *format, char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper);
  74. void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
  75. char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
  76. const timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void);
  77. timelib_long timelib_parse_tz_cor(char**);
  78. /* From parse_iso_intervals.re */
  79. void timelib_strtointerval(char *s, size_t len,
  80. timelib_time **begin, timelib_time **end,
  81. timelib_rel_time **period, int *recurrences,
  82. struct timelib_error_container **errors);
  83. /* From tm2unixtime.c */
  84. void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi);
  85. void timelib_do_normalize(timelib_time *base);
  86. void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt);
  87. /* From unixtime2tm.c */
  88. int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
  89. void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts);
  90. void timelib_unixtime2local(timelib_time *tm, timelib_sll ts);
  91. void timelib_update_from_sse(timelib_time *tm);
  92. void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset);
  93. void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info);
  94. void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz);
  95. /* From parse_tz.c */
  96. int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb);
  97. timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb);
  98. int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz);
  99. timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz);
  100. timelib_sll timelib_get_current_offset(timelib_time *t);
  101. void timelib_dump_tzinfo(timelib_tzinfo *tz);
  102. const timelib_tzdb *timelib_builtin_db(void);
  103. const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count);
  104. timelib_long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper);
  105. /* From timelib.c */
  106. timelib_tzinfo* timelib_tzinfo_ctor(char *name);
  107. void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr);
  108. void timelib_time_tz_name_update(timelib_time* tm, char* tz_name);
  109. void timelib_tzinfo_dtor(timelib_tzinfo *tz);
  110. timelib_tzinfo* timelib_tzinfo_clone(timelib_tzinfo *tz);
  111. timelib_rel_time* timelib_rel_time_ctor(void);
  112. void timelib_rel_time_dtor(timelib_rel_time* t);
  113. timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *tz);
  114. timelib_time* timelib_time_ctor(void);
  115. void timelib_time_set_option(timelib_time* tm, int option, void* option_value);
  116. void timelib_time_dtor(timelib_time* t);
  117. timelib_time* timelib_time_clone(timelib_time* orig);
  118. int timelib_time_compare(timelib_time *t1, timelib_time *t2);
  119. timelib_time_offset* timelib_time_offset_ctor(void);
  120. void timelib_time_offset_dtor(timelib_time_offset* t);
  121. void timelib_error_container_dtor(timelib_error_container *errors);
  122. timelib_long timelib_date_to_int(timelib_time *d, int *error);
  123. void timelib_dump_date(timelib_time *d, int options);
  124. void timelib_dump_rel_time(timelib_rel_time *d);
  125. void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec);
  126. timelib_long timelib_parse_tz_cor(char **ptr);
  127. /* from astro.c */
  128. double timelib_ts_to_juliandate(timelib_sll ts);
  129. 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);
  130. /* from interval.c */
  131. timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two);
  132. timelib_time *timelib_add(timelib_time *t, timelib_rel_time *interval);
  133. timelib_time *timelib_sub(timelib_time *t, timelib_rel_time *interval);
  134. #endif