xref: /PHP-7.2/ext/date/lib/timelib_private.h (revision 5feb5396)
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_PRIVATE_H__
26 #define __TIMELIB_PRIVATE_H__
27 
28 #ifdef HAVE_TIMELIB_CONFIG_H
29 # include "timelib_config.h"
30 #endif
31 
32 #ifdef HAVE_SYS_TIME_H
33 # include <sys/time.h>
34 #endif
35 
36 #ifdef _WIN32
37 # ifdef HAVE_WINSOCK2_H
38 #  include <winsock2.h>
39 # endif
40 #endif
41 
42 #ifdef HAVE_STRING_H
43 # include <string.h>
44 #endif
45 
46 #ifdef HAVE_STRINGS_H
47 # include <strings.h>
48 #endif
49 
50 #ifdef HAVE_SYS_TYPES_H
51 #include <sys/types.h>
52 #endif
53 
54 #if defined(HAVE_STDINT_H)
55 # include <stdint.h>
56 #endif
57 
58 #if HAVE_UNISTD_H
59 # include <unistd.h>
60 #endif
61 
62 #if HAVE_IO_H
63 # include <io.h>
64 #endif
65 
66 #if HAVE_DIRENT_H
67 # include <dirent.h>
68 #endif
69 
70 #include <stdio.h>
71 
72 #if HAVE_LIMITS_H
73 #include <limits.h>
74 #endif
75 
76 #define TIMELIB_SECOND   1
77 #define TIMELIB_MINUTE   2
78 #define TIMELIB_HOUR     3
79 #define TIMELIB_DAY      4
80 #define TIMELIB_MONTH    5
81 #define TIMELIB_YEAR     6
82 #define TIMELIB_WEEKDAY  7
83 #define TIMELIB_SPECIAL  8
84 #define TIMELIB_MICROSEC 9
85 
86 #define TIMELIB_SPECIAL_WEEKDAY                   0x01
87 #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH      0x02
88 #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03
89 
90 #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH        0x01
91 #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH         0x02
92 
93 #define SECS_PER_ERA   TIMELIB_LL_CONST(12622780800)
94 #define SECS_PER_DAY   86400
95 #define DAYS_PER_YEAR    365
96 #define DAYS_PER_LYEAR   366
97 /* 400*365 days + 97 leap days */
98 #define DAYS_PER_LYEAR_PERIOD 146097
99 #define YEARS_PER_LYEAR_PERIOD 400
100 
101 #define TIMELIB_TZINFO_PHP       0x01
102 #define TIMELIB_TZINFO_ZONEINFO  0x02
103 
104 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
105 
106 #define TIMELIB_DEBUG(s)  if (0) { s }
107 
108 #define TIMELIB_TIME_FREE(m)    \
109 	if (m) {        \
110 		timelib_free(m);    \
111 		m = NULL;   \
112 	}
113 
114 struct _ttinfo
115 {
116 	int32_t      offset;
117 	int          isdst;
118 	unsigned int abbr_idx;
119 
120 	unsigned int isstdcnt;
121 	unsigned int isgmtcnt;
122 };
123 
124 struct _tlinfo
125 {
126 	int32_t  trans;
127 	int32_t  offset;
128 };
129 
130 
131 #ifndef LONG_MAX
132 #define LONG_MAX 2147483647L
133 #endif
134 
135 #ifndef LONG_MIN
136 #define LONG_MIN (- LONG_MAX - 1)
137 #endif
138 
139 /* From unixtime2tm.c */
140 int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
141 
142 /* From parse_tz.c */
143 void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr);
144 
145 /* From timelib.c */
146 int timelib_strcasecmp(const char *s1, const char *s2);
147 int timelib_strncasecmp(const char *s1, const char *s2, size_t n);
148 
149 #endif
150