Bug #77243 [Opn]: Weekdays are calculated incorrectly for negative years

From: Date: Sat, 17 Oct 2020 13:52:46 +0000
Subject: Bug #77243 [Opn]: Weekdays are calculated incorrectly for negative years
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229689@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77243&edit=1 ID: 77243 Updated by: cmb@php.net Reported by: bjoern dot fischer at dezem dot de Summary: Weekdays are calculated incorrectly for negative years Status: Open Type: Bug Package: Date/time related Operating System: Linux PHP Version: 7.2.12 Block user comment: N Private report: N New Comment: > Expected: 0000-01-02 There is no year zero in the Gregorian nor the Julian calendar, though. Consider to use ext/calendar for such purposes. Previous Comments: ------------------------------------------------------------------------ [2018-12-05 15:41:23] danack@php.net From the date page http://php.net/manual/en/function.date.php : The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows). You may need to use a more specific library to cope with BCE dates, and to do things like deal with the Julian to Gregorian calendar changes. ------------------------------------------------------------------------ [2018-12-05 14:32:02] bjoern dot fischer at dezem dot de 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 this bug report at https://bugs.php.net/bug.php?id=77243&edit=1

« previous php.bugs (#229689) next »