- MF51: Implemented better timezone guessing algorithm.

This commit is contained in:
Derick Rethans 2005-10-01 15:07:20 +00:00
parent 7db47e291b
commit 2eaf85c481
10 changed files with 1882 additions and 452 deletions

View File

@ -0,0 +1,34 @@
{ "hst", 0, -10, "Pacific/Honolulu" },
{ "akst", 0, -9, "America/Anchorage" },
{ "akdt", 1, -8, "America/Anchorage" },
{ "pst", 0, -8, "America/Los_Angeles" },
{ "pdt", 1, -7, "America/Los_Angeles" },
{ "mst", 0, -7, "America/Denver" },
{ "mdt", 1, -6, "America/Denver" },
{ "cst", 0, -6, "America/Chicago" },
{ "cdt", 1, -5, "America/Chicago" },
{ "est", 0, -5, "America/New_York" },
{ "edt", 1, -4, "America/New_York" },
{ "ast", 0, -4, "America/Halifax" },
{ "adt", 0, -3, "America/Halifax" },
{ "gmt", 0, 0, "Europe/London" },
{ "bst", 1, 1, "Europe/London" },
{ "cet", 0, 1, "Europe/Paris" },
{ "cest", 1, 2, "Europe/Paris" },
{ "eet", 0, 2, "Europe/Helsinki" },
{ "eest", 1, 3, "Europe/Helsinki" },
{ "msk", 0, 3, "Europe/Moscow" },
{ "msd", 1, 4, "Europe/Moscow" },
{ "gst", 0, 4, "Asia/Dubai" },
{ "pkt", 0, 5, "Asia/Karachi" },
{ "ist", 0, 5.5, "Asia/Calcutta" },
{ "npt", 0, 5.75, "Asia/Katmandu" },
{ "novst", 1, 7, "Asia/Novosibirsk" },
{ "krat", 0, 7, "Asia/Krasnoyarsk" },
{ "krast", 1, 8, "Asia/Krasnoyarsk" },
{ "jst", 0, 9, "Asia/Tokyo" },
{ "est", 0, 10, "Australia/Melbourne" },
{ "cst", 1, 10.5, "Australia/Adelaide" },
{ "est", 1, 11, "Australia/Melbourne" },
{ "nzst", 0, 12, "Pacific/Auckland" },
{ "nzdt", 1, 13, "Pacific/Auckland" },

View File

