Skip to content

Commit fe97a5a

Browse files
committed
Merge remote-tracking branch 'derickr/bug77342' into PHP-8.0
2 parents a83363e + b23dfe4 commit fe97a5a

File tree

6 files changed

+112
-4
lines changed

6 files changed

+112
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Date:
66
. Fixed bug #74671 (DST timezone abbreviation has incorrect offset). (Derick)
7+
. Fixed bug #77243 (Weekdays are calculated incorrectly for negative years).
8+
(Derick)
79
. Fixed bug #78139 (timezone_open accepts invalid timezone string argument).
810
(Derick)
911

ext/date/lib/dow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static timelib_sll timelib_day_of_week_ex(timelib_sll y, timelib_sll m, timelib_
5252
/* Only valid for Gregorian calendar, commented out as we don't handle
5353
* Julian calendar. We just return the 'wrong' day of week to be
5454
* consistent. */
55-
c1 = century_value(y / 100);
55+
c1 = century_value(positive_mod(y, 400) / 100);
5656
y1 = positive_mod(y, 100);
5757
m1 = timelib_is_leap(y) ? m_table_leap[m] : m_table_common[m];
5858
dow = positive_mod((c1 + y1 + m1 + (y1 / 4) + d), 7);

ext/date/tests/bug49585.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ var_dump($date->format('c'));
1313
?>
1414
--EXPECT--
1515
string(32) "Fri, 01 Jan -1500 00:00:00 +0000"
16-
string(38) "Mon, 01 Jan -2147483648 00:00:00 +0000"
16+
string(38) "Tue, 01 Jan -2147483648 00:00:00 +0000"
1717
string(32) "-2147483648-01-01T00:00:00+00:00"

ext/date/tests/bug75851.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ echo date(DATE_ATOM."\n".DATE_RFC2822."\nc\nr\no\ny\nY\nU\n\n", PHP_INT_MAX);
1313
?>
1414
--EXPECT--
1515
-292277022657-01-27T08:29:52+00:00
16-
Fri, 27 Jan -292277022657 08:29:52 +0000
16+
Sun, 27 Jan -292277022657 08:29:52 +0000
1717
-292277022657-01-27T08:29:52+00:00
18-
Fri, 27 Jan -292277022657 08:29:52 +0000
18+
Sun, 27 Jan -292277022657 08:29:52 +0000
1919
-292277022657
2020
-57
2121
-292277022657

ext/date/tests/bug77243-001.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Bug #77243 (Weekdays are calculated incorrectly for negative years)
3+
--SKIPIF--
4+
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
5+
--FILE--
6+
<?php
7+
date_default_timezone_set('UTC');
8+
9+
$time=-62167046400; // 0000-01-03 0-01-1
10+
11+
for ($i = -10; $i < 10; $i++ )
12+
{
13+
echo date('Y-m-d o-W-N', $time + ($i * 86400)), "\n";
14+
}
15+
?>
16+
--EXPECT--
17+
-0001-12-24 -1-51-5
18+
-0001-12-25 -1-51-6
19+
-0001-12-26 -1-51-7
20+
-0001-12-27 -1-52-1
21+
-0001-12-28 -1-52-2
22+
-0001-12-29 -1-52-3
23+
-0001-12-30 -1-52-4
24+
-0001-12-31 -1-52-5
25+
0000-01-01 -1-52-6
26+
0000-01-02 -1-52-7
27+
0000-01-03 0-01-1
28+
0000-01-04 0-01-2
29+
0000-01-05 0-01-3
30+
0000-01-06 0-01-4
31+
0000-01-07 0-01-5
32+
0000-01-08 0-01-6
33+
0000-01-09 0-01-7
34+
0000-01-10 0-02-1
35+
0000-01-11 0-02-2
36+
0000-01-12 0-02-3

ext/date/tests/bug77243-002.phpt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--TEST--
2+
Bug #77243 (Weekdays are calculated incorrectly for negative years)
3+
--SKIPIF--
4+
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
5+
--FILE--
6+
<?php
7+
date_default_timezone_set('UTC');
8+
9+
$startingPoints = [
10+
-62167046400 - (((101 * 365) + 25) * 86400),
11+
-62167046400 - (((100 * 365) + 25) * 86400),
12+
-62167046400 - ((( 99 * 365) + 25) * 86400),
13+
];
14+
15+
foreach ($startingPoints as $startingPoint)
16+
{
17+
for ($i = -7; $i < 7; $i++ )
18+
{
19+
echo date('Y-m-d o-W-N', $startingPoint + ($i * 86400)), "\n";
20+
}
21+
echo "\n\n";
22+
}
23+
?>
24+
--EXPECT--
25+
-0102-12-26 -102-52-1
26+
-0102-12-27 -102-52-2
27+
-0102-12-28 -102-52-3
28+
-0102-12-29 -102-52-4
29+
-0102-12-30 -102-52-5
30+
-0102-12-31 -102-52-6
31+
-0101-01-01 -102-52-7
32+
-0101-01-02 -101-01-1
33+
-0101-01-03 -101-01-2
34+
-0101-01-04 -101-01-3
35+
-0101-01-05 -101-01-4
36+
-0101-01-06 -101-01-5
37+
-0101-01-07 -101-01-6
38+
-0101-01-08 -101-01-7
39+
40+
41+
-0101-12-26 -101-52-2
42+
-0101-12-27 -101-52-3
43+
-0101-12-28 -101-52-4
44+
-0101-12-29 -101-52-5
45+
-0101-12-30 -101-52-6
46+
-0101-12-31 -101-52-7
47+
-0100-01-01 -100-01-1
48+
-0100-01-02 -100-01-2
49+
-0100-01-03 -100-01-3
50+
-0100-01-04 -100-01-4
51+
-0100-01-05 -100-01-5
52+
-0100-01-06 -100-01-6
53+
-0100-01-07 -100-01-7
54+
-0100-01-08 -100-02-1
55+
56+
57+
-0100-12-26 -100-52-3
58+
-0100-12-27 -100-52-4
59+
-0100-12-28 -100-52-5
60+
-0100-12-29 -100-52-6
61+
-0100-12-30 -100-52-7
62+
-0100-12-31 -99-01-1
63+
-0099-01-01 -99-01-2
64+
-0099-01-02 -99-01-3
65+
-0099-01-03 -99-01-4
66+
-0099-01-04 -99-01-5
67+
-0099-01-05 -99-01-6
68+
-0099-01-06 -99-01-7
69+
-0099-01-07 -99-02-1
70+
-0099-01-08 -99-02-2

0 commit comments

Comments
 (0)