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 25 #ifndef __TIMELIB_H__ 26 #define __TIMELIB_H__ 27 28 #include "timelib_structs.h" 29 #if HAVE_LIMITS_H 30 #include <limits.h> 31 #endif 32 33 #ifndef timelib_malloc 34 # define timelib_malloc malloc 35 # define timelib_realloc realloc 36 # define timelib_calloc calloc 37 # define timelib_strdup strdup 38 # define timelib_free free 39 #endif 40 41 #define TIMELIB_VERSION 201602 42 #define TIMELIB_ASCII_VERSION "2016.02" 43 44 #define TIMELIB_NONE 0x00 45 #define TIMELIB_OVERRIDE_TIME 0x01 46 #define TIMELIB_NO_CLONE 0x02 47 48 #define TIMELIB_UNSET -99999 49 50 #define TIMELIB_SPECIAL_WEEKDAY 0x01 51 #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02 52 #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03 53 54 #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01 55 #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02 56 57 #ifndef LONG_MAX 58 #define LONG_MAX 2147483647L 59 #endif 60 61 #ifndef LONG_MIN 62 #define LONG_MIN (- LONG_MAX - 1) 63 #endif 64 65 #if defined(_MSC_VER) && !defined(strcasecmp) 66 #define strcasecmp stricmp 67 #endif 68 69 #if defined(_MSC_VER) && !defined(strncasecmp) 70 #define strncasecmp strnicmp 71 #endif 72 73 /* Function pointers */ 74 typedef timelib_tzinfo* (*timelib_tz_get_wrapper)(char *tzname, const timelib_tzdb *tzdb); 75 76 /* From dow.c */ 77 timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); 78 timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); 79 timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d); 80 timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d); 81 timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m); 82 void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy); 83 int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s); 84 int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d); 85 86 /* From parse_date.re */ 87 timelib_time *timelib_strtotime(char *s, size_t len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper); 88 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); 89 void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options); 90 char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst); 91 const timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void); 92 timelib_long timelib_parse_tz_cor(char**); 93 94 /* From parse_iso_intervals.re */ 95 void timelib_strtointerval(char *s, size_t len, 96 timelib_time **begin, timelib_time **end, 97 timelib_rel_time **period, int *recurrences, 98 struct timelib_error_container **errors); 99 100 101 /* From tm2unixtime.c */ 102 void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi); 103 void timelib_do_normalize(timelib_time *base); 104 void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt); 105 106 /* From unixtime2tm.c */ 107 int timelib_apply_localtime(timelib_time *t, unsigned int localtime); 108 void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts); 109 void timelib_unixtime2local(timelib_time *tm, timelib_sll ts); 110 void timelib_update_from_sse(timelib_time *tm); 111 void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset); 112 void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info); 113 void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz); 114 115 /* From parse_tz.c */ 116 int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb); 117 timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb); 118 int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz); 119 timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz); 120 timelib_sll timelib_get_current_offset(timelib_time *t); 121 void timelib_dump_tzinfo(timelib_tzinfo *tz); 122 const timelib_tzdb *timelib_builtin_db(void); 123 const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count); 124 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); 125 126 /* From timelib.c */ 127 timelib_tzinfo* timelib_tzinfo_ctor(char *name); 128 void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr); 129 void timelib_time_tz_name_update(timelib_time* tm, char* tz_name); 130 void timelib_tzinfo_dtor(timelib_tzinfo *tz); 131 timelib_tzinfo* timelib_tzinfo_clone(timelib_tzinfo *tz); 132 133 timelib_rel_time* timelib_rel_time_ctor(void); 134 void timelib_rel_time_dtor(timelib_rel_time* t); 135 timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *tz); 136 137 timelib_time* timelib_time_ctor(void); 138 void timelib_time_set_option(timelib_time* tm, int option, void* option_value); 139 void timelib_time_dtor(timelib_time* t); 140 timelib_time* timelib_time_clone(timelib_time* orig); 141 int timelib_time_compare(timelib_time *t1, timelib_time *t2); 142 143 timelib_time_offset* timelib_time_offset_ctor(void); 144 void timelib_time_offset_dtor(timelib_time_offset* t); 145 146 void timelib_error_container_dtor(timelib_error_container *errors); 147 148 timelib_long timelib_date_to_int(timelib_time *d, int *error); 149 void timelib_dump_date(timelib_time *d, int options); 150 void timelib_dump_rel_time(timelib_rel_time *d); 151 152 void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec); 153 timelib_long timelib_parse_tz_cor(char **ptr); 154 155 /* from astro.c */ 156 double timelib_ts_to_juliandate(timelib_sll ts); 157 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); 158 159 /* from interval.c */ 160 timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two); 161 timelib_time *timelib_add(timelib_time *t, timelib_rel_time *interval); 162 timelib_time *timelib_sub(timelib_time *t, timelib_rel_time *interval); 163 164 #endif 165