@ -1,4 +1,4 @@
/* Generated by re2c 0.9.10.dev on Thu Aug 25 11:40:22 2005 */
/* Generated by re2c 0.9.10.dev on Sat Oct 1 17:04:46 2005 */
#line 1 "resource/parse_date.re"
/*
+----------------------------------------------------------------------+
@ -162,108 +162,13 @@ typedef struct _timelib_relunit {
/* The timezone table. */
static timelib_tz_lookup_table timelib_timezone_lookup[] = {
{ "a", 0, HOUR (- 1), NULL },
{ "adt", 1, HOUR ( 4), "America/Halifax" }, /* Atlantic Daylight */
{ "ahst", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska-Hawaii Standard */
{ "akdt", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska Daylight */
{ "akst", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska Standard */
{ "ast", 0, HOUR ( 4), "America/Halifax" }, /* Atlantic Standard */
{ "at", 0, HOUR ( 2), "Atlantic/Azores" }, /* Azores */
{ "b", 0, HOUR (- 2), NULL },
{ "bst", 1, HOUR ( 0), "Europe/London" }, /* British Summer */
{ "bt", 0, -HOUR ( 3), "Asia/Baghdad" }, /* Baghdad, USSR Zone 2 */
{ "c", 0, HOUR (- 3), NULL },
{ "cadt", 1, -HOUR (9.5), "Australia/Adelaide" }, /* Central Australian Daylight */
{ "cast", 0, -HOUR (9.5), "Australia/Adelaide" }, /* Central Australian Standard */
{ "cat", 0, HOUR ( 10), "America/Anchorage" }, /* Central Alaska */
{ "cct", 0, -HOUR ( 8), "Asia/Shanghai" }, /* China Coast, USSR Zone 7 */
{ "cdt", 1, HOUR ( 6), "America/Chicago" }, /* Central Daylight */
{ "cest", 1, -HOUR ( 1), "Europe/Berlin" }, /* Central European Summer */
{ "cet", 0, -HOUR ( 1), "Europe/Berlin" }, /* Central European */
{ "cst", 0, HOUR ( 6), "America/Chicago" }, /* Central Standard */
{ "d", 0, HOUR (- 4), NULL },
{ "e", 0, HOUR (- 5), NULL },
{ "eadt", 1, -HOUR ( 10), "Australia/Sydney" }, /* Eastern Australian Daylight */
{ "east", 0, -HOUR ( 10), "Australia/Sydney" }, /* Eastern Australian Standard */
{ "edt", 1, HOUR ( 5), "America/New_York" }, /* Eastern Daylight */
{ "eest", 1, HOUR ( 2), "Europe/Helsinki" }, /* Eastern European Summer */
{ "eet", 0, -HOUR ( 2), "Europe/Bucharest" }, /* Eastern Europe, USSR Zone 1 */
{ "est", 0, HOUR ( 5), "America/New_York" }, /* Eastern Standard */
{ "f", 0, HOUR (- 6), NULL },
{ "fst", 1, -HOUR ( 1), "Europe/Paris" }, /* French Summer */
{ "fwt", 0, -HOUR ( 1), "Europe/Paris" }, /* French Winter */
{ "g", 0, HOUR (- 7), NULL },
{ "gmt", 0, HOUR ( 0), "GMT" }, /* Greenwich Mean */
{ "gst", 0, -HOUR ( 10), "Pacific/Guam" }, /* Guam Standard, USSR Zone 9 */
{ "h", 0, HOUR (- 8), NULL },
{ "hdt", 1, HOUR ( 10), "Pacific/Honolulu" }, /* Hawaii Daylight */
{ "hst", 0, HOUR ( 10), "Pacific/Honolulu" }, /* Hawaii Standard */
{ "i", 0, HOUR (- 9), NULL },
{ "idle", 0, -HOUR ( 12), "NZ" }, /* International Date Line East */
{ "idlw", 0, HOUR ( 12), NULL }, /* International Date Line West */
{ "ist", 0, -HOUR (5.5), "Asia/Calcutta" }, /* Indian Standard */
{ "it", 0, -HOUR (3.5), "Asia/Tehran" }, /* Iran */
{ "jst", 0, -HOUR ( 9), "Asia/Tokyo" }, /* Japan Standard, USSR Zone 8 */
{ "jt", 0, -HOUR (7.5), NULL }, /* Java (3pm in Cronusland!) */
{ "k", 0, HOUR (-10), NULL },
{ "l", 0, HOUR (-11), NULL },
{ "m", 0, HOUR (-12), NULL },
{ "mdt", 1, HOUR ( 7), "America/Phoenix" }, /* Mountain Daylight */
{ "mest", 1, -HOUR ( 1), "MET" }, /* Middle European Summer */
{ "mesz", 1, -HOUR ( 1), "MET" }, /* Middle European Summer */
{ "met", 0, -HOUR ( 1), "MET" }, /* Middle European */
{ "mewt", 0, -HOUR ( 1), "MET" }, /* Middle European Winter */
{ "msd", 1, HOUR ( 3), "Europe/Moscow" }, /* Moscow Summer */
{ "msk", 0, HOUR ( 3), "Europe/Moscow" }, /* Moscow */
{ "mst", 0, HOUR ( 7), "America/Phoenix" }, /* Mountain Standard */
{ "n", 0, HOUR ( 1), NULL },
{ "ndt", 1, HOUR (3.5), "America/St_Johns" }, /* Newfoundland Daylight */
{ "nft", 0, HOUR (3.5), "America/St_Johns" }, /* Newfoundland */
{ "nst", 0, HOUR (3.5), "America/St_Johns" }, /* Newfoundland Standard */
{ "nt", 0, HOUR ( 11), NULL }, /* Nome */
{ "nzdt", 1, -HOUR ( 12), "NZ" }, /* New Zealand Daylight */
{ "nzst", 0, -HOUR ( 12), "NZ" }, /* New Zealand Standard */
{ "nzt", 0, -HOUR ( 12), "NZ" }, /* New Zealand */
{ "o", 0, HOUR ( 2), NULL },
{ "p", 0, HOUR ( 3), NULL },
{ "pdt", 1, HOUR ( 8), "America/Los_Angeles" }, /* Pacific Daylight */
{ "pst", 0, HOUR ( 8), "America/Los_Angeles" }, /* Pacific Standard */
{ "q", 0, HOUR ( 4), NULL },
{ "r", 0, HOUR ( 5), NULL },
{ "s", 0, HOUR ( 6), NULL },
{ "slst", 1, -HOUR ( 1), "Europe/Oslo" }, /* Skien Local Summer Time */
{ "slt", 0, -HOUR ( 1), "Europe/Oslo" }, /* Skien Local Time */
{ "sst", 1, -HOUR ( 1), "Europe/Stockholm" }, /* Swedish Summer */
{ "swt", 0, -HOUR ( 1), "Europe/Stockholm" }, /* Swedish Winter */
{ "t", 0, HOUR ( 7), NULL },
{ "u", 0, HOUR ( 8), NULL },
{ "ut", 0, HOUR ( 0), "UTC" }, /* Universal (Coordinated) */
{ "utc", 0, HOUR ( 0), "UTC" },
{ "v", 0, HOUR ( 9), NULL },
{ "w", 0, HOUR ( 10), NULL },
{ "wadt", 1, -HOUR ( 7), "Australia/Perth" }, /* West Australian Daylight */
{ "wast", 0, -HOUR ( 7), "Australia/Perth" }, /* West Australian Standard */
{ "wat", 0, HOUR ( 1), "Africa/Dakar" }, /* West Africa */
{ "wet", 0, HOUR ( 0), "Europe/London" }, /* Western European */
{ "x", 0, HOUR ( 11), NULL },
{ "y", 0, HOUR ( 12), NULL },
{ "ydt", 1, HOUR ( 9), "America/Anchorage" }, /* Yukon Daylight */
{ "yst", 0, HOUR ( 9), "America/Anchorage" }, /* Yukon Standard */
{ "z", 0, HOUR ( 0), NULL },
{ "zp4", 0, -HOUR ( 4), NULL }, /* USSR Zone 3 */
{ "zp5", 0, -HOUR ( 5), NULL }, /* USSR Zone 4 */
{ "zp6", 0, -HOUR ( 6), NULL }, /* USSR Zone 5 */
#if 0
/* For completeness. BST is also British Summer, and GST is
* also Guam Standard. */
{ "bst", 0, HOUR ( 3), NULL }, /* Brazil Standard */
{ "gst", 0, HOUR ( 3), NULL }, /* Greenland Standard */
#include "timezonemap.h"
{ NULL, 0, 0, NULL },
};
/* For completeness. NST is also Newfoundland Standard, and SST is
* also Swedish Summer. */
{ "nst", 0, -HOUR (6.5), NULL },/* North Sumatra */
{ "sst", 0, -HOUR (7), NULL }, /* South Sumatra, USSR Zone 6 */
#endif
static timelib_tz_lookup_table timelib_timezone_fallbackmap[] = {
#include "fallbackmap.h"
{ NULL, 0, 0, NULL },
};
static timelib_relunit const timelib_relunit_lookup[] = {
@ -652,24 +557,37 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, Scanner *s)
}
}
static timelib_tz_lookup_table* zone_search(const char *word, int left, int right)
static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, int isdst)
{
int mid, cmp;
if (left > right) {
return NULL; /* not found */
int first_found = 0;
timelib_tz_lookup_table *tp, *first_found_elem;
timelib_tz_lookup_table *fmp;
for (tp = timelib_timezone_lookup; tp->name; tp++) {
if (strcasecmp(word, tp->name) == 0) {
if (!first_found) {
first_found = 1;
first_found_elem = tp;
if (gmtoffset == -1) {
return tp;
}
}
if (tp->gmtoffset == gmtoffset) {
return tp;
}
}
}
mid = (left + right) / 2;
cmp = strcasecmp(word, timelib_timezone_lookup[mid].name);
if (cmp < 0) {
return zone_search(word, left, mid - 1);
} else if (cmp > 0) {
return zone_search(word, mid + 1, right);
} else { /* (cmp == 0) */
return (timelib_tz_lookup_table*)&timelib_timezone_lookup[mid];
if (first_found) {
return first_found_elem;
}
/* Still didn't find anything, let's find the zone solely based on
* offset/isdst then */
for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {
if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) {
return fmp;
}
}
return NULL;
}
static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found)
@ -686,9 +604,10 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found
word = calloc(1, end - begin + 1);
memcpy(word, begin, end - begin);
if ((tp = zone_search(word, 0, sizeof(timelib_timezone_lookup)/sizeof(*timelib_timezone_lookup)-1))) {
value = tp->value;
if ((tp = zone_search(word, -1, 0))) {
value = -tp->gmtoffset / 60;
*dst = tp->type;
value += tp->type * 60;
*found = 1;
} else {
*found = 0;
@ -773,7 +692,7 @@ static int scan(Scanner *s)
std:
s->tok = cursor;
s->len = 0;
#line 879 "resource/parse_date.re"
#line 798 "resource/parse_date.re"
{
@ -812,7 +731,7 @@ std:
0, 0, 0, 0, 0, 0, 0, 0,
};
#line 816 "<stdout>"
#line 735 "<stdout>"
{
YYCTYPE yych;
unsigned int yyaccept;
@ -897,7 +816,7 @@ yy2:
yy3:
YYDEBUG(3, *YYCURSOR);
#line 1361 "resource/parse_date.re"
#line 1280 "resource/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("tzcorrection | tz");
@ -907,7 +826,7 @@ yy3:
TIMELIB_DEINIT;
return TIMELIB_TIMEZONE;
}
#line 904 "<stdout>"
#line 823 "<stdout>"
yy4:
YYDEBUG(4, *YYCURSOR);
yych = *++YYCURSOR;
@ -993,13 +912,13 @@ yy6:
yy7:
YYDEBUG(7, *YYCURSOR);
#line 1427 "resource/parse_date.re"
#line 1346 "resource/parse_date.re"
{
/* printf("unexpected character: #%d, %c ", *s->tok, *s->tok); */
s->errors++;
goto std;
}
#line 987 "<stdout>"
#line 906 "<stdout>"
yy8:
YYDEBUG(8, *YYCURSOR);
yyaccept = 0;
@ -1922,11 +1841,11 @@ yy43:
yy44:
YYDEBUG(44, *YYCURSOR);
#line 1416 "resource/parse_date.re"
#line 1335 "resource/parse_date.re"
{
goto std;
}
#line 1835 "<stdout>"
#line 1754 "<stdout>"
yy45:
YYDEBUG(45, *YYCURSOR);
++YYCURSOR;
@ -1934,12 +1853,12 @@ yy45:
yy46:
YYDEBUG(46, *YYCURSOR);
#line 1421 "resource/parse_date.re"
#line 1340 "resource/parse_date.re"
{
s->pos = cursor; s->line++;
goto std;
}
#line 1844 "<stdout>"
#line 1763 "<stdout>"
yy47:
YYDEBUG(47, *YYCURSOR);
yych = *++YYCURSOR;
@ -2397,7 +2316,7 @@ yy84:
yy85:
YYDEBUG(85, *YYCURSOR);
#line 1400 "resource/parse_date.re"
#line 1319 "resource/parse_date.re"
{
timelib_ull i;
DEBUG_OUTPUT("relative");
@ -2412,7 +2331,7 @@ yy85:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 2234 "<stdout>"
#line 2153 "<stdout>"
yy86:
YYDEBUG(86, *YYCURSOR);
++YYCURSOR;
@ -3105,12 +3024,12 @@ yy150:
yy151:
YYDEBUG(151, *YYCURSOR);
#line 1355 "resource/parse_date.re"
#line 1274 "resource/parse_date.re"
{
DEBUG_OUTPUT("dayabbr");
goto std;
}
#line 2798 "<stdout>"
#line 2717 "<stdout>"
yy152:
YYDEBUG(152, *YYCURSOR);
yyaccept = 1;
@ -3149,7 +3068,7 @@ yy157:
yy158:
YYDEBUG(158, *YYCURSOR);
#line 1339 "resource/parse_date.re"
#line 1258 "resource/parse_date.re"
{
const timelib_relunit* relunit;
DEBUG_OUTPUT("dayfull");
@ -3164,7 +3083,7 @@ yy158:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 2838 "<stdout>"
#line 2757 "<stdout>"
yy159:
YYDEBUG(159, *YYCURSOR);
yyaccept = 1;
@ -3533,7 +3452,7 @@ yy189:
yy190:
YYDEBUG(190, *YYCURSOR);
#line 1323 "resource/parse_date.re"
#line 1242 "resource/parse_date.re"
{
timelib_sll i;
DEBUG_OUTPUT("relativetext");
@ -3548,7 +3467,7 @@ yy190:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 3156 "<stdout>"
#line 3075 "<stdout>"
yy191:
YYDEBUG(191, *YYCURSOR);
++YYCURSOR;
@ -9178,7 +9097,7 @@ yy508:
yy509:
YYDEBUG(509, *YYCURSOR);
#line 1145 "resource/parse_date.re"
#line 1064 "resource/parse_date.re"
{
DEBUG_OUTPUT("datetextual | datenoyear");
TIMELIB_INIT;
@ -9190,7 +9109,7 @@ yy509:
TIMELIB_DEINIT;
return TIMELIB_DATE_TEXT;
}
#line 8149 "<stdout>"
#line 8068 "<stdout>"
yy510:
YYDEBUG(510, *YYCURSOR);
yych = *++YYCURSOR;
@ -9350,7 +9269,7 @@ yy526:
yy527:
YYDEBUG(527, *YYCURSOR);
#line 1372 "resource/parse_date.re"
#line 1291 "resource/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz");
@ -9377,7 +9296,7 @@ yy527:
TIMELIB_DEINIT;
return TIMELIB_SHORTDATE_WITH_TIME;
}
#line 8300 "<stdout>"
#line 8219 "<stdout>"
yy528:
YYDEBUG(528, *YYCURSOR);
yyaccept = 7;
@ -9690,7 +9609,7 @@ yy561:
yy562:
YYDEBUG(562, *YYCURSOR);
#line 1119 "resource/parse_date.re"
#line 1038 "resource/parse_date.re"
{
DEBUG_OUTPUT("datenoday");
TIMELIB_INIT;
@ -9702,7 +9621,7 @@ yy562:
TIMELIB_DEINIT;
return TIMELIB_DATE_NO_DAY;
}
#line 8555 "<stdout>"
#line 8474 "<stdout>"
yy563:
YYDEBUG(563, *YYCURSOR);
yyaccept = 6;
@ -10002,7 +9921,7 @@ yy587:
yy588:
YYDEBUG(588, *YYCURSOR);
#line 1254 "resource/parse_date.re"
#line 1173 "resource/parse_date.re"
{
DEBUG_OUTPUT("pgtextshort");
TIMELIB_INIT;
@ -10014,7 +9933,7 @@ yy588:
TIMELIB_DEINIT;
return TIMELIB_PG_TEXT;
}
#line 8814 "<stdout>"
#line 8733 "<stdout>"
yy589:
YYDEBUG(589, *YYCURSOR);
yych = *++YYCURSOR;
@ -11518,7 +11437,7 @@ yy683:
yy684:
YYDEBUG(684, *YYCURSOR);
#line 1308 "resource/parse_date.re"
#line 1227 "resource/parse_date.re"
{
DEBUG_OUTPUT("ago");
TIMELIB_INIT;
@ -11532,7 +11451,7 @@ yy684:
TIMELIB_DEINIT;
return TIMELIB_AGO;
}
#line 10139 "<stdout>"
#line 10058 "<stdout>"
yy685:
YYDEBUG(685, *YYCURSOR);
yyaccept = 1;
@ -13466,7 +13385,7 @@ yy787:
yy788:
YYDEBUG(788, *YYCURSOR);
#line 1158 "resource/parse_date.re"
#line 1077 "resource/parse_date.re"
{
DEBUG_OUTPUT("datenoyearrev");
TIMELIB_INIT;
@ -13476,7 +13395,7 @@ yy788:
TIMELIB_DEINIT;
return TIMELIB_DATE_TEXT;
}
#line 11871 "<stdout>"
#line 11790 "<stdout>"
yy789:
YYDEBUG(789, *YYCURSOR);
yyaccept = 10;
@ -13569,7 +13488,7 @@ yy796:
yy797:
YYDEBUG(797, *YYCURSOR);
#line 966 "resource/parse_date.re"
#line 885 "resource/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("timeshort24 | timelong24 | iso8601long");
@ -13592,7 +13511,7 @@ yy797:
TIMELIB_DEINIT;
return TIMELIB_TIME24_WITH_ZONE;
}
#line 11969 "<stdout>"
#line 11888 "<stdout>"
yy798:
YYDEBUG(798, *YYCURSOR);
yyaccept = 11;
@ -13720,7 +13639,7 @@ yy811:
yy812:
YYDEBUG(812, *YYCURSOR);
#line 951 "resource/parse_date.re"
#line 870 "resource/parse_date.re"
{
DEBUG_OUTPUT("timeshort12 | timelong12");
TIMELIB_INIT;
@ -13734,7 +13653,7 @@ yy812:
TIMELIB_DEINIT;
return TIMELIB_TIME12;
}
#line 12081 "<stdout>"
#line 12000 "<stdout>"
yy813:
YYDEBUG(813, *YYCURSOR);
yych = *++YYCURSOR;
@ -13857,7 +13776,7 @@ yy824:
yy825:
YYDEBUG(825, *YYCURSOR);
#line 1093 "resource/parse_date.re"
#line 1012 "resource/parse_date.re"
{
DEBUG_OUTPUT("datefull");
TIMELIB_INIT;
@ -13869,7 +13788,7 @@ yy825:
TIMELIB_DEINIT;
return TIMELIB_DATE_FULL;
}
#line 12190 "<stdout>"
#line 12109 "<stdout>"
yy826:
YYDEBUG(826, *YYCURSOR);
yych = *++YYCURSOR;
@ -14488,7 +14407,7 @@ yy892:
yy893:
YYDEBUG(893, *YYCURSOR);
#line 1106 "resource/parse_date.re"
#line 1025 "resource/parse_date.re"
{
DEBUG_OUTPUT("pointed date");
TIMELIB_INIT;
@ -14500,7 +14419,7 @@ yy893:
TIMELIB_DEINIT;
return TIMELIB_DATE_FULL_POINTED;
}
#line 12685 "<stdout>"
#line 12604 "<stdout>"
yy894:
YYDEBUG(894, *YYCURSOR);
yych = *++YYCURSOR;
@ -15068,7 +14987,7 @@ yy938:
yy939:
YYDEBUG(939, *YYCURSOR);
#line 1080 "resource/parse_date.re"
#line 999 "resource/parse_date.re"
{
DEBUG_OUTPUT("gnudateshort");
TIMELIB_INIT;
@ -15080,7 +14999,7 @@ yy939:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 13173 "<stdout>"
#line 13092 "<stdout>"
yy940:
YYDEBUG(940, *YYCURSOR);
yych = *++YYCURSOR;
@ -15102,7 +15021,7 @@ yy942:
yy943:
YYDEBUG(943, *YYCURSOR);
#line 1053 "resource/parse_date.re"
#line 972 "resource/parse_date.re"
{
DEBUG_OUTPUT("americanshort | american");
TIMELIB_INIT;
@ -15116,7 +15035,7 @@ yy943:
TIMELIB_DEINIT;
return TIMELIB_AMERICAN;
}
#line 13201 "<stdout>"
#line 13120 "<stdout>"
yy944:
YYDEBUG(944, *YYCURSOR);
yyaccept = 12;
@ -15338,7 +15257,7 @@ yy975:
yy976:
YYDEBUG(976, *YYCURSOR);
#line 1280 "resource/parse_date.re"
#line 1199 "resource/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("clf");
@ -15356,7 +15275,7 @@ yy976:
TIMELIB_DEINIT;
return TIMELIB_CLF;
}
#line 13375 "<stdout>"
#line 13294 "<stdout>"
yy977:
YYDEBUG(977, *YYCURSOR);
yyaccept = 13;
@ -15665,7 +15584,7 @@ yy1015:
yy1016:
YYDEBUG(1016, *YYCURSOR);
#line 1267 "resource/parse_date.re"
#line 1186 "resource/parse_date.re"
{
DEBUG_OUTPUT("pgtextreverse");
TIMELIB_INIT;
@ -15677,7 +15596,7 @@ yy1016:
TIMELIB_DEINIT;
return TIMELIB_PG_TEXT;
}
#line 13615 "<stdout>"
#line 13534 "<stdout>"
yy1017:
YYDEBUG(1017, *YYCURSOR);
yych = *++YYCURSOR;
@ -15810,7 +15729,7 @@ yy1027:
yy1028:
YYDEBUG(1028, *YYCURSOR);
#line 1299 "resource/parse_date.re"
#line 1218 "resource/parse_date.re"
{
DEBUG_OUTPUT("year4");
TIMELIB_INIT;
@ -15818,7 +15737,7 @@ yy1028:
TIMELIB_DEINIT;
return TIMELIB_CLF;
}
#line 13731 "<stdout>"
#line 13650 "<stdout>"
yy1029:
YYDEBUG(1029, *YYCURSOR);
yych = *++YYCURSOR;
@ -15954,7 +15873,7 @@ yy1036:
yy1037:
YYDEBUG(1037, *YYCURSOR);
#line 1132 "resource/parse_date.re"
#line 1051 "resource/parse_date.re"
{
DEBUG_OUTPUT("datenodayrev");
TIMELIB_INIT;
@ -15966,7 +15885,7 @@ yy1037:
TIMELIB_DEINIT;
return TIMELIB_DATE_NO_DAY;
}
#line 13858 "<stdout>"
#line 13777 "<stdout>"
yy1038:
YYDEBUG(1038, *YYCURSOR);
yych = *++YYCURSOR;
@ -16175,7 +16094,7 @@ yy1056:
yy1057:
YYDEBUG(1057, *YYCURSOR);
#line 1235 "resource/parse_date.re"
#line 1154 "resource/parse_date.re"
{
timelib_sll w, d;
DEBUG_OUTPUT("isoweek");
@ -16193,7 +16112,7 @@ yy1057:
TIMELIB_DEINIT;
return TIMELIB_ISO_WEEK;
}
#line 14045 "<stdout>"
#line 13964 "<stdout>"
yy1058:
YYDEBUG(1058, *YYCURSOR);
++YYCURSOR;
@ -16201,7 +16120,7 @@ yy1058:
yy1059:
YYDEBUG(1059, *YYCURSOR);
#line 1216 "resource/parse_date.re"
#line 1135 "resource/parse_date.re"
{
timelib_sll w, d;
DEBUG_OUTPUT("isoweekday");
@ -16219,7 +16138,7 @@ yy1059:
TIMELIB_DEINIT;
return TIMELIB_ISO_WEEK;
}
#line 14067 "<stdout>"
#line 13986 "<stdout>"
yy1060:
YYDEBUG(1060, *YYCURSOR);
yych = *++YYCURSOR;
@ -16288,7 +16207,7 @@ yy1062:
yy1063:
YYDEBUG(1063, *YYCURSOR);
#line 1203 "resource/parse_date.re"
#line 1122 "resource/parse_date.re"
{
DEBUG_OUTPUT("pgydotd");
TIMELIB_INIT;
@ -16300,7 +16219,7 @@ yy1063:
TIMELIB_DEINIT;
return TIMELIB_PG_YEARDAY;
}
#line 14140 "<stdout>"
#line 14059 "<stdout>"
yy1064:
YYDEBUG(1064, *YYCURSOR);
yych = *++YYCURSOR;
@ -16415,7 +16334,7 @@ yy1069:
yy1070:
YYDEBUG(1070, *YYCURSOR);
#line 1169 "resource/parse_date.re"
#line 1088 "resource/parse_date.re"
{
DEBUG_OUTPUT("datenocolon");
TIMELIB_INIT;
@ -16426,7 +16345,7 @@ yy1070:
TIMELIB_DEINIT;
return TIMELIB_DATE_NOCOLON;
}
#line 14248 "<stdout>"
#line 14167 "<stdout>"
yy1071:
YYDEBUG(1071, *YYCURSOR);
yych = *++YYCURSOR;
@ -16524,7 +16443,7 @@ yy1080:
yy1081:
YYDEBUG(1081, *YYCURSOR);
#line 1181 "resource/parse_date.re"
#line 1100 "resource/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx");
@ -16545,7 +16464,7 @@ yy1081:
TIMELIB_DEINIT;
return TIMELIB_XMLRPC_SOAP;
}
#line 14345 "<stdout>"
#line 14264 "<stdout>"
yy1082:
YYDEBUG(1082, *YYCURSOR);
yych = *++YYCURSOR;
@ -17148,7 +17067,7 @@ yy1171:
yy1172:
YYDEBUG(1172, *YYCURSOR);
#line 1068 "resource/parse_date.re"
#line 987 "resource/parse_date.re"
{
DEBUG_OUTPUT("iso8601date | iso8601dateslash | dateslash");
TIMELIB_INIT;
@ -17159,7 +17078,7 @@ yy1172:
TIMELIB_DEINIT;
return TIMELIB_ISO_DATE;
}
#line 14777 "<stdout>"
#line 14696 "<stdout>"
yy1173:
YYDEBUG(1173, *YYCURSOR);
yych = *++YYCURSOR;
@ -17932,7 +17851,7 @@ yy1262:
yy1263:
YYDEBUG(1263, *YYCURSOR);
#line 990 "resource/parse_date.re"
#line 909 "resource/parse_date.re"
{
DEBUG_OUTPUT("gnunocolon");
TIMELIB_INIT;
@ -17953,7 +17872,7 @@ yy1263:
TIMELIB_DEINIT;
return TIMELIB_GNU_NOCOLON;
}
#line 15387 "<stdout>"
#line 15306 "<stdout>"
yy1264:
YYDEBUG(1264, *YYCURSOR);
yych = *++YYCURSOR;
@ -18050,7 +17969,7 @@ yy1270:
yy1271:
YYDEBUG(1271, *YYCURSOR);
#line 1035 "resource/parse_date.re"
#line 954 "resource/parse_date.re"
{
int tz_not_found;
DEBUG_OUTPUT("iso8601nocolon");
@ -18067,7 +17986,7 @@ yy1271:
TIMELIB_DEINIT;
return TIMELIB_ISO_NOCOLON;
}
#line 15485 "<stdout>"
#line 15404 "<stdout>"
yy1272:
YYDEBUG(1272, *YYCURSOR);
yyaccept = 21;
@ -18364,7 +18283,7 @@ yy1295:
yy1296:
YYDEBUG(1296, *YYCURSOR);
#line 927 "resource/parse_date.re"
#line 846 "resource/parse_date.re"
{
timelib_ull i;
@ -18387,7 +18306,7 @@ yy1296:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 15749 "<stdout>"
#line 15668 "<stdout>"
yy1297:
YYDEBUG(1297, *YYCURSOR);
yych = *++YYCURSOR;
@ -18458,7 +18377,7 @@ yy1304:
yy1305:
YYDEBUG(1305, *YYCURSOR);
#line 915 "resource/parse_date.re"
#line 834 "resource/parse_date.re"
{
DEBUG_OUTPUT("tomorrow");
TIMELIB_INIT;
@ -18469,7 +18388,7 @@ yy1305:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 15813 "<stdout>"
#line 15732 "<stdout>"
yy1306:
YYDEBUG(1306, *YYCURSOR);
yych = *++YYCURSOR;
@ -18482,7 +18401,7 @@ yy1307:
yy1308:
YYDEBUG(1308, *YYCURSOR);
#line 905 "resource/parse_date.re"
#line 824 "resource/parse_date.re"
{
DEBUG_OUTPUT("today");
TIMELIB_INIT;
@ -18491,7 +18410,7 @@ yy1308:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 15829 "<stdout>"
#line 15748 "<stdout>"
yy1309:
YYDEBUG(1309, *YYCURSOR);
yych = *++YYCURSOR;
@ -18525,7 +18444,7 @@ yy1310:
yy1311:
YYDEBUG(1311, *YYCURSOR);
#line 896 "resource/parse_date.re"
#line 815 "resource/parse_date.re"
{
DEBUG_OUTPUT("now");
TIMELIB_INIT;
@ -18533,7 +18452,7 @@ yy1311:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 15865 "<stdout>"
#line 15784 "<stdout>"
yy1312:
YYDEBUG(1312, *YYCURSOR);
yych = *++YYCURSOR;
@ -18591,7 +18510,7 @@ yy1319:
yy1320:
YYDEBUG(1320, *YYCURSOR);
#line 884 "resource/parse_date.re"
#line 803 "resource/parse_date.re"
{
DEBUG_OUTPUT("yesterday");
TIMELIB_INIT;
@ -18602,10 +18521,10 @@ yy1320:
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
#line 15916 "<stdout>"
#line 15835 "<stdout>"
}
}
#line 1432 "resource/parse_date.re"
#line 1351 "resource/parse_date.re"
}
@ -18682,11 +18601,11 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
*/
}
char *timelib_timezone_id_from_abbr(const char *abbr)
char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst)
{
timelib_tz_lookup_table *tp;
tp = zone_search(abbr, 0, sizeof(timelib_timezone_lookup) / sizeof(*timelib_timezone_lookup) - 1);
tp = zone_search(abbr, gmtoffset, isdst);
if (tp) {
return (tp->full_tz_name);
} else {

View File

@ -160,108 +160,13 @@ typedef struct _timelib_relunit {
/* The timezone table. */
static timelib_tz_lookup_table timelib_timezone_lookup[] = {
{ "a", 0, HOUR (- 1), NULL },
{ "adt", 1, HOUR ( 4), "America/Halifax" }, /* Atlantic Daylight */
{ "ahst", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska-Hawaii Standard */
{ "akdt", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska Daylight */
{ "akst", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska Standard */
{ "ast", 0, HOUR ( 4), "America/Halifax" }, /* Atlantic Standard */
{ "at", 0, HOUR ( 2), "Atlantic/Azores" }, /* Azores */
{ "b", 0, HOUR (- 2), NULL },
{ "bst", 1, HOUR ( 0), "Europe/London" }, /* British Summer */
{ "bt", 0, -HOUR ( 3), "Asia/Baghdad" }, /* Baghdad, USSR Zone 2 */
{ "c", 0, HOUR (- 3), NULL },
{ "cadt", 1, -HOUR (9.5), "Australia/Adelaide" }, /* Central Australian Daylight */
{ "cast", 0, -HOUR (9.5), "Australia/Adelaide" }, /* Central Australian Standard */
{ "cat", 0, HOUR ( 10), "America/Anchorage" }, /* Central Alaska */
{ "cct", 0, -HOUR ( 8), "Asia/Shanghai" }, /* China Coast, USSR Zone 7 */
{ "cdt", 1, HOUR ( 6), "America/Chicago" }, /* Central Daylight */
{ "cest", 1, -HOUR ( 1), "Europe/Berlin" }, /* Central European Summer */
{ "cet", 0, -HOUR ( 1), "Europe/Berlin" }, /* Central European */
{ "cst", 0, HOUR ( 6), "America/Chicago" }, /* Central Standard */
{ "d", 0, HOUR (- 4), NULL },
{ "e", 0, HOUR (- 5), NULL },
{ "eadt", 1, -HOUR ( 10), "Australia/Sydney" }, /* Eastern Australian Daylight */
{ "east", 0, -HOUR ( 10), "Australia/Sydney" }, /* Eastern Australian Standard */
{ "edt", 1, HOUR ( 5), "America/New_York" }, /* Eastern Daylight */
{ "eest", 1, HOUR ( 2), "Europe/Helsinki" }, /* Eastern European Summer */
{ "eet", 0, -HOUR ( 2), "Europe/Bucharest" }, /* Eastern Europe, USSR Zone 1 */
{ "est", 0, HOUR ( 5), "America/New_York" }, /* Eastern Standard */
{ "f", 0, HOUR (- 6), NULL },
{ "fst", 1, -HOUR ( 1), "Europe/Paris" }, /* French Summer */
{ "fwt", 0, -HOUR ( 1), "Europe/Paris" }, /* French Winter */
{ "g", 0, HOUR (- 7), NULL },
{ "gmt", 0, HOUR ( 0), "GMT" }, /* Greenwich Mean */
{ "gst", 0, -HOUR ( 10), "Pacific/Guam" }, /* Guam Standard, USSR Zone 9 */
{ "h", 0, HOUR (- 8), NULL },
{ "hdt", 1, HOUR ( 10), "Pacific/Honolulu" }, /* Hawaii Daylight */
{ "hst", 0, HOUR ( 10), "Pacific/Honolulu" }, /* Hawaii Standard */
{ "i", 0, HOUR (- 9), NULL },
{ "idle", 0, -HOUR ( 12), "NZ" }, /* International Date Line East */
{ "idlw", 0, HOUR ( 12), NULL }, /* International Date Line West */
{ "ist", 0, -HOUR (5.5), "Asia/Calcutta" }, /* Indian Standard */
{ "it", 0, -HOUR (3.5), "Asia/Tehran" }, /* Iran */
{ "jst", 0, -HOUR ( 9), "Asia/Tokyo" }, /* Japan Standard, USSR Zone 8 */
{ "jt", 0, -HOUR (7.5), NULL }, /* Java (3pm in Cronusland!) */
{ "k", 0, HOUR (-10), NULL },
{ "l", 0, HOUR (-11), NULL },
{ "m", 0, HOUR (-12), NULL },
{ "mdt", 1, HOUR ( 7), "America/Phoenix" }, /* Mountain Daylight */
{ "mest", 1, -HOUR ( 1), "MET" }, /* Middle European Summer */
{ "mesz", 1, -HOUR ( 1), "MET" }, /* Middle European Summer */
{ "met", 0, -HOUR ( 1), "MET" }, /* Middle European */
{ "mewt", 0, -HOUR ( 1), "MET" }, /* Middle European Winter */
{ "msd", 1, HOUR ( 3), "Europe/Moscow" }, /* Moscow Summer */
{ "msk", 0, HOUR ( 3), "Europe/Moscow" }, /* Moscow */
{ "mst", 0, HOUR ( 7), "America/Phoenix" }, /* Mountain Standard */
{ "n", 0, HOUR ( 1), NULL },
{ "ndt", 1, HOUR (3.5), "America/St_Johns" }, /* Newfoundland Daylight */
{ "nft", 0, HOUR (3.5), "America/St_Johns" }, /* Newfoundland */
{ "nst", 0, HOUR (3.5), "America/St_Johns" }, /* Newfoundland Standard */
{ "nt", 0, HOUR ( 11), NULL }, /* Nome */
{ "nzdt", 1, -HOUR ( 12), "NZ" }, /* New Zealand Daylight */
{ "nzst", 0, -HOUR ( 12), "NZ" }, /* New Zealand Standard */
{ "nzt", 0, -HOUR ( 12), "NZ" }, /* New Zealand */
{ "o", 0, HOUR ( 2), NULL },
{ "p", 0, HOUR ( 3), NULL },
{ "pdt", 1, HOUR ( 8), "America/Los_Angeles" }, /* Pacific Daylight */
{ "pst", 0, HOUR ( 8), "America/Los_Angeles" }, /* Pacific Standard */
{ "q", 0, HOUR ( 4), NULL },
{ "r", 0, HOUR ( 5), NULL },
{ "s", 0, HOUR ( 6), NULL },
{ "slst", 1, -HOUR ( 1), "Europe/Oslo" }, /* Skien Local Summer Time */
{ "slt", 0, -HOUR ( 1), "Europe/Oslo" }, /* Skien Local Time */
{ "sst", 1, -HOUR ( 1), "Europe/Stockholm" }, /* Swedish Summer */
{ "swt", 0, -HOUR ( 1), "Europe/Stockholm" }, /* Swedish Winter */
{ "t", 0, HOUR ( 7), NULL },
{ "u", 0, HOUR ( 8), NULL },
{ "ut", 0, HOUR ( 0), "UTC" }, /* Universal (Coordinated) */
{ "utc", 0, HOUR ( 0), "UTC" },
{ "v", 0, HOUR ( 9), NULL },
{ "w", 0, HOUR ( 10), NULL },
{ "wadt", 1, -HOUR ( 7), "Australia/Perth" }, /* West Australian Daylight */
{ "wast", 0, -HOUR ( 7), "Australia/Perth" }, /* West Australian Standard */
{ "wat", 0, HOUR ( 1), "Africa/Dakar" }, /* West Africa */
{ "wet", 0, HOUR ( 0), "Europe/London" }, /* Western European */
{ "x", 0, HOUR ( 11), NULL },
{ "y", 0, HOUR ( 12), NULL },
{ "ydt", 1, HOUR ( 9), "America/Anchorage" }, /* Yukon Daylight */
{ "yst", 0, HOUR ( 9), "America/Anchorage" }, /* Yukon Standard */
{ "z", 0, HOUR ( 0), NULL },
{ "zp4", 0, -HOUR ( 4), NULL }, /* USSR Zone 3 */
{ "zp5", 0, -HOUR ( 5), NULL }, /* USSR Zone 4 */
{ "zp6", 0, -HOUR ( 6), NULL }, /* USSR Zone 5 */
#if 0
/* For completeness. BST is also British Summer, and GST is
* also Guam Standard. */
{ "bst", 0, HOUR ( 3), NULL }, /* Brazil Standard */
{ "gst", 0, HOUR ( 3), NULL }, /* Greenland Standard */
#include "timezonemap.h"
{ NULL, 0, 0, NULL },
};
/* For completeness. NST is also Newfoundland Standard, and SST is
* also Swedish Summer. */
{ "nst", 0, -HOUR (6.5), NULL },/* North Sumatra */
{ "sst", 0, -HOUR (7), NULL }, /* South Sumatra, USSR Zone 6 */
#endif
static timelib_tz_lookup_table timelib_timezone_fallbackmap[] = {
#include "fallbackmap.h"
{ NULL, 0, 0, NULL },
};
static timelib_relunit const timelib_relunit_lookup[] = {
@ -650,24 +555,37 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, Scanner *s)
}
}
static timelib_tz_lookup_table* zone_search(const char *word, int left, int right)
static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, int isdst)
{
int mid, cmp;
if (left > right) {
return NULL; /* not found */
int first_found = 0;
timelib_tz_lookup_table *tp, *first_found_elem;
timelib_tz_lookup_table *fmp;
for (tp = timelib_timezone_lookup; tp->name; tp++) {
if (strcasecmp(word, tp->name) == 0) {
if (!first_found) {
first_found = 1;
first_found_elem = tp;
if (gmtoffset == -1) {
return tp;
}
}
if (tp->gmtoffset == gmtoffset) {
return tp;
}
}
}
mid = (left + right) / 2;
cmp = strcasecmp(word, timelib_timezone_lookup[mid].name);
if (cmp < 0) {
return zone_search(word, left, mid - 1);
} else if (cmp > 0) {
return zone_search(word, mid + 1, right);
} else { /* (cmp == 0) */
return (timelib_tz_lookup_table*)&timelib_timezone_lookup[mid];
if (first_found) {
return first_found_elem;
}
/* Still didn't find anything, let's find the zone solely based on
* offset/isdst then */
for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {
if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) {
return fmp;
}
}
return NULL;
}
static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found)
@ -684,9 +602,10 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found
word = calloc(1, end - begin + 1);
memcpy(word, begin, end - begin);
if ((tp = zone_search(word, 0, sizeof(timelib_timezone_lookup)/sizeof(*timelib_timezone_lookup)-1))) {
value = tp->value;
if ((tp = zone_search(word, -1, 0))) {
value = -tp->gmtoffset / 60;
*dst = tp->type;
value += tp->type * 60;
*found = 1;
} else {
*found = 0;
@ -1504,11 +1423,11 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
*/
}
char *timelib_timezone_id_from_abbr(const char *abbr)
char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst)
{
timelib_tz_lookup_table *tp;
tp = zone_search(abbr, 0, sizeof(timelib_timezone_lookup) / sizeof(*timelib_timezone_lookup) - 1);
tp = zone_search(abbr, gmtoffset, isdst);
if (tp) {
return (tp->full_tz_name);
} else {

View File

@ -160,108 +160,13 @@ typedef struct _timelib_relunit {
/* The timezone table. */
static timelib_tz_lookup_table timelib_timezone_lookup[] = {
{ "a", 0, HOUR (- 1), NULL },
{ "adt", 1, HOUR ( 4), "America/Halifax" }, /* Atlantic Daylight */
{ "ahst", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska-Hawaii Standard */
{ "akdt", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska Daylight */
{ "akst", 0, HOUR ( 10), "America/Anchorage" }, /* Alaska Standard */
{ "ast", 0, HOUR ( 4), "America/Halifax" }, /* Atlantic Standard */
{ "at", 0, HOUR ( 2), "Atlantic/Azores" }, /* Azores */
{ "b", 0, HOUR (- 2), NULL },
{ "bst", 1, HOUR ( 0), "Europe/London" }, /* British Summer */
{ "bt", 0, -HOUR ( 3), "Asia/Baghdad" }, /* Baghdad, USSR Zone 2 */
{ "c", 0, HOUR (- 3), NULL },
{ "cadt", 1, -HOUR (9.5), "Australia/Adelaide" }, /* Central Australian Daylight */
{ "cast", 0, -HOUR (9.5), "Australia/Adelaide" }, /* Central Australian Standard */
{ "cat", 0, HOUR ( 10), "America/Anchorage" }, /* Central Alaska */
{ "cct", 0, -HOUR ( 8), "Asia/Shanghai" }, /* China Coast, USSR Zone 7 */
{ "cdt", 1, HOUR ( 6), "America/Chicago" }, /* Central Daylight */
{ "cest", 1, -HOUR ( 1), "Europe/Berlin" }, /* Central European Summer */
{ "cet", 0, -HOUR ( 1), "Europe/Berlin" }, /* Central European */
{ "cst", 0, HOUR ( 6), "America/Chicago" }, /* Central Standard */
{ "d", 0, HOUR (- 4), NULL },
{ "e", 0, HOUR (- 5), NULL },
{ "eadt", 1, -HOUR ( 10), "Australia/Sydney" }, /* Eastern Australian Daylight */
{ "east", 0, -HOUR ( 10), "Australia/Sydney" }, /* Eastern Australian Standard */
{ "edt", 1, HOUR ( 5), "America/New_York" }, /* Eastern Daylight */
{ "eest", 1, HOUR ( 2), "Europe/Helsinki" }, /* Eastern European Summer */
{ "eet", 0, -HOUR ( 2), "Europe/Bucharest" }, /* Eastern Europe, USSR Zone 1 */
{ "est", 0, HOUR ( 5), "America/New_York" }, /* Eastern Standard */
{ "f", 0, HOUR (- 6), NULL },
{ "fst", 1, -HOUR ( 1), "Europe/Paris" }, /* French Summer */
{ "fwt", 0, -HOUR ( 1), "Europe/Paris" }, /* French Winter */
{ "g", 0, HOUR (- 7), NULL },
{ "gmt", 0, HOUR ( 0), "GMT" }, /* Greenwich Mean */
{ "gst", 0, -HOUR ( 10), "Pacific/Guam" }, /* Guam Standard, USSR Zone 9 */
{ "h", 0, HOUR (- 8), NULL },
{ "hdt", 1, HOUR ( 10), "Pacific/Honolulu" }, /* Hawaii Daylight */
{ "hst", 0, HOUR ( 10), "Pacific/Honolulu" }, /* Hawaii Standard */
{ "i", 0, HOUR (- 9), NULL },
{ "idle", 0, -HOUR ( 12), "NZ" }, /* International Date Line East */
{ "idlw", 0, HOUR ( 12), NULL }, /* International Date Line West */
{ "ist", 0, -HOUR (5.5), "Asia/Calcutta" }, /* Indian Standard */
{ "it", 0, -HOUR (3.5), "Asia/Tehran" }, /* Iran */
{ "jst", 0, -HOUR ( 9), "Asia/Tokyo" }, /* Japan Standard, USSR Zone 8 */
{ "jt", 0, -HOUR (7.5), NULL }, /* Java (3pm in Cronusland!) */
{ "k", 0, HOUR (-10), NULL },
{ "l", 0, HOUR (-11), NULL },
{ "m", 0, HOUR (-12), NULL },
{ "mdt", 1, HOUR ( 7), "America/Phoenix" }, /* Mountain Daylight */
{ "mest", 1, -HOUR ( 1), "MET" }, /* Middle European Summer */
{ "mesz", 1, -HOUR ( 1), "MET" }, /* Middle European Summer */
{ "met", 0, -HOUR ( 1), "MET" }, /* Middle European */
{ "mewt", 0, -HOUR ( 1), "MET" }, /* Middle European Winter */
{ "msd", 1, HOUR ( 3), "Europe/Moscow" }, /* Moscow Summer */
{ "msk", 0, HOUR ( 3), "Europe/Moscow" }, /* Moscow */
{ "mst", 0, HOUR ( 7), "America/Phoenix" }, /* Mountain Standard */
{ "n", 0, HOUR ( 1), NULL },
{ "ndt", 1, HOUR (3.5), "America/St_Johns" }, /* Newfoundland Daylight */
{ "nft", 0, HOUR (3.5), "America/St_Johns" }, /* Newfoundland */
{ "nst", 0, HOUR (3.5), "America/St_Johns" }, /* Newfoundland Standard */
{ "nt", 0, HOUR ( 11), NULL }, /* Nome */
{ "nzdt", 1, -HOUR ( 12), "NZ" }, /* New Zealand Daylight */
{ "nzst", 0, -HOUR ( 12), "NZ" }, /* New Zealand Standard */
{ "nzt", 0, -HOUR ( 12), "NZ" }, /* New Zealand */
{ "o", 0, HOUR ( 2), NULL },
{ "p", 0, HOUR ( 3), NULL },
{ "pdt", 1, HOUR ( 8), "America/Los_Angeles" }, /* Pacific Daylight */
{ "pst", 0, HOUR ( 8), "America/Los_Angeles" }, /* Pacific Standard */
{ "q", 0, HOUR ( 4), NULL },
{ "r", 0, HOUR ( 5), NULL },
{ "s", 0, HOUR ( 6), NULL },
{ "slst", 1, -HOUR ( 1), "Europe/Oslo" }, /* Skien Local Summer Time */
{ "slt", 0, -HOUR ( 1), "Europe/Oslo" }, /* Skien Local Time */
{ "sst", 1, -HOUR ( 1), "Europe/Stockholm" }, /* Swedish Summer */
{ "swt", 0, -HOUR ( 1), "Europe/Stockholm" }, /* Swedish Winter */
{ "t", 0, HOUR ( 7), NULL },
{ "u", 0, HOUR ( 8), NULL },
{ "ut", 0, HOUR ( 0), "UTC" }, /* Universal (Coordinated) */
{ "utc", 0, HOUR ( 0), "UTC" },
{ "v", 0, HOUR ( 9), NULL },
{ "w", 0, HOUR ( 10), NULL },
{ "wadt", 1, -HOUR ( 7), "Australia/Perth" }, /* West Australian Daylight */
{ "wast", 0, -HOUR ( 7), "Australia/Perth" }, /* West Australian Standard */
{ "wat", 0, HOUR ( 1), "Africa/Dakar" }, /* West Africa */
{ "wet", 0, HOUR ( 0), "Europe/London" }, /* Western European */
{ "x", 0, HOUR ( 11), NULL },
{ "y", 0, HOUR ( 12), NULL },
{ "ydt", 1, HOUR ( 9), "America/Anchorage" }, /* Yukon Daylight */
{ "yst", 0, HOUR ( 9), "America/Anchorage" }, /* Yukon Standard */
{ "z", 0, HOUR ( 0), NULL },
{ "zp4", 0, -HOUR ( 4), NULL }, /* USSR Zone 3 */
{ "zp5", 0, -HOUR ( 5), NULL }, /* USSR Zone 4 */
{ "zp6", 0, -HOUR ( 6), NULL }, /* USSR Zone 5 */
#if 0
/* For completeness. BST is also British Summer, and GST is
* also Guam Standard. */
{ "bst", 0, HOUR ( 3), NULL }, /* Brazil Standard */
{ "gst", 0, HOUR ( 3), NULL }, /* Greenland Standard */
#include "timezonemap.h"
{ NULL, 0, 0, NULL },
};
/* For completeness. NST is also Newfoundland Standard, and SST is
* also Swedish Summer. */
{ "nst", 0, -HOUR (6.5), NULL },/* North Sumatra */
{ "sst", 0, -HOUR (7), NULL }, /* South Sumatra, USSR Zone 6 */
#endif
static timelib_tz_lookup_table timelib_timezone_fallbackmap[] = {
#include "fallbackmap.h"
{ NULL, 0, 0, NULL },
};
static timelib_relunit const timelib_relunit_lookup[] = {
@ -650,24 +555,37 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, Scanner *s)
}
}
static timelib_tz_lookup_table* zone_search(const char *word, int left, int right)
static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, int isdst)
{
int mid, cmp;
if (left > right) {
return NULL; /* not found */
int first_found = 0;
timelib_tz_lookup_table *tp, *first_found_elem;
timelib_tz_lookup_table *fmp;
for (tp = timelib_timezone_lookup; tp->name; tp++) {
if (strcasecmp(word, tp->name) == 0) {
if (!first_found) {
first_found = 1;
first_found_elem = tp;
if (gmtoffset == -1) {
return tp;
}
}
if (tp->gmtoffset == gmtoffset) {
return tp;
}
}
}
mid = (left + right) / 2;
cmp = strcasecmp(word, timelib_timezone_lookup[mid].name);
if (cmp < 0) {
return zone_search(word, left, mid - 1);
} else if (cmp > 0) {
return zone_search(word, mid + 1, right);
} else { /* (cmp == 0) */
return (timelib_tz_lookup_table*)&timelib_timezone_lookup[mid];
if (first_found) {
return first_found_elem;
}
/* Still didn't find anything, let's find the zone solely based on
* offset/isdst then */
for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {
if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) {
return fmp;
}
}
return NULL;
}
static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found)
@ -684,9 +602,10 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found
word = calloc(1, end - begin + 1);
memcpy(word, begin, end - begin);
if ((tp = zone_search(word, 0, sizeof(timelib_timezone_lookup)/sizeof(*timelib_timezone_lookup)-1))) {
value = tp->value;
if ((tp = zone_search(word, -1, 0))) {
value = -tp->gmtoffset / 60;
*dst = tp->type;
value += tp->type * 60;
*found = 1;
} else {
*found = 0;
@ -1504,11 +1423,11 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
*/
}
char *timelib_timezone_id_from_abbr(const char *abbr)
char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst)
{
timelib_tz_lookup_table *tp;
tp = zone_search(abbr, 0, sizeof(timelib_timezone_lookup) / sizeof(*timelib_timezone_lookup) - 1);
tp = zone_search(abbr, gmtoffset, isdst);
if (tp) {
return (tp->full_tz_name);
} else {

View File

@ -49,7 +49,7 @@ void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, time
/* From parse_date.re */
timelib_time *timelib_strtotime(char *s, int *errors);
void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
char *timelib_timezone_id_from_abbr(const char *abbr);
char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst);
timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void);
/* From tm2unixtime.c */

View File

@ -149,7 +149,7 @@ typedef struct timelib_time {
typedef struct _timelib_tz_lookup_table {
char *name;
int type;
int value;
int gmtoffset;
char *full_tz_name;
} timelib_tz_lookup_table;

1627
ext/date/lib/timezonemap.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -267,7 +267,7 @@ static char* guess_timezone(TSRMLS_D)
}
/* Check environment variable */
env = getenv("TZ");
if (env && *env) {
if (env && *env && strlen(env)) {
return env;
}
/* Check config setting for default timezone */
@ -283,12 +283,12 @@ static char* guess_timezone(TSRMLS_D)
the_time = time(NULL);
ta = php_localtime_r(&the_time, &tmbuf);
tzid = timelib_timezone_id_from_abbr(ta->tm_zone);
tzid = timelib_timezone_id_from_abbr(ta->tm_zone, ta->tm_gmtoff, ta->tm_isdst);
if (! tzid) {
tzid = "UTC";
}
php_error_docref(NULL TSRMLS_CC, E_STRICT, "It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use '%s' for '%s' instead.", tzid, ta->tm_zone);
php_error_docref(NULL TSRMLS_CC, E_STRICT, "It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use '%s' for '%s/%.1f/%s' instead.", tzid, ta->tm_zone, (float) (ta->tm_gmtoff / 3600), ta->tm_isdst ? "DST" : "no DST");
return tzid;
}
#endif
@ -1367,7 +1367,7 @@ PHP_FUNCTION(timezone_open)
if (!tzi) {
char *tzid;
tzid = timelib_timezone_id_from_abbr(tz);
tzid = timelib_timezone_id_from_abbr(tz, -1, 0);
if (tzid) {
tzi = timelib_parse_tzfile(tzid);
}
@ -1464,12 +1464,12 @@ PHP_FUNCTION(timezone_abbreviations_list)
table = timelib_timezone_abbreviations_list();
array_init(return_value);
entry = table;
#warning NEED TO MAKE SURE ABBRS ARE NOT UNIQUEIZED HERE
do {
MAKE_STD_ZVAL(element);
array_init(element);
add_assoc_bool(element, "dst", entry->type);
add_assoc_long(element, "offset", - entry->value * 60);
add_assoc_long(element, "offset", entry->gmtoffset);
if (entry->full_tz_name) {
add_assoc_string(element, "timezone_id", entry->full_tz_name, 1);
} else {

View File

@ -6,7 +6,11 @@ date.timezone=
<?php
putenv('TZ=');
echo date_default_timezone_get(), "\n";
echo date('e'), "\n";
?>
--EXPECTF--
Strict Standards: date_default_timezone_get(): It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use 'UTC' for 'UTC' instead. in %sdate_default_timezone_get-1.php on line 3
UTC
Strict Standards: date_default_timezone_get(): It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use 'Europe/London' for 'UTC/0.0/no DST' instead. in %sdate_default_timezone_get-1.php on line 3
Europe/London
Strict Standards: date(): It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use 'Europe/London' for 'UTC/0.0/no DST' instead. in %sdate_default_timezone_get-1.php on line 4
Europe/London

View File

@ -5,16 +5,24 @@ date.timezone=
--FILE--
<?php
putenv("TZ=");
$date1 = strtotime("2005-07-12 08:00:00");
date_default_timezone_set("America/Indiana/Knox");
$date1 = strtotime("2005-01-12 08:00:00");
$date2 = strtotime("2005-07-12 08:00:00");
date_default_timezone_set("America/Indiana/Knox");
$date3 = strtotime("2005-01-12 08:00:00");
$date4 = strtotime("2005-07-12 08:00:00");
echo date_default_timezone_get(), "\n";
echo date(DATE_ISO8601, $date1), "\n";
echo date(DATE_ISO8601, $date2), "\n";
echo date(DATE_ISO8601, $date3), "\n";
echo date(DATE_ISO8601, $date4), "\n";
?>
--EXPECTF--
Strict Standards: strtotime(): It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use 'UTC' for 'UTC' instead. in %sdate_default_timezone_set-1.php on line 3
Strict Standards: strtotime(): It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use 'Europe/London' for 'UTC/0.0/no DST' instead. in %sdate_default_timezone_set-1.php on line 3
Strict Standards: strtotime(): It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We use 'Europe/London' for 'UTC/0.0/no DST' instead. in %sdate_default_timezone_set-1.php on line 4
America/Indiana/Knox
2005-07-12T03:00:00-0500
2005-01-12T03:00:00-0500
2005-07-12T02:00:00-0500
2005-01-12T08:00:00-0500
2005-07-12T08:00:00-0500