Bug #76624 [Opn]: date_create_from_format doesn't respect "T" Timezone format character
| From: | jalaj dot chhalotre at gmail dot com | Date: | Sat, 14 Jul 2018 20:43:14 +0000 |
| Subject: | Bug #76624 [Opn]: date_create_from_format doesn't respect "T" Timezone format character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216324@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76624&edit=1
ID: 76624
User updated by: jalaj dot chhalotre at gmail dot com
Reported by: jalaj dot chhalotre at gmail dot com
Summary: date_create_from_format doesn't respect "T" Timezone
format character
Status: Open
Type: Bug
Package: *General Issues
-Operating System: Ubuntu 0.16.04.1
+Operating System: Ubuntu 16.04.1
PHP Version: 7.0.30
Block user comment: N
Private report: N
New Comment:
Corrected OS (typo)
Previous Comments:
------------------------------------------------------------------------
[2018-07-14 20:39:49] jalaj dot chhalotre at gmail dot com
Description:
------------
When T timezone format character is used to specify timezone in date_create_from_format() function,
wrong time (with respect to epoch) is generated.
In test script attached, two different epoch times are generated if 'T' and 'e'
timezone format characters are used. However using e format character returns correct time.
Test script:
---------------
# date_string = "2018-07-13 15:30:15 IST" = "2018-07-13 15:30:15 Asia/Kolkata"
$date1 = new DateTime('2018-07-13 15:30:15', new DateTimeZone('Asia/Kolkata'));
echo $date1->format('Y-m-d H:i:s T');
//2018-07-13 15:30:15 IST
echo $str1=$date1->format('U');
//1531476015
$date2=date_create_from_format('Y-m-d H:i:s T', '2018-07-13 15:30:15 IST');
echo $str2=$date2->format('U');
//1531488615
/*
$str1 IS NOT equal to $str2
but date1=date2
*/
echo $date1->format('Y-m-d H:i:s e');
//2018-07-13 15:30:15 Asia/Kolkata
echo $str3=$date1->format('U');
//1531476015
$date2=date_create_from_format('Y-m-d H:i:s e', '2018-07-13 15:30:15
Asia/Kolkata');
echo $str4=$date2->format('U');
//1531476015
/*
$str3 IS equal to $str4
as date1=date3
*/
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76624&edit=1