From 0ae51b159ea33d25b73b7a3a92e357e39f65e4d4 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 30 Jul 2008 17:48:21 +0000 Subject: [PATCH] - Fixed a bug with the YYYY-MM format not resetting the day correctly. - Fixed a bug in the DateTime->modify() methods, it would not use the advanced relative time strings. - Fixed return values of all the modifying methods, they now properly return the object itself. --- ext/date/lib/parse_date.c | 89 +++++++++++++++--------------- ext/date/lib/parse_date.re | 1 + ext/date/php_date.c | 21 ++++--- ext/date/tests/012.phpt | 27 ++++++++- ext/date/tests/013.phpt | 18 +++++- ext/date/tests/date_parse_001.phpt | 16 ++---- 6 files changed, 105 insertions(+), 67 deletions(-) diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index f155cbb086..b0927044c9 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Wed Jul 23 21:49:54 2008 */ +/* Generated by re2c 0.13.5 on Wed Jul 30 19:25:10 2008 */ #line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ @@ -982,7 +982,7 @@ yy2: } yy3: YYDEBUG(3, *YYCURSOR); -#line 1605 "ext/date/lib/parse_date.re" +#line 1606 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("tzcorrection | tz"); @@ -1306,7 +1306,7 @@ yy11: if (yych <= '9') goto yy1343; yy12: YYDEBUG(12, *YYCURSOR); -#line 1700 "ext/date/lib/parse_date.re" +#line 1701 "ext/date/lib/parse_date.re" { add_error(s, "Unexpected character"); goto std; @@ -2334,7 +2334,7 @@ yy46: if (yych <= '9') goto yy52; yy47: YYDEBUG(47, *YYCURSOR); -#line 1689 "ext/date/lib/parse_date.re" +#line 1690 "ext/date/lib/parse_date.re" { goto std; } @@ -2347,7 +2347,7 @@ yy49: YYDEBUG(49, *YYCURSOR); ++YYCURSOR; YYDEBUG(50, *YYCURSOR); -#line 1694 "ext/date/lib/parse_date.re" +#line 1695 "ext/date/lib/parse_date.re" { s->pos = cursor; s->line++; goto std; @@ -2739,7 +2739,7 @@ yy69: if (yych == 's') goto yy71; yy70: YYDEBUG(70, *YYCURSOR); -#line 1673 "ext/date/lib/parse_date.re" +#line 1674 "ext/date/lib/parse_date.re" { timelib_ull i; DEBUG_OUTPUT("relative"); @@ -3507,7 +3507,7 @@ yy164: } yy165: YYDEBUG(165, *YYCURSOR); -#line 1536 "ext/date/lib/parse_date.re" +#line 1537 "ext/date/lib/parse_date.re" { const timelib_relunit* relunit; DEBUG_OUTPUT("daytext"); @@ -4001,7 +4001,7 @@ yy191: } yy192: YYDEBUG(192, *YYCURSOR); -#line 1595 "ext/date/lib/parse_date.re" +#line 1596 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("monthtext"); TIMELIB_INIT; @@ -4061,7 +4061,7 @@ yy196: } yy197: YYDEBUG(197, *YYCURSOR); -#line 1345 "ext/date/lib/parse_date.re" +#line 1346 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datetextual | datenoyear"); TIMELIB_INIT; @@ -4342,7 +4342,7 @@ yy220: } yy221: YYDEBUG(221, *YYCURSOR); -#line 1643 "ext/date/lib/parse_date.re" +#line 1644 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz"); @@ -5048,7 +5048,7 @@ yy277: YYDEBUG(277, *YYCURSOR); ++YYCURSOR; YYDEBUG(278, *YYCURSOR); -#line 1619 "ext/date/lib/parse_date.re" +#line 1620 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("dateshortwithtimeshort12 | dateshortwithtimelong12"); TIMELIB_INIT; @@ -5244,7 +5244,7 @@ yy293: ++YYCURSOR; yy294: YYDEBUG(294, *YYCURSOR); -#line 1319 "ext/date/lib/parse_date.re" +#line 1320 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenoday"); TIMELIB_INIT; @@ -6466,7 +6466,7 @@ yy361: if (yych <= '9') goto yy364; yy363: YYDEBUG(363, *YYCURSOR); -#line 1459 "ext/date/lib/parse_date.re" +#line 1460 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pgtextshort"); TIMELIB_INIT; @@ -7062,7 +7062,7 @@ yy389: } yy390: YYDEBUG(390, *YYCURSOR); -#line 1515 "ext/date/lib/parse_date.re" +#line 1516 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("ago"); TIMELIB_INIT; @@ -9338,7 +9338,7 @@ yy472: } yy473: YYDEBUG(473, *YYCURSOR); -#line 1358 "ext/date/lib/parse_date.re" +#line 1359 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenoyearrev"); TIMELIB_INIT; @@ -9979,7 +9979,7 @@ yy531: if (yych <= '9') goto yy538; yy532: YYDEBUG(532, *YYCURSOR); -#line 1280 "ext/date/lib/parse_date.re" +#line 1281 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datefull"); TIMELIB_INIT; @@ -10729,7 +10729,7 @@ yy602: YYDEBUG(603, *YYCURSOR); ++YYCURSOR; YYDEBUG(604, *YYCURSOR); -#line 1294 "ext/date/lib/parse_date.re" +#line 1295 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pointed date YYYY"); TIMELIB_INIT; @@ -10776,7 +10776,7 @@ yy608: if (yych <= '9') goto yy602; yy609: YYDEBUG(609, *YYCURSOR); -#line 1306 "ext/date/lib/parse_date.re" +#line 1307 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pointed date YY"); TIMELIB_INIT; @@ -11429,7 +11429,7 @@ yy653: } yy654: YYDEBUG(654, *YYCURSOR); -#line 1267 "ext/date/lib/parse_date.re" +#line 1268 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("gnudateshort"); TIMELIB_INIT; @@ -11794,7 +11794,7 @@ yy697: if (yych <= ':') goto yy701; yy698: YYDEBUG(698, *YYCURSOR); -#line 1485 "ext/date/lib/parse_date.re" +#line 1486 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("clf"); @@ -12417,7 +12417,7 @@ yy768: YYDEBUG(768, *YYCURSOR); ++YYCURSOR; YYDEBUG(769, *YYCURSOR); -#line 1472 "ext/date/lib/parse_date.re" +#line 1473 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pgtextreverse"); TIMELIB_INIT; @@ -12567,7 +12567,7 @@ yy780: } yy781: YYDEBUG(781, *YYCURSOR); -#line 1506 "ext/date/lib/parse_date.re" +#line 1507 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("year4"); TIMELIB_INIT; @@ -12726,7 +12726,7 @@ yy790: } yy791: YYDEBUG(791, *YYCURSOR); -#line 1332 "ext/date/lib/parse_date.re" +#line 1333 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenodayrev"); TIMELIB_INIT; @@ -12953,7 +12953,7 @@ yy811: if (yych <= '7') goto yy814; yy812: YYDEBUG(812, *YYCURSOR); -#line 1440 "ext/date/lib/parse_date.re" +#line 1441 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweek"); @@ -12981,7 +12981,7 @@ yy814: YYDEBUG(814, *YYCURSOR); ++YYCURSOR; YYDEBUG(815, *YYCURSOR); -#line 1421 "ext/date/lib/parse_date.re" +#line 1422 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweekday"); @@ -13063,7 +13063,7 @@ yy818: } yy819: YYDEBUG(819, *YYCURSOR); -#line 1408 "ext/date/lib/parse_date.re" +#line 1409 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pgydotd"); TIMELIB_INIT; @@ -13178,7 +13178,7 @@ yy839: ++YYCURSOR; yy840: YYDEBUG(840, *YYCURSOR); -#line 1382 "ext/date/lib/parse_date.re" +#line 1383 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx | exif"); @@ -13465,7 +13465,7 @@ yy845: } yy846: YYDEBUG(846, *YYCURSOR); -#line 1370 "ext/date/lib/parse_date.re" +#line 1371 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenocolon"); TIMELIB_INIT; @@ -14403,11 +14403,12 @@ yy971: TIMELIB_HAVE_DATE(); s->time->y = timelib_get_nr((char **) &ptr, 4); s->time->m = timelib_get_nr((char **) &ptr, 2); + s->time->d = 1; TIMELIB_PROCESS_YEAR(s->time->y); TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 14411 "ext/date/lib/parse_date.c" +#line 14412 "ext/date/lib/parse_date.c" yy972: YYDEBUG(972, *YYCURSOR); yyaccept = 22; @@ -15438,7 +15439,7 @@ yy1065: TIMELIB_DEINIT; return TIMELIB_GNU_NOCOLON; } -#line 15442 "ext/date/lib/parse_date.c" +#line 15443 "ext/date/lib/parse_date.c" yy1066: YYDEBUG(1066, *YYCURSOR); yych = *++YYCURSOR; @@ -15549,7 +15550,7 @@ yy1073: TIMELIB_DEINIT; return TIMELIB_ISO_NOCOLON; } -#line 15553 "ext/date/lib/parse_date.c" +#line 15554 "ext/date/lib/parse_date.c" yy1074: YYDEBUG(1074, *YYCURSOR); yyaccept = 25; @@ -16447,7 +16448,7 @@ yy1114: } yy1115: YYDEBUG(1115, *YYCURSOR); -#line 1578 "ext/date/lib/parse_date.re" +#line 1579 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -16463,7 +16464,7 @@ yy1115: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 16467 "ext/date/lib/parse_date.c" +#line 16468 "ext/date/lib/parse_date.c" yy1116: YYDEBUG(1116, *YYCURSOR); ++YYCURSOR; @@ -16535,7 +16536,7 @@ yy1123: TIMELIB_DEINIT; return TIMELIB_WEEK_DAY_OF_MONTH; } -#line 16539 "ext/date/lib/parse_date.c" +#line 16540 "ext/date/lib/parse_date.c" yy1125: YYDEBUG(1125, *YYCURSOR); yyaccept = 26; @@ -16643,7 +16644,7 @@ yy1138: } yy1139: YYDEBUG(1139, *YYCURSOR); -#line 1554 "ext/date/lib/parse_date.re" +#line 1555 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -16666,7 +16667,7 @@ yy1139: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 16670 "ext/date/lib/parse_date.c" +#line 16671 "ext/date/lib/parse_date.c" yy1140: YYDEBUG(1140, *YYCURSOR); yych = *++YYCURSOR; @@ -19106,7 +19107,7 @@ yy1289: TIMELIB_DEINIT; return TIMELIB_LF_DAY_OF_MONTH; } -#line 19110 "ext/date/lib/parse_date.c" +#line 19111 "ext/date/lib/parse_date.c" yy1290: YYDEBUG(1290, *YYCURSOR); yych = *++YYCURSOR; @@ -20216,7 +20217,7 @@ yy1345: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 20220 "ext/date/lib/parse_date.c" +#line 20221 "ext/date/lib/parse_date.c" yy1346: YYDEBUG(1346, *YYCURSOR); yych = *++YYCURSOR; @@ -20663,7 +20664,7 @@ yy1375: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 20667 "ext/date/lib/parse_date.c" +#line 20668 "ext/date/lib/parse_date.c" yy1376: YYDEBUG(1376, *YYCURSOR); yych = *++YYCURSOR; @@ -20707,7 +20708,7 @@ yy1378: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 20711 "ext/date/lib/parse_date.c" +#line 20712 "ext/date/lib/parse_date.c" yy1379: YYDEBUG(1379, *YYCURSOR); yych = *++YYCURSOR; @@ -22539,7 +22540,7 @@ yy1458: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22543 "ext/date/lib/parse_date.c" +#line 22544 "ext/date/lib/parse_date.c" yy1459: YYDEBUG(1459, *YYCURSOR); yych = *++YYCURSOR; @@ -22689,7 +22690,7 @@ yy1466: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22693 "ext/date/lib/parse_date.c" +#line 22694 "ext/date/lib/parse_date.c" yy1467: YYDEBUG(1467, *YYCURSOR); yyaccept = 0; @@ -23180,7 +23181,7 @@ yy1489: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 23184 "ext/date/lib/parse_date.c" +#line 23185 "ext/date/lib/parse_date.c" yy1490: YYDEBUG(1490, *YYCURSOR); yyaccept = 0; @@ -23326,7 +23327,7 @@ yy1495: goto yy1489; } } -#line 1704 "ext/date/lib/parse_date.re" +#line 1705 "ext/date/lib/parse_date.re" } diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 8b48a80a0e..44d9c81e81 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -1258,6 +1258,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of TIMELIB_HAVE_DATE(); s->time->y = timelib_get_nr((char **) &ptr, 4); s->time->m = timelib_get_nr((char **) &ptr, 2); + s->time->d = 1; TIMELIB_PROCESS_YEAR(s->time->y); TIMELIB_DEINIT; return TIMELIB_ISO_DATE; diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 8c79778c32..5a31e6be44 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2962,20 +2962,15 @@ PHP_FUNCTION(date_modify) DATE_CHECK_INITIALIZED(dateobj->time, DateTime); tmp_time = timelib_strtotime(modify, modify_len, NULL, DATE_TIMEZONEDB); - dateobj->time->relative.y = tmp_time->relative.y; - dateobj->time->relative.m = tmp_time->relative.m; - dateobj->time->relative.d = tmp_time->relative.d; - dateobj->time->relative.h = tmp_time->relative.h; - dateobj->time->relative.i = tmp_time->relative.i; - dateobj->time->relative.s = tmp_time->relative.s; - dateobj->time->relative.weekday = tmp_time->relative.weekday; + memcpy(&dateobj->time->relative, &tmp_time->relative, sizeof(struct timelib_rel_time)); dateobj->time->have_relative = tmp_time->have_relative; - dateobj->time->relative.have_weekday_relative = tmp_time->relative.have_weekday_relative; dateobj->time->sse_uptodate = 0; timelib_time_dtor(tmp_time); timelib_update_ts(dateobj->time, NULL); timelib_update_from_sse(dateobj->time); + + RETURN_ZVAL(object, 1, 0); } /* }}} */ @@ -3115,6 +3110,8 @@ PHP_FUNCTION(date_timezone_set) } timelib_set_timezone(dateobj->time, tzobj->tzi.tz); timelib_unixtime2local(dateobj->time, dateobj->time->sse); + + RETURN_ZVAL(object, 1, 0); } /* }}} */ @@ -3171,6 +3168,8 @@ PHP_FUNCTION(date_time_set) dateobj->time->i = i; dateobj->time->s = s; timelib_update_ts(dateobj->time, NULL); + + RETURN_ZVAL(object, 1, 0); } /* }}} */ @@ -3192,6 +3191,8 @@ PHP_FUNCTION(date_date_set) dateobj->time->m = m; dateobj->time->d = d; timelib_update_ts(dateobj->time, NULL); + + RETURN_ZVAL(object, 1, 0); } /* }}} */ @@ -3216,6 +3217,8 @@ PHP_FUNCTION(date_isodate_set) dateobj->time->have_relative = 1; timelib_update_ts(dateobj->time, NULL); + + RETURN_ZVAL(object, 1, 0); } /* }}} */ @@ -3235,6 +3238,8 @@ PHP_FUNCTION(date_timestamp_set) DATE_CHECK_INITIALIZED(dateobj->time, DateTime); timelib_unixtime2local(dateobj->time, (timelib_sll)timestamp); timelib_update_ts(dateobj->time, NULL); + + RETURN_ZVAL(object, 1, 0); } /* }}} */ diff --git a/ext/date/tests/012.phpt b/ext/date/tests/012.phpt index 8b96509b45..c355484baf 100644 --- a/ext/date/tests/012.phpt +++ b/ext/date/tests/012.phpt @@ -20,15 +20,36 @@ var_dump($dto->format("Y/m/d H:i:s")); echo "Done\n"; ?> --EXPECTF-- -NULL +object(DateTime)#1 (3) { + [u"date"]=> + unicode(19) "2006-01-23 00:00:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(3) "UTC" +} unicode(19) "2006/01/23 00:00:00" Warning: date_isodate_set() expects at least 3 parameters, 2 given in %s on line %d bool(false) unicode(19) "2006/01/23 00:00:00" -NULL +object(DateTime)#1 (3) { + [u"date"]=> + unicode(19) "2006-01-30 00:00:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(3) "UTC" +} unicode(19) "2006/01/30 00:00:00" -NULL +object(DateTime)#1 (3) { + [u"date"]=> + unicode(19) "2007-12-10 00:00:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(3) "UTC" +} unicode(19) "2007/12/10 00:00:00" Warning: date_isodate_set() expects at most 4 parameters, 5 given in %s on line %d diff --git a/ext/date/tests/013.phpt b/ext/date/tests/013.phpt index f743208cc4..5497a936a4 100644 --- a/ext/date/tests/013.phpt +++ b/ext/date/tests/013.phpt @@ -37,8 +37,22 @@ unicode(19) "2006.12.12 00:00:00" Warning: date_date_set() expects exactly 4 parameters, 3 given in %s on line %d bool(false) unicode(19) "2006.12.12 00:00:00" -NULL +object(DateTime)#1 (3) { + [u"date"]=> + unicode(19) "2006-02-15 00:00:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(3) "UTC" +} unicode(19) "2006.02.15 00:00:00" -NULL +object(DateTime)#1 (3) { + [u"date"]=> + unicode(19) "2008-01-29 00:00:00" + [u"timezone_type"]=> + int(3) + [u"timezone"]=> + unicode(3) "UTC" +} unicode(19) "2008.01.29 00:00:00" Done diff --git a/ext/date/tests/date_parse_001.phpt b/ext/date/tests/date_parse_001.phpt index 72e1eec669..2fbb12ea60 100644 --- a/ext/date/tests/date_parse_001.phpt +++ b/ext/date/tests/date_parse_001.phpt @@ -79,7 +79,7 @@ array(15) { [u"month"]=> int(12) [u"day"]=> - bool(false) + int(1) [u"hour"]=> bool(false) [u"minute"]=> @@ -89,11 +89,9 @@ array(15) { [u"fraction"]=> bool(false) [u"warning_count"]=> - int(1) + int(0) [u"warnings"]=> - array(1) { - [12]=> - unicode(27) "The parsed date was invalid" + array(0) { } [u"error_count"]=> int(1) @@ -175,7 +173,7 @@ array(12) { [u"month"]=> int(3) [u"day"]=> - bool(false) + int(1) [u"hour"]=> bool(false) [u"minute"]=> @@ -185,11 +183,9 @@ array(12) { [u"fraction"]=> bool(false) [u"warning_count"]=> - int(1) + int(0) [u"warnings"]=> - array(1) { - [8]=> - unicode(27) "The parsed date was invalid" + array(0) { } [u"error_count"]=> int(0) -- 2.50.1