php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72096 Swatch time value incorrect for dates before 1970
Submitted: 2016-04-24 18:54 UTC Modified: 2016-04-24 21:06 UTC
From: p987b at davewilliamsmedia dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.6.20 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: p987b at davewilliamsmedia dot com
New email:
PHP Version: OS:

 

 [2016-04-24 18:54 UTC] 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   

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-24 21:06 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2016-04-24 21:06 UTC] 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...
 [2017-03-09 15:46 UTC] nikic@php.net
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
 [2017-03-09 15:46 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC