First of all: I know that I can manually create a bunch of config files with corresponding patterns for every locale; actually I try to find a workaround with using only IntlDateFormatter.
I'll try to explain with examples.
<?php
$tz = new DateTimeZone('Europe/Moscow');
$now = time();
foreach (['en_US', 'ja_JA', 'ru_RU'] as $locale) {
printf("%s:
", $locale);
foreach ([IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG] as $datetype) {
$formatter = new IntlDateFormatter($locale, $datetype, IntlDateFormatter::NONE);
printf("- %s
", $formatter->format($now));
}
}
This produces
en_US:
- Feb 1, 2016
- February 1, 2016
ja_JA:
- 2016/02/01
- 2016年2月1日
ru_RU:
- 1 февр. 2016 г.
- 1 февраля 2016 г.
And I need
en_US:
- Feb 1
- February 1
ja_JA:
- 02/01
- 2月1日
ru_RU:
- 1 февр.
- 1 февраля
The first idea was to extract a pattern for given locale and remove any 'y' and 'Y' letters. But as you can see, there is more than just a 4-digit year: all that commas, slashes, labels (like 'г.' and '年').
PS:
Actually, what I want from an ideal IntlDateFormatter
implementation is a smart pattern, where all components are in their places, but I can configure what pattern to use for each component. Like: instead of 'd MMMM y г.'
pattern for ru_RU
formatter has a 'dmy'
pattern, and for d
component it has d
pattern, m
- MMMM
and y
- y г.
. So I could say y
component is a '' (empty string), and voila.
Also, if you are aware of any library that already does this — please, let me know.