Bug #73097 [NEW]: strftime %G does not work in some cases
| From: | dmanye at gmail dot com | Date: | Fri, 16 Sep 2016 10:38:08 +0000 |
| Subject: | Bug #73097 [NEW]: strftime %G does not work in some cases | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204072@lists.php.net to get a copy of this message | ||
From: dmanye at gmail dot com
Operating system: linux
PHP version: Irrelevant
Package: Date/time related
Bug Type: Bug
Bug description:strftime %G does not work in some cases
Description:
------------
strftime(%G) for Jan 1st 2017 returns 2016 instead of 2017.
trying with other years works as expected (2013..2015 and 2018..2020)
but others do not (2005, 2006, 2010..2012, 2016, 2017). these lists are
not exhaustive.
tested on 7.0.10 and 5.6.7 php versions.
the date function works as expected.
here's a second 19-line script that looks for the first January day
where %G works as expected:
-----------------
<?php
echo "php version: " . phpversion() . "\n";
for ($year=1970;$year<2030;$year++) {
$day = 1;
$seconds = mktime(0,0,0,1,$day,$year);
while ( strftime("%G",$seconds) != $year ) {
$day ++;
$seconds = mktime(0,0,0,1,$day,$year);
}
if ($day == 1)
echo "$year: ok\n";
else
echo "$year: it is not $year until " . strftime("%c",$seconds) .
"\n";
}
----------------------------------
thanks.
Test script:
---------------
<?php
echo "php version: " . phpversion() . "\n";
$seconds = mktime(0,0,0,1,1,2017);
echo "seconds from epoch: $seconds\n";
echo "strftime(%G): " . strftime("%G",$seconds) . "\n";
echo "strftime(%c): " . strftime("%c",$seconds) . "\n";
echo "date(Y) : " . date("Y",$seconds) . "\n";
?>
Expected result:
----------------
php version: 7.0.10-1
seconds from epoch: 1483225200
strftime(%G): 2017
strftime(%c): Sun Jan 1 00:00:00 2017
date(Y) : 2017
Actual result:
--------------
php version: 7.0.10-1
seconds from epoch: 1483225200
strftime(%G): 2016
strftime(%c): Sun Jan 1 00:00:00 2017
date(Y) : 2017
--
Edit bug report at https://bugs.php.net/bug.php?id=73097&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73097&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73097&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73097&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73097&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73097&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73097&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73097&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73097&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73097&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73097&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73097&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73097&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73097&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73097&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73097&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73097&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73097&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73097&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73097&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73097&r=mysqlcfg