# [PATCH] lenient datetime

- Thread: https://externals.io/message/50093
- Original archive: https://news-web.php.net/php.internals/50093
- Started by james.butler@edigitalresearch.com on 2010-11-03T20:33:04+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #50093 — james.butler@edigitalresearch.com — 2010-11-03T20:33:04+00:00

URL: https://externals.io/message/50093#50093

Like the idea,
Couple of questions...

What would happen if the string contained a matching pattern twice or me, which would be 'returned', also does this allow the rest of the string to be pretty much junk.

(haven't had time to test patch as miles from a computer) 

--
James Butler
Sent from my iPhone



> Hi!
> 
> As I previously noted, in DateTime module there's no way to make 
> DateTime format parser to parse the string if the string contains more 
> data that the format supplies - i.e. if you need 'Y-m-d' and you have 
> string '2010-11-02 12:30' - you can't make DateTime accept it without 
> pre-parsing. The attached patch adds format character '+' that 
> implements that - i.e., if you use format 'Y-m-d+' then the string 
> '2010-11-02 12:30' will be parsed successfully, as well as '2010-11-02' 
> and string with anything following the date.
> The character would make the format 'lenient' when used in any position 
> in the string, doesn't have to be at the end.
> 
> Any objections? If not, I'll add some unit tests and commit it.
> -- 
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
> -- 
> 
> 
> <lenient_date.diff

---

## #50096 — Stas Malyshev — 2010-11-03T21:46:02+00:00

URL: https://externals.io/message/50093#50096 · In reply to: #50093

Hi!

> What would happen if the string contained a matching pattern twice or
> me, which would be 'returned', also does this allow the rest of the
> string to be pretty much junk.

Yes, the rest of the string (i.e. everything after the format was
matched, while ignoring +) can be anything. I.e., as soon as the 
requirements of the format (like "Y-m-d") is satisfied, it doesn't 
matter what else the string has.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
