Bug #70335 [Com]: DateTime doesn't take into account leap seconsa

From: Date: Sun, 23 Aug 2015 17:02:44 +0000
Subject: Bug #70335 [Com]: DateTime doesn't take into account leap seconsa
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195450@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70335&edit=1

 ID:                 70335
 Comment by:         teo8976 at gmail dot com
 Reported by:        teo8976 at gmail dot com
 Summary:            DateTime doesn't take into account leap seconsa
 Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 PHP Version:        7.0.0RC1
 Block user comment: N
 Private report:     N

 New Comment:

And how is it not a bug to arbitrarily adopt a calendar that is not the one the whole industrialized
world currently agrees upon?


Previous Comments:
------------------------------------------------------------------------
[2015-08-23 16:57:33] teo8976 at gmail dot com

How is it not a bug calling UTC what is not UTC??

------------------------------------------------------------------------
[2015-08-23 16:45:21] derick@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

PHP uses the proleptic Gregorian calendar 
which doesn't do leap seconds.

------------------------------------------------------------------------
[2015-08-23 16:18:09] teo8976 at gmail dot com

> and the conversion between timestamps and UTC is therefore offset 
> of a few seconds


And of course adding date/time intervals may result in inaccurate times as demonstrated in the
example.

------------------------------------------------------------------------
[2015-08-23 16:15:51] teo8976 at gmail dot com

Description:
------------
https://en.wikipedia.org/wiki/Leap_second#Insertion_of_leap_seconds

Test script:
---------------
https://3v4l.org/DL88F

<?php
$date=date_create("Jun 30 2015 23:59:59", new DateTimeZone("UTC"));
print_r($date);
print_r($date->getTimeStamp());
echo "\n";
$date= $date->add(new DateInterval("PT1S"));
print_r($date);
print_r($date->getTimeStamp());

$date2=date_create("now", new DateTimeZone("UTC"));
$date2->setTimeStamp("1435708799");
print_r($date2);
$date2->setTimeStamp("1435708801");
print_r($date2);

Expected result:
----------------
Adding one second to jun 30 2015 23:59:59 UTC should yield jun 30 2015 23:59:60 UTC because of the
leap second. Same for 2012 (and a few more years).

If the timestamp 1435708799 corresponds to jun 30 2015 23:59:59, which it shouldn't because it
is calculated without taking into account the 25 leap seconds occurred since the beginning of the
Unix Epoch until that date, but if it was, then  1435708800 should correspond to jun 30 2015
23:59:60 and 1435708801 should be jul 1 2015 00:00:00

Actual result:
--------------
Leap seconds are not taken into account, as if they didn't exist. No 23:59:60 time exists for
the days where it should, and the conversion between timestamps and UTC is therefore offset of a few
seconds depending on the date, up to 26 seconds today.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70335&edit=1


Thread (11 messages)

« previous php.bugs (#195450) next »