]> granicus.if.org Git - php/commitdiff
- Fixed bug #36988 (mktime freezes on long numbers)
authorDerick Rethans <derick@php.net>
Tue, 11 Apr 2006 17:56:49 +0000 (17:56 +0000)
committerDerick Rethans <derick@php.net>
Tue, 11 Apr 2006 17:56:49 +0000 (17:56 +0000)
ext/date/lib/timelib_structs.h
ext/date/lib/tm2unixtime.c
ext/date/tests/bug36988.phpt [new file with mode: 0644]

index 55831dbd09a97fa935b0afa7a5b902f3466daa28..373fecb9c208d51891a129ea13507adb31389f4b 100644 (file)
@@ -183,9 +183,10 @@ typedef struct _timelib_tzdb {
 #define TIMELIB_ZONETYPE_ABBR   2
 #define TIMELIB_ZONETYPE_ID     3
 
-#define SECS_PER_DAY   86400
-#define DAYS_PER_YEAR    365
-#define DAYS_PER_LYEAR   366
+#define SECS_PER_ERA 12622780800L
+#define SECS_PER_DAY       86400
+#define DAYS_PER_YEAR        365
+#define DAYS_PER_LYEAR       366
 
 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
 
index cb4cfeba3a0b21d708aadeb8799eaa88ddaee0f6..70094dcad34f09801be17619f2594add16ff703b 100644 (file)
@@ -135,6 +135,13 @@ static timelib_sll do_years(timelib_sll year)
 {
        timelib_sll i;
        timelib_sll res = 0;
+       timelib_sll eras;
+
+       eras = (year - 1970) / 400;
+       if (eras != 0) {
+               year = year - (eras * 400);
+               res += (SECS_PER_ERA * eras);
+       }
 
        if (year >= 1970) {
                for (i = year - 1; i >= 1970; i--) {
diff --git a/ext/date/tests/bug36988.phpt b/ext/date/tests/bug36988.phpt
new file mode 100644 (file)
index 0000000..e9fd69d
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #36988 (mktime freezes on long numbers)
+--FILE--
+<?php
+$start = microtime(true);
+$a = mktime(1, 1, 1, 1, 1, 11111111111);
+echo (microtime(true) - $start) < 1 ? "smaller than one second" : "more than a second";
+?>
+--EXPECT--
+smaller than one second