#include "lib/timelib.h"
#include <time.h>
-#ifndef HAVE_LLABS
-# ifdef PHP_WIN32
-static __inline __int64 llabs( __int64 i ) { return i >= 0? i: -i; }
-# elif defined(__GNUC__) && __GNUC__ < 3
-static __inline __int64_t llabs( __int64_t i ) { return i >= 0 ? i : -i; }
-# elif defined(NETWARE) && defined(__MWERKS__)
-static __inline long long llabs( long long i ) { return i >= 0 ? i : -i; }
-# endif
+#ifdef PHP_WIN32
+# include "win32/php_stdint.h"
#endif
+static __inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i; }
+
/* {{{ arginfo */
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_date, 0, 0, 1)
{
smart_str string = {0};
int i, length;
- char buffer[33];
+ char buffer[97];
timelib_time_offset *offset = NULL;
timelib_sll isoweek, isoyear;
int rfc_colon;
/* year */
case 'L': length = slprintf(buffer, 32, "%d", timelib_is_leap((int) t->y)); break;
case 'y': length = slprintf(buffer, 32, "%02d", (int) t->y % 100); break;
- case 'Y': length = slprintf(buffer, 32, "%s%04lld", t->y < 0 ? "-" : "", llabs(t->y)); break;
+ case 'Y': length = slprintf(buffer, 32, "%s%04lld", t->y < 0 ? "-" : "", php_date_llabs((timelib_sll) t->y)); break;
/* time */
case 'a': length = slprintf(buffer, 32, "%s", t->h >= 12 ? "pm" : "am"); break;
localtime ? abs((offset->offset % 3600) / 60) : 0
);
break;
- case 'r': length = slprintf(buffer, 32, "%3s, %02d %3s %04d %02d:%02d:%02d %c%02d%02d",
+ case 'r': length = slprintf(buffer, 96, "%3s, %02d %3s %04d %02d:%02d:%02d %c%02d%02d",
php_date_short_day_name(t->y, t->m, t->d),
(int) t->d, mon_short_names[t->m - 1],
(int) t->y, (int) t->h, (int) t->i, (int) t->s,
char *modify;
int modify_len;
timelib_time *tmp_time;
+ timelib_error_container *err = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, date_ce_date, &modify, &modify_len) == FAILURE) {
RETURN_FALSE;
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
- tmp_time = timelib_strtotime(modify, modify_len, NULL, DATE_TIMEZONEDB);
+ tmp_time = timelib_strtotime(modify, modify_len, &err, DATE_TIMEZONEDB);
+
+ if (err && err->error_count) {
+ /* spit out the first library error message, at least */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", modify,
+ err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message);
+ timelib_time_dtor(tmp_time);
+ RETURN_FALSE;
+ }
+
memcpy(&dateobj->time->relative, &tmp_time->relative, sizeof(struct timelib_rel_time));
dateobj->time->have_relative = tmp_time->have_relative;
dateobj->time->have_weekday_relative = tmp_time->have_weekday_relative;
--- /dev/null
+--TEST--
+Bug #45866 (decimal values fed to DateTime->modify() causes long execution times)
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$date = new DateTime( '2009-07-29 16:44:23 Europe/London' );
+$date->modify( "+1.61538461538 day" );
+echo $date->format( 'r' ), "\n";
+
+$date = new DateTime( '2009-07-29 16:44:23 Europe/London' );
+$date->modify( "61538461538 day" );
+echo $date->format( 'r' ), "\n";
+
+$date = new DateTime( '2009-07-29 16:44:23 Europe/London' );
+$date->modify( "£61538461538 day" );
+echo $date->format( 'r' ), "\n";
+?>
+--EXPECTF--
+Thu, 14 Aug 168488594 16:44:23 +0000
+Thu, 14 Aug 168488594 16:44:23 +0000
+
+Warning: DateTime::modify(): Failed to parse time string (£61538461538 day) at position 0 (%s): Unexpected character in %sbug45866.php on line 11
+Wed, 29 Jul 2009 16:44:23 +0100