Bug->Req #71802 [Opn]: strtotime parses "13:01 PM" as 16:01

From: Date: Sat, 12 Mar 2016 04:52:40 +0000
Subject: Bug->Req #71802 [Opn]: strtotime parses "13:01 PM" as 16:01
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199773@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71802&edit=1 ID: 71802 Updated by: requinix@php.net Reported by: php at richardneill dot org Summary: strtotime parses "13:01 PM" as 16:01 Status: Open -Type: Bug +Type: Feature/Change Request Package: Date/time related Operating System: Linux PHP Version: 5.6.19 Block user comment: N Private report: N New Comment: https://3v4l.org/2beus Since "13:01 PM" isn't valid as time with meridian, the other behavior is to parse the P as a timezone (military style where P=UTC-3). The M is a timezone too but ignored. As a request, though, this doesn't sound unreasonable: allow an AM/PM after any time specification, and warn or ignore if H>12. For a workaround you could use date_parse() then check if hour>12 and tz_addr={A,P}. It'd be work to construct a timestamp on your own from there, so maybe if you detect this problem you could try a regex to remove /[AaPp]\.?[Mm]\.?/ from the input. Previous Comments: ------------------------------------------------------------------------ [2016-03-11 17:15:00] php at richardneill dot org Description: ------------ The time expression "13:01 P.M." is technically malformed (it's tautologous), but people are still likely to use it sometimes. PHP mis-converts it, turning 13 into 16 !. (In comparison, the Unix date command rejects it) Test script: --------------- PHP: <? echo date ("Y-m-d H:i:s", strtotime("13:01 P.M.")); #result: 2016-03-11 16:01:00 #expected: 2016-03-11 13:01:00 echo date ("Y-m-d H:i:s", strtotime("12:01 P.M.")); #result: 2016-03-11 12:01:00 #correct ?> Shell: $ date -d '13:01 P.M.'; date: invalid date ‘13:01 P.M.’ $ date -d '12:01 P.M.'; Fri Mar 11 12:01:00 GMT 2016 Expected result: ---------------- PHP shouldn't be off-by-3. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71802&edit=1

« previous php.bugs (#199773) next »