php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50105 strtotime, strftime, weekday & monday & year leap
Submitted: 2009-11-06 21:12 UTC Modified: 2009-11-06 21:39 UTC
From: tcheko at no-log dot org Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.0 OS: Linux
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: tcheko at no-log dot org
New email:
PHP Version: OS:

 

 [2009-11-06 21:12 UTC] tcheko at no-log dot org
Description:
------------
This code fails on two weeks. Week 1, year printed is 2009 instead of dec 29 2008 and week 52, year printed is 2009 instead of Jan 3 2010.

Bug or feature or am I doing something wrong ?
 

Reproduce code:
---------------
setlocale(LC_ALL, "fr_FR.utf8");
date_default_timezone_set("Europe/Paris");

// Get the number of weeks in a year
$weeks = date("W", mktime(0,0,0,12,31, 2009));
// print the 1st monday of each week with year
for($i=1; $i <= $weeks; $i++)
{
	if(strlen($i) == 1) $w = "0" . $i; else $w = $i;
	echo strftime("%A %e %B %G", strtotime("2009W$w")) . " - " .strftime("%A %e %B %G", strtotime("2009W$w +6days"));
}



Expected result:
----------------
lundi 28 d?cembre 2008 instead of lundi 28 d?cembre 2009

dimanche 3 janvier 2010 instead of dimanche 3 janvier 2009


Actual result:
--------------
Actual code output. Submitted code stripped to revelant part only.

Semaine n?1 du lundi 29 d?cembre 2009 au dimanche 4 janvier 2009
Semaine n?53 du lundi 28 d?cembre 2009 au dimanche 3 janvier 2009

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-06 21:39 UTC] 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

You're doing it wrong, please read:

       %G     The ISO 8601 week-based year (see NOTES) with century as a deci&#8208;
              mal number.  The 4-digit year corresponding to the ISO week num&#8208;
              ber  (see %V).  This has the same format and value as %Y, except
              that if the ISO week number belongs  to  the  previous  or  next
              year, that year is used instead. (TZ)

NOTES
   ISO 8601 Week Dates
       %G, %g, and %V yield values calculated from the week-based year defined
       by the ISO 8601 standard.  In this system, weeks start on a Monday, and
       are numbered from 01, for the first week, up to 52 or 53, for the  last
       week.  Week 1 is the first week where four or more days fall within the
       new year (or, synonymously, week 01 is: the first week of the year that
       contains  a  Thursday;  or,  the  week that has 4 January in it).  When
       three of fewer days of the first calendar week of  the  new  year  fall
       within that year, then the ISO 8601 week-based system counts those days
       as part of week 53 of the preceding year.  For example, 1 January  2010
       is a Friday, meaning that just three days of that calendar week fall in
       2010.  Thus, the ISO 8601 week-based system considers these days to  be
       part  of  week 53 (%V) of the year 2009 (%G) ; week 01 of ISO 8601 year
       2010 starts on Thursday, 4 January 2010.

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 09:00:02 2026 UTC