1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 5 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1997-2015 The PHP Group | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 3.01 of the PHP license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.php.net/license/3_01.txt | 11 | If you did not receive a copy of the PHP license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@php.net so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Authors: Derick Rethans <derick@derickrethans.nl> | 16 +----------------------------------------------------------------------+ 17 */ 18 19 /* $Id$ */ 20 21 #ifndef __TIMELIB_H__ 22 #define __TIMELIB_H__ 23 24 #include "timelib_structs.h" 25 #if HAVE_LIMITS_H 26 #include <limits.h> 27 #endif 28 29 #define TIMELIB_VERSION 201102 30 31 #define TIMELIB_NONE 0x00 32 #define TIMELIB_OVERRIDE_TIME 0x01 33 #define TIMELIB_NO_CLONE 0x02 34 35 #define TIMELIB_UNSET -99999 36 37 #define TIMELIB_SPECIAL_WEEKDAY 0x01 38 #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02 39 #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03 40 41 #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01 42 #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02 43 44 #ifndef LONG_MAX 45 #define LONG_MAX 2147483647L 46 #endif 47 48 #ifndef LONG_MIN 49 #define LONG_MIN (- LONG_MAX - 1) 50 #endif 51 52 #if defined(_MSC_VER) && !defined(strcasecmp) 53 #define strcasecmp stricmp 54 #endif 55 56 #if defined(_MSC_VER) && !defined(strncasecmp) 57 #define strncasecmp strnicmp 58 #endif 59 60 /* Function pointers */ 61 typedef timelib_tzinfo* (*timelib_tz_get_wrapper)(char *tzname, const timelib_tzdb *tzdb); 62 63 /* From dow.c */ 64 timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); 65 timelib_sll timelib_iso_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); 66 timelib_sll timelib_day_of_year(timelib_sll y, timelib_sll m, timelib_sll d); 67 timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d); 68 timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m); 69 void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy); 70 int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s); 71 int timelib_valid_date(timelib_sll y, timelib_sll m, timelib_sll d); 72 73 /* From parse_date.re */ 74 timelib_time *timelib_strtotime(char *s, int len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper); 75 timelib_time *timelib_parse_from_format(char *format, char *s, int len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper); 76 void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options); 77 char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst); 78 const timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void); 79 long timelib_parse_tz_cor(char**); 80 81 /* From parse_iso_intervals.re */ 82 void timelib_strtointerval(char *s, int len, 83 timelib_time **begin, timelib_time **end, 84 timelib_rel_time **period, int *recurrences, 85 struct timelib_error_container **errors); 86 87 88 /* From tm2unixtime.c */ 89 void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi); 90 void timelib_do_normalize(timelib_time *base); 91 void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt); 92 93 /* From unixtime2tm.c */ 94 int timelib_apply_localtime(timelib_time *t, unsigned int localtime); 95 void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts); 96 void timelib_unixtime2local(timelib_time *tm, timelib_sll ts); 97 void timelib_update_from_sse(timelib_time *tm); 98 void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset); 99 void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info); 100 void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz); 101 102 /* From parse_tz.c */ 103 int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb); 104 timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb); 105 int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz); 106 timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz); 107 timelib_sll timelib_get_current_offset(timelib_time *t); 108 void timelib_dump_tzinfo(timelib_tzinfo *tz); 109 const timelib_tzdb *timelib_builtin_db(void); 110 const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count); 111 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); 112 113 /* From timelib.c */ 114 timelib_tzinfo* timelib_tzinfo_ctor(char *name); 115 void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr); 116 void timelib_time_tz_name_update(timelib_time* tm, char* tz_name); 117 void timelib_tzinfo_dtor(timelib_tzinfo *tz); 118 timelib_tzinfo* timelib_tzinfo_clone(timelib_tzinfo *tz); 119 120 timelib_rel_time* timelib_rel_time_ctor(void); 121 void timelib_rel_time_dtor(timelib_rel_time* t); 122 timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *tz); 123 124 timelib_time* timelib_time_ctor(void); 125 void timelib_time_set_option(timelib_time* tm, int option, void* option_value); 126 void timelib_time_dtor(timelib_time* t); 127 timelib_time* timelib_time_clone(timelib_time* orig); 128 129 timelib_time_offset* timelib_time_offset_ctor(void); 130 void timelib_time_offset_dtor(timelib_time_offset* t); 131 132 void timelib_error_container_dtor(timelib_error_container *errors); 133 134 signed long timelib_date_to_int(timelib_time *d, int *error); 135 void timelib_dump_date(timelib_time *d, int options); 136 void timelib_dump_rel_time(timelib_rel_time *d); 137 138 void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec); 139 long timelib_parse_tz_cor(char **ptr); 140 141 /* from astro.c */ 142 double timelib_ts_to_juliandate(timelib_sll ts); 143 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); 144 145 /* from interval.c */ 146 timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two); 147 timelib_time *timelib_add(timelib_time *t, timelib_rel_time *interval); 148 timelib_time *timelib_sub(timelib_time *t, timelib_rel_time *interval); 149 150 #endif 151