Bug #72096 [Ver->Csd]: Swatch time value incorrect for dates before 1970
Edit report at https://bugs.php.net/bug.php?id=72096&edit=1
ID: 72096
Updated by: nikic@php.net
Reported by: p987b at davewilliamsmedia dot com
Summary: Swatch time value incorrect for dates before 1970
-Status: Verified
+Status: Closed
Type: Bug
Package: Date/time related
Operating System: Windows
PHP Version: 5.6.20
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of php@mcq8.be
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b224e7426713befd7449117afd68355231f9077e
Log: Fixed bug #72096 Swatch time value incorrect for dates before 1970
Previous Comments:
------------------------------------------------------------------------
[2016-04-24 21:06:35] requinix@php.net
Done some digging around. Yadda yadda yadda, the time is supposed to be calculated as floor(seconds
past midnight in UTC+1 / 86.4). The ext/date code uses integer division, and with the negative
numbers it explains the accidental rounding up.
The official website <http://www.swatch.com/en_us/internet-time/>
has the same bug, but it looks like they're running PHP so...
------------------------------------------------------------------------
[2016-04-24 18:54:14] p987b at davewilliamsmedia dot com
Description:
------------
For dates prior to 1970, (i.e. dates represented by a negative unix timestamp value), swatch values
produced by the gmdate() function using format character 'B' are incorrectly rounded-up.
They consequently differ from the values produced for identical times of day on dates after 1970, as
these are correctly rounded-down.
This problem occurs on PHP 5.3 as well as 5.6.
Test script:
---------------
for ($unix=1461283200;$unix<=1461369600;$unix+=8000)
{
echo "\n Time:".gmdate('Y-m-d H:i:s = B ',$unix);
echo " Time:".gmdate('Y-m-d H:i:s = B ',$unix-2592000000);
}
Expected result:
----------------
I would expect the three-digit swatch time values produced for the 1934 date (right-hand column) to
be identical to the swatch values produced for the 2016 date (left-hand column), for any given time
of day.
Actual result:
--------------
Time:2016-04-22 00:00:00 = 041 Time:1934-03-04 00:00:00 = 041
Time:2016-04-22 02:13:20 = 134 Time:1934-03-04 02:13:20 = 135
Time:2016-04-22 04:26:40 = 226 Time:1934-03-04 04:26:40 = 227
Time:2016-04-22 06:40:00 = 319 Time:1934-03-04 06:40:00 = 320
Time:2016-04-22 08:53:20 = 412 Time:1934-03-04 08:53:20 = 413
Time:2016-04-22 11:06:40 = 504 Time:1934-03-04 11:06:40 = 505
Time:2016-04-22 13:20:00 = 597 Time:1934-03-04 13:20:00 = 598
Time:2016-04-22 15:33:20 = 689 Time:1934-03-04 15:33:20 = 690
Time:2016-04-22 17:46:40 = 782 Time:1934-03-04 17:46:40 = 783
Time:2016-04-22 20:00:00 = 875 Time:1934-03-04 20:00:00 = 875
Time:2016-04-22 22:13:20 = 967 Time:1934-03-04 22:13:20 = 968
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72096&edit=1
Thread (3 messages)