diff options
Diffstat (limited to 'xs_time.h')
| -rw-r--r-- | xs_time.h | 124 |
1 files changed, 124 insertions, 0 deletions
| @@ -15,6 +15,8 @@ time_t xs_parse_time(const char *str, const char *fmt, int local); | |||
| 15 | #define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1) | 15 | #define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1) |
| 16 | #define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0) | 16 | #define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0) |
| 17 | xs_str *xs_str_time_diff(time_t time_diff); | 17 | xs_str *xs_str_time_diff(time_t time_diff); |
| 18 | xs_list *xs_tz_list(void); | ||
| 19 | int xs_tz_offset(const char *tz); | ||
| 18 | 20 | ||
| 19 | #ifdef XS_IMPLEMENTATION | 21 | #ifdef XS_IMPLEMENTATION |
| 20 | 22 | ||
| @@ -106,6 +108,128 @@ time_t xs_parse_iso_date(const char *iso_date, int local) | |||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | 110 | ||
| 111 | /** timezones **/ | ||
| 112 | |||
| 113 | /* intentionally dead simple */ | ||
| 114 | |||
| 115 | struct { | ||
| 116 | const char *tz; /* timezone name */ | ||
| 117 | float h_offset; /* hour offset */ | ||
| 118 | } xs_tz[] = { | ||
| 119 | { "UTC", 0 }, | ||
| 120 | { "WET (Western European Time)", 0 }, | ||
| 121 | { "WEST (Western European Summer Time)", 1 }, | ||
| 122 | { "CET (Central European Time)", 1 }, | ||
| 123 | { "CEST (Central European Summer Time)", 2 }, | ||
| 124 | { "EET (Eastern European Time)", 2 }, | ||
| 125 | { "EEST (Eastern European Summer Time)", 3 }, | ||
| 126 | { "MSK (Moskow Time Zone)", 3 }, | ||
| 127 | { "EST (Eastern Time Zone)", -5 }, | ||
| 128 | { "AST (Atlantic Time Zone)", -4 }, | ||
| 129 | { "ADT (Atlantic Daylight Time Zone)", -3 }, | ||
| 130 | { "CST (Central Time Zone)", -6 }, | ||
| 131 | { "CDT (Central Daylight Time Zone)", -5 }, | ||
| 132 | { "MST (Mountain Time Zone)", -7 }, | ||
| 133 | { "MDT (Mountain Daylight Time Zone)", -6 }, | ||
| 134 | { "PST (Pacific Time Zone)", -8 }, | ||
| 135 | { "PDT (Pacific Daylight Time Zone)", -7 }, | ||
| 136 | { "AKST (Alaska Time Zone)", -9 }, | ||
| 137 | { "AKDT (Alaska Daylight Time Zone)", -8 }, | ||
| 138 | { "China Time Zone", 8 }, | ||
| 139 | { "IST (Israel Standard Time)", 2 }, | ||
| 140 | { "IDT (Israel Daylight Standard Time)", 3 }, | ||
| 141 | { "WIB (Western Indonesia Time)", 7 }, | ||
| 142 | { "WITA (Central Indonesia Time)", 8 }, | ||
| 143 | { "WIT (Eastern Indonesia Time)", 9 }, | ||
| 144 | { "AWST (Australian Western Time)", 8 }, | ||
| 145 | { "ACST (Australian Eastern Time)", 9.5 }, | ||
| 146 | { "ACDT (Australian Daylight Eastern Time)", 10.5 }, | ||
| 147 | { "AEST (Australian Eastern Time)", 10 }, | ||
| 148 | { "AEDT (Australian Daylight Eastern Time)", 11 }, | ||
| 149 | { "NZST (New Zealand Time)", 12 }, | ||
| 150 | { "NZDT (New Zealand Daylight Time)", 13 }, | ||
| 151 | { "UTC", 0 }, | ||
| 152 | { "UTC+1", 1 }, | ||
| 153 | { "UTC+2", 2 }, | ||
| 154 | { "UTC+3", 3 }, | ||
| 155 | { "UTC+4", 4 }, | ||
| 156 | { "UTC+5", 5 }, | ||
| 157 | { "UTC+6", 6 }, | ||
| 158 | { "UTC+7", 7 }, | ||
| 159 | { "UTC+8", 8 }, | ||
| 160 | { "UTC+9", 9 }, | ||
| 161 | { "UTC+10", 10 }, | ||
| 162 | { "UTC+11", 11 }, | ||
| 163 | { "UTC+12", 12 }, | ||
| 164 | { "UTC-1", -1 }, | ||
| 165 | { "UTC-2", -2 }, | ||
| 166 | { "UTC-3", -3 }, | ||
| 167 | { "UTC-4", -4 }, | ||
| 168 | { "UTC-5", -5 }, | ||
| 169 | { "UTC-6", -6 }, | ||
| 170 | { "UTC-7", -7 }, | ||
| 171 | { "UTC-8", -8 }, | ||
| 172 | { "UTC-9", -9 }, | ||
| 173 | { "UTC-10", -10 }, | ||
| 174 | { "UTC-11", -11 }, | ||
| 175 | { "UTC-12", -12 }, | ||
| 176 | { "UTC-13", -13 }, | ||
| 177 | { "UTC-14", -14 }, | ||
| 178 | { "GMT", 0 }, | ||
| 179 | { "GMT+1", -1 }, | ||
| 180 | { "GMT+2", -2 }, | ||
| 181 | { "GMT+3", -3 }, | ||
| 182 | { "GMT+4", -4 }, | ||
| 183 | { "GMT+5", -5 }, | ||
| 184 | { "GMT+6", -6 }, | ||
| 185 | { "GMT+7", -7 }, | ||
| 186 | { "GMT+8", -8 }, | ||
| 187 | { "GMT+9", -9 }, | ||
| 188 | { "GMT+10", -10 }, | ||
| 189 | { "GMT+11", -11 }, | ||
| 190 | { "GMT+12", -12 }, | ||
| 191 | { "GMT-1", 1 }, | ||
| 192 | { "GMT-2", 2 }, | ||
| 193 | { "GMT-3", 3 }, | ||
| 194 | { "GMT-4", 4 }, | ||
| 195 | { "GMT-5", 5 }, | ||
| 196 | { "GMT-6", 6 }, | ||
| 197 | { "GMT-7", 7 }, | ||
| 198 | { "GMT-8", 8 }, | ||
| 199 | { "GMT-9", 9 }, | ||
| 200 | { "GMT-10", 10 }, | ||
| 201 | { "GMT-11", 11 }, | ||
| 202 | { "GMT-12", 12 }, | ||
| 203 | { "GMT-13", 13 }, | ||
| 204 | { "GMT-14", 14 }, | ||
| 205 | { NULL, 0 } | ||
| 206 | }; | ||
| 207 | |||
| 208 | |||
| 209 | xs_list *xs_tz_list(void) | ||
| 210 | /* returns the list of supported timezones */ | ||
| 211 | { | ||
| 212 | xs_list *l = xs_list_new(); | ||
| 213 | |||
| 214 | for (int n = 0; xs_tz[n].tz != NULL; n++) | ||
| 215 | l = xs_list_append(l, xs_tz[n].tz); | ||
| 216 | |||
| 217 | return l; | ||
| 218 | } | ||
| 219 | |||
| 220 | |||
| 221 | int xs_tz_offset(const char *tz) | ||
| 222 | /* returns the offset in seconds from the specified Time Zone to UTC */ | ||
| 223 | { | ||
| 224 | for (int n = 0; xs_tz[n].tz != NULL; n++) { | ||
| 225 | if (strcmp(xs_tz[n].tz, tz) == 0) | ||
| 226 | return xs_tz[n].h_offset * 3600; | ||
| 227 | } | ||
| 228 | |||
| 229 | return 0; | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 109 | #endif /* XS_IMPLEMENTATION */ | 233 | #endif /* XS_IMPLEMENTATION */ |
| 110 | 234 | ||
| 111 | #endif /* _XS_TIME_H */ | 235 | #endif /* _XS_TIME_H */ |