Bug #73097 [Opn->Nab]: strftime %G does not work in some cases

From: Date: Fri, 16 Sep 2016 15:12:13 +0000
Subject: Bug #73097 [Opn->Nab]: strftime %G does not work in some cases
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204081@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73097&edit=1

 ID:                 73097
 Updated by:         requinix@php.net
 Reported by:        dmanye at gmail dot com
 Summary:            strftime %G does not work in some cases
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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

http://php.net/manual/en/function.strftime.php
> %G	The full four-digit version of %g
> %g	Two digit representation of the year going by ISO-8601:1988 standards (see %V)
> %V	ISO-8601:1988 week number of the given year, starting with the first week of the year with
> at least 4 weekdays, with Monday being the start of the week

Compare with
> %Y	Four digit representation for the year


Previous Comments:
------------------------------------------------------------------------
[2016-09-16 10:38:07] dmanye at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=73097&edit=1


Thread (2 messages)

« previous php.bugs (#204081) next »