Bug #77243 [NEW]: Weekdays are calculated incorrectly for negative years
From: bjoern dot fischer at dezem dot de
Operating system: Linux
PHP version: 7.2.12
Package: Date/time related
Bug Type: Bug
Bug description:Weekdays are calculated incorrectly for negative years
Description:
------------
When we reach negative years 'date()' calulates the day of the week 'N'
incorrectly.
Apparently one day too much is subtracted in this case.
So that for example the date '-1-W52-3' is displayed as '-1-W52-2'
instead, when using 'date()'.
The issue can be easily reproduced here:
https://3v4l.org/4Glr2
Test script:
---------------
<?php
date_default_timezone_set('UTC');
$time=-62167046400; // 0000-01-03 0-01-1
var_dump(date('Y-m-d o-W-N', $time - 86400));
var_dump(date('Y-m-d o-W-N', $time - 86400 * 2));
var_dump(date('Y-m-d o-W-N', $time - 86400 * 3), 'The issue appeared
here. Expected: 0000-01-02 -1-52-5');
var_dump(date('Y-m-d o-W-N', $time - 86400 * 4));
var_dump(date('Y-m-d o-W-N', $time - 86400 * 5));
Expected result:
----------------
The date should be formatted correctly and the displayed weekday should
match the actual weekday for a timestamp.
Actual result:
--------------
The date is formatted incorrectly and the displayed weekday, for
negative years, is one less than the actual weekday.
--
Edit bug report at https://bugs.php.net/bug.php?id=77243&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77243&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77243&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77243&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77243&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77243&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77243&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77243&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77243&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77243&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77243&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77243&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77243&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77243&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77243&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77243&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77243&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77243&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77243&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77243&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77243&r=mysqlcfg
Thread (6 messages)
- bjoern dot fischer at dezem dot de