php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71725 Incorrect ordinal suffix used for 29th February
Submitted: 2016-03-06 22:27 UTC Modified: 2016-03-07 01:11 UTC
From: daniel at honestempire dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.0.4 OS: Mac OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniel at honestempire dot com
New email:
PHP Version: OS:

 

 [2016-03-06 22:27 UTC] daniel at honestempire dot com
Description:
------------
When attempting to find the last weekday of February 2016, I stumbled across this bug. See the test script for replication information.

Test script:
---------------
$lastDayOfMonth = date('tS F Y', strtotime('2016-02-01 12:00:00'));
var_dump($lastDayOfMonth); // string(18) "29st February 2016"
var_dump(date('d', strtotime(sprintf('last weekday %s', $lastDayOfMonth)))); // string(2) "26" (should be string(2) "29")



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-06 22:46 UTC] daniel at honestempire dot com
-Status: Open +Status: Closed
 [2016-03-06 22:46 UTC] daniel at honestempire dot com
It would appear the ordinal is parsed before the t flag, removing the ordinal fixes my issue.
 [2016-03-07 01:11 UTC] requinix@php.net
-Status: Closed +Status: Not a bug -Package: Calendar related +Package: Date/time related
 [2016-03-07 01:11 UTC] requinix@php.net
'S' works according to the date you passed, which was Feb 1. 't' is merely the number of days in the month and will not magically turn the date into Feb 29.

// 03-00 will underflow to whichever is the last day of February
$lastDayOfMonth = date('jS F Y', strtotime('2016-03-00 12:00:00'));
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 01:01:31 2024 UTC