Cdatetimeparser::parse - Problem When "day" Not Present

There is a problem with CDateTimeParser::parse method. I’m not sure if this can be called bug, but there is no such problem with e.g. native PHP functions such as strtotime or date_create_from_format.

Assumptions:

  • Current time is 2014-01-31 12:00:00

  • We would like to parse string "2013-02" to get timestamp

What we do is


CDateTimeParser::parse('2013-02', 'yyyy-MM')

and expected result is some integer value. However it returns null.

This is because CDateTimeParser::parse uses current day as default one. So in above example date is converted into 2013-02-31 before parsing. But obviously 31st of February is not a valid date. Thus CTimestamp::isValidDate($year,$month,$day) from line 257 returns false and the whole methods returns null.

The bypass for this is to use method as follows:


CDateTimeParser::parse('2013-02', 'yyyy-MM', array('day' => 1))

However it’s not the way like native PHP functions behave.

What is your opinion about this?

Regards,

KS