phpcakephpcakephp-4.x

FrozenDate::parseDate doesn't work with September


Is there a reason why FrozenDate::parseDate, called with the month of September (ex. Sep), the date doesn't get parsed?

Code:

$months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

foreach($months as $m)
{
    $d = "01-".$m."-23";
    debug($d);
    $fd = FrozenDate::parseDate($d, "dd-MMM-yy");
    debug($fd);
}


APP/Controller\AdministratorsController.php (line 202)
'01-Sep-23'
APP/Controller\AdministratorsController.php (line 204)
null

Edit #1

Tried outputting any errors using getLastErrors(). Nothing there either.

debug(FrozenDate::getLastErrors());

APP/Controller\AdministratorsController.php (line 205)
[
'warning_count' => (int) 0,
'warnings' => [ ],
'error_count' => (int) 0,
'errors' => [ ],
]

Edit #2

Seems using "Sept" works. Noting that I'm importing from Excel and the format given is "Sep" and not "Sept". And, the date "01-Sept-23" converts to "01-Sep-2023" in Excel for some reason.

$months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];

foreach($months as $m)
{
    $d = "01-".$m."-23";
    debug($d);
    $fd = FrozenDate::parseDate($d, "dd-MMM-yy");
    debug($fd);
}

Solution

Set a locale prior to calling the parseDate() function.

FrozenDate::setDefaultLocale("en_US");//en_CA doesn't work

Solution

  • CLDR/ICU problem, in newer versions (not sure about the latest, can't test it right now), for certain locales either Sept was introduced, or Sep was removed, or vice versa, or some combination or whatever. It's not clear to me from any of the comments, and I really don't feel like wasting hours to investigate it.

    tl;dr, classic CLDR/ICU L. Better get used to it, stuff like this happens regularly.