-
-
Save manojiksula/f5798f4e78d4683b507e0b848df58fc7 to your computer and use it in GitHub Desktop.
Forcing four-digit years on IntlDateFormatter::SHORT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$d = new DateTime("2012-10-11"); | |
function unalteredFormat($date, $locale) { | |
$fmt = new IntlDateFormatter( | |
$locale, | |
IntlDateFormatter::SHORT, | |
IntlDateFormatter::NONE); | |
$fmtted = $fmt->format($date); | |
echo "$locale: $fmtted\n"; | |
} | |
function modifiedFormat($date, $locale) { | |
$fmt = new IntlDateFormatter( | |
$locale, | |
IntlDateFormatter::SHORT, | |
IntlDateFormatter::NONE); | |
$pattern = $fmt->getPattern(); | |
$pattern = preg_replace( | |
'/(?<!y)yy(?!y)/', | |
'yyyy', | |
$pattern); | |
$fmt->setPattern($pattern); | |
$fmtted = $fmt->format($date); | |
echo "$locale: $fmtted\n"; | |
} | |
$locales = array( | |
'en_US', | |
'en_GB', | |
'de_DE', | |
'fr_FR', | |
'ru_RU', | |
'en_ZW', | |
'ps_AF', | |
); | |
echo "-- Unaltered format --\n"; | |
foreach ($locales as $locale) { | |
unalteredFormat($d, $locale); | |
} | |
echo "\n"; | |
echo "-- Modified format --\n"; | |
foreach ($locales as $locale) { | |
modifiedFormat($d, $locale); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Unaltered format -- | |
en_US: 10/11/12 | |
en_GB: 11/10/2012 | |
de_DE: 11.10.12 | |
fr_FR: 11/10/2012 | |
ru_RU: 11.10.12 | |
en_ZW: 11/10/2012 | |
ps_AF: م. ۲۰۱۲/۱۰/۱۱ | |
-- Modified format -- | |
en_US: 10/11/2012 | |
en_GB: 11/10/2012 | |
de_DE: 11.10.2012 | |
fr_FR: 11/10/2012 | |
ru_RU: 11.10.2012 | |
en_ZW: 11/10/2012 | |
ps_AF: م. ۲۰۱۲/۱۰/۱۱ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment