php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61962 Relative format : second/third... not parsed
Submitted: 2012-05-06 11:30 UTC Modified: 2017-01-13 07:03 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:-1 (-100.0%)
From: francois dot dambrine at isen-lille dot fr Assigned: heiglandreas (profile)
Status: Assigned Package: Date/time related
PHP Version: 5.4.2 OS: Ubuntu 11.10
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: francois dot dambrine at isen-lille dot fr
New email:
PHP Version: OS:

 

 [2012-05-06 11:30 UTC] francois dot dambrine at isen-lille dot fr
Description:
------------
As I was testing a script where I need to get the second day of previous month I 
found out this issue : I can't get this day with that phrase.
With larger tests I got the issue for every "ordinal" keyword apart from "first" 
and "last".

Test script:
---------------
date_default_timezone_set('Europe/Paris');
$firstDay = new DateTime('first day of previous month');
echo $firstDay->format('l').PHP_EOL;
$lastDay = new DateTime('last day of previous month');
echo $lastDay->format('l').PHP_EOL;
$secondDay = new DateTime('second day of previous month');
echo $secondDay->format('l').PHP_EOL;
$thirdDay = new DateTime('third day of previous month');
echo $thirdDay->format('l').PHP_EOL;

Expected result:
----------------
Sunday
Monday
Monday
Tuesday

Actual result:
--------------
Sunday
Monday
PHP Fatal error:  Uncaught exception 'Exception' with message 
'DateTime::__construct(): Failed to parse time string (second day of previous 
month) at position 11 (o): The timezone could not be found in the database' in 
/home/isen/essai.php:7
Stack trace:
#0 /home/isen/essai.php(7): DateTime->__construct('second day of p...')
#1 {main}
  thrown in /home/isen/essai.php on line 7

Fatal error: Uncaught exception 'Exception' with message 
'DateTime::__construct(): Failed to parse time string (second day of previous 
month) at position 11 (o): The timezone could not be found in the database' in 
/home/isen/essai.php:7
Stack trace:
#0 /home/isen/essai.php(7): DateTime->__construct('second day of p...')
#1 {main}
  thrown in /home/isen/essai.php on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-11 15:47 UTC] zhanglijiu at gmail dot com
There is no parameter 'second,third day of previous month'.
 [2012-05-11 16:38 UTC] derick@php.net
-Package: Date/time related +Package: *General Issues
 [2012-05-11 16:38 UTC] derick@php.net
This is just not implemented. For you now, you'll have to do:

$firstDay = new DateTime('first day of previous month');
$firstDay->modify( 'next day' );
 [2016-06-14 11:41 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request -Package: *General Issues +Package: Date/time related
 [2016-06-14 11:41 UTC] cmb@php.net
> This is just not implemented.

So I'm changing to feature request.
 [2017-01-13 07:03 UTC] heiglandreas@php.net
-Assigned To: +Assigned To: heiglandreas
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC