Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/date/lib/dow.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static timelib_sll timelib_day_of_week_ex(timelib_sll y, timelib_sll m, timelib_
/* Only valid for Gregorian calendar, commented out as we don't handle
* Julian calendar. We just return the 'wrong' day of week to be
* consistent. */
c1 = century_value(y / 100);
c1 = century_value(positive_mod(y, 400) / 100);
y1 = positive_mod(y, 100);
m1 = timelib_is_leap(y) ? m_table_leap[m] : m_table_common[m];
dow = positive_mod((c1 + y1 + m1 + (y1 / 4) + d), 7);
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/bug49585.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ var_dump($date->format('c'));
?>
--EXPECT--
string(32) "Fri, 01 Jan -1500 00:00:00 +0000"
string(38) "Mon, 01 Jan -2147483648 00:00:00 +0000"
string(38) "Tue, 01 Jan -2147483648 00:00:00 +0000"
string(32) "-2147483648-01-01T00:00:00+00:00"
4 changes: 2 additions & 2 deletions ext/date/tests/bug75851.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", PHP_INT_MAX);
?>
--EXPECT--
-292277022657-01-27T08:29:52+00:00
Fri, 27 Jan -292277022657 08:29:52 +0000
Sun, 27 Jan -292277022657 08:29:52 +0000
-292277022657-01-27T08:29:52+00:00
Fri, 27 Jan -292277022657 08:29:52 +0000
Sun, 27 Jan -292277022657 08:29:52 +0000
-292277022657
-57
-292277022657
Expand Down
36 changes: 36 additions & 0 deletions ext/date/tests/bug77243-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Bug #77243 (Weekdays are calculated incorrectly for negative years)
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
--FILE--
<?php
date_default_timezone_set('UTC');

$time=-62167046400; // 0000-01-03 0-01-1

for ($i = -10; $i < 10; $i++ )
{
echo date('Y-m-d o-W-N', $time + ($i * 86400)), "\n";
}
?>
--EXPECT--
-0001-12-24 -1-51-5
-0001-12-25 -1-51-6
-0001-12-26 -1-51-7
-0001-12-27 -1-52-1
-0001-12-28 -1-52-2
-0001-12-29 -1-52-3
-0001-12-30 -1-52-4
-0001-12-31 -1-52-5
0000-01-01 -1-52-6
0000-01-02 -1-52-7
0000-01-03 0-01-1
0000-01-04 0-01-2
0000-01-05 0-01-3
0000-01-06 0-01-4
0000-01-07 0-01-5
0000-01-08 0-01-6
0000-01-09 0-01-7
0000-01-10 0-02-1
0000-01-11 0-02-2
0000-01-12 0-02-3
70 changes: 70 additions & 0 deletions ext/date/tests/bug77243-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--TEST--
Bug #77243 (Weekdays are calculated incorrectly for negative years)
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
--FILE--
<?php
date_default_timezone_set('UTC');

$startingPoints = [
-62167046400 - (((101 * 365) + 25) * 86400),
-62167046400 - (((100 * 365) + 25) * 86400),
-62167046400 - ((( 99 * 365) + 25) * 86400),
];

foreach ($startingPoints as $startingPoint)
{
for ($i = -7; $i < 7; $i++ )
{
echo date('Y-m-d o-W-N', $startingPoint + ($i * 86400)), "\n";
}
echo "\n\n";
}
?>
--EXPECT--
-0102-12-26 -102-52-1
-0102-12-27 -102-52-2
-0102-12-28 -102-52-3
-0102-12-29 -102-52-4
-0102-12-30 -102-52-5
-0102-12-31 -102-52-6
-0101-01-01 -102-52-7
-0101-01-02 -101-01-1
-0101-01-03 -101-01-2
-0101-01-04 -101-01-3
-0101-01-05 -101-01-4
-0101-01-06 -101-01-5
-0101-01-07 -101-01-6
-0101-01-08 -101-01-7


-0101-12-26 -101-52-2
-0101-12-27 -101-52-3
-0101-12-28 -101-52-4
-0101-12-29 -101-52-5
-0101-12-30 -101-52-6
-0101-12-31 -101-52-7
-0100-01-01 -100-01-1
-0100-01-02 -100-01-2
-0100-01-03 -100-01-3
-0100-01-04 -100-01-4
-0100-01-05 -100-01-5
-0100-01-06 -100-01-6
-0100-01-07 -100-01-7
-0100-01-08 -100-02-1


-0100-12-26 -100-52-3
-0100-12-27 -100-52-4
-0100-12-28 -100-52-5
-0100-12-29 -100-52-6
-0100-12-30 -100-52-7
-0100-12-31 -99-01-1
-0099-01-01 -99-01-2
-0099-01-02 -99-01-3
-0099-01-03 -99-01-4
-0099-01-04 -99-01-5
-0099-01-05 -99-01-6
-0099-01-06 -99-01-7
-0099-01-07 -99-02-1
-0099-01-08 -99-02-2