php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch php-datetime-bug54851.diff-v2 for Date/time related Bug #54851Patch version 2011-05-20 09:02 UTC Return to Bug #54851 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: mats.lindh@gmail.comIndex: ext/date/tests/bug54851.phpt =================================================================== --- ext/date/tests/bug54851.phpt (revision 0) +++ ext/date/tests/bug54851.phpt (revision 0) @@ -0,0 +1,28 @@ +--TEST-- +Bug #54851 (DateTime::createFromFormat() uses today for "D") +--INI-- +date.timezone=UTC +--FILE-- +<?php +$date = new \DateTime("2008-07-08T22:14:12+02:00"); +$date2 = \DateTime::createFromFormat("D", $date->format("D")); + +var_dump($date->format("D") == $date2->format("D")); + +// Test entries with wrong day/date and that the behaviour is consistent with the constructor and strtotime. +// Verify that our implementation works regardless of position +$datePre = \DateTime::createFromFormat("D d M Y", "Fri 17 may 2011"); +$datePost = \DateTime::createFromFormat("d M Y D", "17 may 2011 Fri"); +var_dump($datePre->format("Y-m-d") == $datePost->format("Y-m-d")); + +// Verify that our implementation is the same as for the constructor and strtotime +$dateConstructor = new \DateTime("17 may 2011 Fri"); +var_dump($dateConstructor->format("Y-m-d") == $datePre->format("Y-m-d")); + +$dateStrToTime = new \DateTime('@' . (strtotime("17 may 2011 Fri") + 100)); +var_dump($dateStrToTime->format("Y-m-d") == $datePre->format("Y-m-d")); +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) Index: ext/date/lib/parse_date.re =================================================================== --- ext/date/lib/parse_date.re (revision 311245) +++ ext/date/lib/parse_date.re (working copy) @@ -1854,6 +1854,7 @@ char *ptr = string; char *begin; timelib_sll tmp; + const timelib_relunit* tmprelunit = 0; Scanner in; Scanner *s = ∈ int allow_extra = 0; @@ -1885,9 +1886,15 @@ switch (*fptr) { case 'D': /* three letter day */ case 'l': /* full day */ - if (!timelib_lookup_relunit((char **) &ptr)) { + tmprelunit = timelib_lookup_relunit((char**) &ptr); + if (!tmprelunit) { add_pbf_error(s, "A textual day could not be found", string, begin); + break; } + in.time->have_relative = 1; + in.time->relative.have_weekday_relative = 1; + in.time->relative.weekday = tmprelunit->multiplier; + in.time->relative.weekday_behavior = 1; break; case 'd': /* two digit day, with leading zero */ case 'j': /* two digit day, without leading zero */ |
Copyright © 2001-2025 The PHP Group All rights reserved. |
Last updated: Fri Jan 31 01:01:29 2025 UTC |