view release on metacpan or search on metacpan
NAME
DateTime::Locale::FromCLDR - DateTime Localised Data from Unicode CLDR
SYNOPSIS
use DateTime::Locale::FromCLDR;
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP' ) ||
die( DateTime::Locale::FromCLDR->error );
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
my $array = $locale->am_pm_abbreviated;
my $array = $locale->available_formats;
$locale->calendar( 'hebrew' );
my $str = $locale->calendar;
# a Locale::Unicode object that stringifies to the initial locale value (ja-Kana-JP)
my $obj = $locale->code;
my $str = $locale->date_at_time_format_full;
my $str = $locale->date_at_time_format_long;
my $str = $locale->date_at_time_format_medium;
my $str = $locale->date_at_time_format_short;
my $str = $locale->date_format_default;
my $str = $locale->date_format_full;
my $str = $locale->date_format_long;
my $str = $locale->date_format_medium;
die( DateTime::Locale::FromCLDR->error );
# Okinawan as spoken in Japan Southern islands
my $locale = DateTime::Locale::FromCLDR->new( 'ryu-Kana-JP-t-de-t0-und-x0-medical' ) ||
die( DateTime::Locale::FromCLDR->error );
use Locale::Unicode;
my $loc = Locale::Unicode->new( 'fr-FR' );
my $locale = DateTime::Locale::FromCLDR->new( $loc ) ||
die( DateTime::Locale::FromCLDR->error );
Specifying a calendar ID other than the default "gregorian":
my $locale = DateTime::Locale::FromCLDR->new( 'ja-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
or, using an hash reference:
my $locale = DateTime::Locale::FromCLDR->new( 'ja-JP', { calendar => 'japanese' } ) ||
die( DateTime::Locale::FromCLDR->error );
Instantiate a new DateTime::Locale::FromCLDR object based on a "locale"
provided, and returns it. By default, it uses the calendar "gregorian",
but you can specify a different one with the "calendar" option.
You can provide any "locale", even complex one as shown above, and only
its core part will be retained. So, for example:
my $locale = DateTime::Locale::FromCLDR->new( 'ryu-Kana-JP-t-de-t0-und-x0-medical' ) ||
die( DateTime::Locale::FromCLDR->error );
say $locale; # ryu-Kana-JP
If an error occurs, it sets an exception object and returns "undef" in
scalar context, or an empty list in list context, or possibly a special
say @$ampm; # AM, PM
my $locale = DateTime::Locale::FromCLDR->new( 'ja' );
my $ampm = $locale->am_pm_abbreviated
say @$ampm; # åå, åå¾
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
my $ampm = $locale->am_pm_abbreviated
say @$ampm; # Empty
See "calendar_term" in Locale::Unicode::Data
am_pm_format_narrow
Same as am_pm_format_abbreviated, but returns the narrow format of the
AM/PM terms.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->am_pm_format_narrow;
am_pm_format_wide
Same as am_pm_format_abbreviated, but returns the wide format of the
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->am_pm_standalone_wide;
available_formats
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->available_formats;
Returns an array reference of all the format ID available for this
"locale"
See "calendar_available_format" in Locale::Unicode::Data
available_format_patterns
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $ref = $locale->available_format_patterns;
Returns an hash reference of all the available format ID to their
corresponding pattern for the "locale"
See "calendar_available_format" in Locale::Unicode::Data
calendar
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
my $str = $locale->calendar; # japanese
$locale->calendar( 'gregorian' );
Sets or gets the calendar ID used to perform queries along with the
given "locale"
code
my $obj = $locale->code;
Returns the Locale::Unicode object either received or created upon
object instantiation.
date_at_time_format_full
my $str = $locale->date_at_time_format_full;
date_format_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->date_format_full;
# EEEE, MMMM d, y
# Tuesday, July 23, 2024
Returns the full date pattern
<https://unicode.org/reports/tr35/tr35-dates.html#dateFormats>
See also "calendar_format_l10n" in Locale::Unicode::Data
date_format_long
Same as date_format_full, but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->date_format_long;
# MMMM d, y
# July 23, 2024
date_format_medium
datetime_format_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->datetime_format_full;
# EEEE, MMMM d, y, h:mm:ssâ¯a zzzz
# Tuesday, July 23, 2024, 1:53:27â¯AM UTC
Returns the full datetime pattern
<https://unicode.org/reports/tr35/tr35-dates.html#dateTimeFormats>
See also "calendar_datetime_format" in Locale::Unicode::Data
datetime_format_long
Same as datetime_format_full, but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->datetime_format_long;
# MMMM d, y, h:mm:ssâ¯a z
# July 23, 2024, 1:57:02â¯AM UTC
datetime_format_medium
day_format_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $days = $locale->day_format_abbreviated;
say @$days;
# Mon, Tue, Wed, Thu, Fri, Sat, Sun
Returns an array reference of week day names abbreviated format with
Monday first and Sunday last.
See also "calendar_term" in Locale::Unicode::Data
day_format_narrow
Same as day_format_abbreviated, but returns the narrow format days.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $days = $locale->day_format_abbreviated;
say @$days;
# M, T, W, T, F, S, S
day_format_short
Returns a string representing the localised expression of the period of
day the DateTime object provided is.
If nothing relevant could be found somehow, this will return an empty
string. "undef" is returned only if an error occurred.
This is used to provide the relevant value for the token "B" or "b" in
the Unicode LDML format patterns
See also "calendar_term" in Locale::Unicode::Data, "day_period" in
Locale::Unicode::Data and DateTime::Format::Unicode
day_period_format_narrow
Same as day_period_format_abbreviated, but returns the narrow format of
day period.
my $dt = DateTime->new( year => 2024, hour => 7 );
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->day_period_format_narrow( $dt );
# in the morning
Returns a string representing the localised expression of the period of
day the DateTime object provided is.
If nothing relevant could be found somehow, this will return an empty
string. "undef" is returned only if an error occurred.
This is used to provide a stand-alone word that can be used as a title,
or in a different context.
See also "calendar_term" in Locale::Unicode::Data, "day_period" in
Locale::Unicode::Data and DateTime::Format::Unicode
day_period_stand_alone_narrow
Same as day_period_stand_alone_abbreviated, but returns the narrow
stand-alone version of the day period.
my $dt = DateTime->new( year => 2024, hour => 13 );
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_stand_alone_narrow( $dt );
# ap.m.
default_time_format_length
This returns the string "medium"
era_abbreviated
my $array = $locale->era_abbreviated;
say @$array;
# BC, AD
Returns an array reference of era names in abbreviated format.
See also "calendar_eras_l10n" in Locale::Unicode::Data
era_narrow
Same as era_abbreviated, but returns the narrow format eras.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->era_narrow;
say @$array;
# B, A
era_wide
localised pattern "h:mm B". However, DateTime does not understand the
token "B"
my $now = DateTime->now( locale => "en", time_zone => "Asia/Tokyo" );
# Assuming $now = 2024-07-23T21:39:39
say $now->format_cldr( 'h:mm B' );
# 9:39 B
But "B" is the day period, which can be looked up with "day_period" in
Locale::Unicode::Data, which provides us with the day period token
"night1", which itself can be looked up with "calendar_term" in
Locale::Unicode::Data and gives us the localised string "at night". Thus
the proper "CLDR" formatting really should be "9:39 at night"
You can use DateTime::Format::Unicode instead of the default DateTime
"CLDR" formatting if you want to get better support for all CLDR pattern
tokens.
With Japanese:
my $locale = DateTime::Locale::FromCLDR->new( 'ja' );
# my $diff = $locale->interval_greatest_diff( $dt1, $dt2, { day_period_first => 1 } );
Provided with 2 DateTime objects, and this will compute the greatest
difference
<https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats>.
Quoting from the LDML specifications
<https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats>:
"The data supplied in CLDR requires the software to determine the
calendar field with the greatest difference before using the format
pattern. For example, the greatest difference in "Jan 10-12, 2008" is
the day field, while the greatest difference in "Jan 10 - Feb 12, 2008"
is the month field. This is used to pick the exact pattern."
If both "DateTime" objects are identical, this will return an empty
string.
You can alter the inner working of the algorithm by providing the option
"day_period_first" with a true value. This will prioritise the day
period over the AM/PM (morning vs afternoon). What this means, is that
month_format_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_format_abbreviated;
say @$array;
# Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Returns an array reference of month names in abbreviated format from
January to December.
See also "calendar_term" in Locale::Unicode::Data
month_format_narrow
Same as month_format_abbreviated, but returns the months in narrow
format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_format_narrow;
say @$array;
# J, F, M, A, M, J, J, A, S, O, N, D
month_stand_alone_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_stand_alone_abbreviated;
say @$array;
# Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Returns an array reference of month names in abbreviated stand-alone
format from January to December.
See also "calendar_term" in Locale::Unicode::Data
Note that there is often little difference between the "format" and
"stand-alone" format types.
See the LDML specifications
<https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_e
ras> for more information on the difference between the "format" and
"stand-alone" types.
month_stand_alone_narrow
above in timeFormats."
quarter_format_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_format_abbreviated;
say @$array;
# Q1, Q2, Q3, Q4
Returns an array reference of quarter names in abbreviated format.
See also "calendar_term" in Locale::Unicode::Data
quarter_format_narrow
Same as quarter_format_abbreviated, but returns the quarters in narrow
format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_format_narrow;
say @$array;
# 1, 2, 3, 4
# 1st quarter, 2nd quarter, 3rd quarter, 4th quarter
quarter_stand_alone_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_stand_alone_abbreviated;
say @$array;
# Q1, Q2, Q3, Q4
Returns an array reference of quarter names in abbreviated format.
See also "calendar_term" in Locale::Unicode::Data
Note that there is often little difference between the "format" and
"stand-alone" format types.
See the LDML specifications
<https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_e
ras> for more information on the difference between the "format" and
"stand-alone" types.
quarter_stand_alone_narrow
territory_id
This is an alias for territory_code
territory_info
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $ref = $locale->territory_info;
which would yield:
{
calendars => undef,
contains => undef,
currency => "USD",
first_day => 7,
gdp => 19490000000000,
languages => [qw(
en es zh-Hant fr de fil it vi ko ru nv yi pdc hnj haw
frc chr esu dak cho lkt ik mus io cic cad jbo osa zh
)],
literacy_percent => 99,
min_days => 1,
territory_id => 297,
weekend => undef,
}
my $locale = DateTime::Locale::FromCLDR->new( 'en-GB' );
my $ref = $locale->territory_info;
which would yield:
{
calendars => undef,
contains => undef,
currency => "GBP",
first_day => 1,
gdp => 2925000000000,
languages => [qw(
en fr de es pl pa ur ta gu sco cy bn ar zh-Hant it lt pt
so tr ga gd kw en-Shaw
)],
literacy_percent => 99,
min_days => 4,
territory_id => 121,
weekend => undef,
}
Returns an hash reference of information related to the ISO3166 country
code associated with the "locale". If the "locale" has no country code
associated, it will expand it using the Unicode LDML rule with
"likely_subtag" in Locale::Unicode::Data
Keep in mind that the default or fallback data are stored in the special
territory code 001 (World). Thus, for example, if the "calendars" field
is empty, the default value would be in 001, and would be
"["gregorian"]"
time_format_allowed
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->time_format_allowed;
Returns an array reference of allowed time patterns
<https://unicode.org/reports/tr35/tr35-dates.html#Time_Data> for the
"locale"'s associated territory. If the locale has no "territory"
time_format_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->time_format_full;
# h:mm:ssâ¯a zzzz
# 10:44:07â¯PM UTC
Returns the full date pattern
<https://unicode.org/reports/tr35/tr35-dates.html#dateFormats>
See also "calendar_format_l10n" in Locale::Unicode::Data
time_format_long
Same as time_format_full, but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->time_format_long;
# h:mm:ssâ¯a z
# 10:44:07â¯PM UTC
time_format_medium
# NAME
DateTime::Locale::FromCLDR - DateTime Localised Data from Unicode CLDR
# SYNOPSIS
use DateTime::Locale::FromCLDR;
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP' ) ||
die( DateTime::Locale::FromCLDR->error );
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
my $array = $locale->am_pm_abbreviated;
my $array = $locale->available_formats;
$locale->calendar( 'hebrew' );
my $str = $locale->calendar;
# a Locale::Unicode object that stringifies to the initial locale value (ja-Kana-JP)
my $obj = $locale->code;
my $str = $locale->date_at_time_format_full;
my $str = $locale->date_at_time_format_long;
my $str = $locale->date_at_time_format_medium;
my $str = $locale->date_at_time_format_short;
my $str = $locale->date_format_default;
my $str = $locale->date_format_full;
my $str = $locale->date_format_long;
my $str = $locale->date_format_medium;
die( DateTime::Locale::FromCLDR->error );
# Okinawan as spoken in Japan Southern islands
my $locale = DateTime::Locale::FromCLDR->new( 'ryu-Kana-JP-t-de-t0-und-x0-medical' ) ||
die( DateTime::Locale::FromCLDR->error );
use Locale::Unicode;
my $loc = Locale::Unicode->new( 'fr-FR' );
my $locale = DateTime::Locale::FromCLDR->new( $loc ) ||
die( DateTime::Locale::FromCLDR->error );
Specifying a calendar ID other than the default `gregorian`:
my $locale = DateTime::Locale::FromCLDR->new( 'ja-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
or, using an hash reference:
my $locale = DateTime::Locale::FromCLDR->new( 'ja-JP', { calendar => 'japanese' } ) ||
die( DateTime::Locale::FromCLDR->error );
Instantiate a new [DateTime::Locale::FromCLDR](https://metacpan.org/pod/DateTime%3A%3ALocale%3A%3AFromCLDR) object based on a `locale` provided, and returns it. By default, it uses the calendar `gregorian`, but you can specify a different one with th...
You can provide any `locale`, even complex one as shown above, and only its core part will be retained. So, for example:
my $locale = DateTime::Locale::FromCLDR->new( 'ryu-Kana-JP-t-de-t0-und-x0-medical' ) ||
die( DateTime::Locale::FromCLDR->error );
say $locale; # ryu-Kana-JP
If an error occurs, it sets an [exception object](https://metacpan.org/pod/DateTime%3A%3ALocale%3A%3AFromCLDR%3A%3AException) and returns `undef` in scalar context, or an empty list in list context, or possibly a special `DateTime::Locale::FromCLDR::...
The object is overloaded and stringifies into the core part of the original string provided upon instantiation.
say @$ampm; # AM, PM
my $locale = DateTime::Locale::FromCLDR->new( 'ja' );
my $ampm = $locale->am_pm_abbreviated
say @$ampm; # åå, åå¾
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
my $ampm = $locale->am_pm_abbreviated
say @$ampm; # Empty
See ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term)
## am\_pm\_format\_narrow
Same as [am\_pm\_format\_abbreviated](#am_pm_format_abbreviated), but returns the narrow format of the AM/PM terms.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->am_pm_format_narrow;
## am\_pm\_format\_wide
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->am_pm_standalone_wide;
## available\_formats
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->available_formats;
Returns an array reference of all the format ID available for this `locale`
See ["calendar\_available\_format" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_available_format)
## available\_format\_patterns
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $ref = $locale->available_format_patterns;
Returns an hash reference of all the available format ID to their corresponding pattern for the `locale`
See ["calendar\_available\_format" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_available_format)
## calendar
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
my $str = $locale->calendar; # japanese
$locale->calendar( 'gregorian' );
Sets or gets the [calendar ID](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar) used to perform queries along with the given `locale`
## code
my $obj = $locale->code;
Returns the [Locale::Unicode](https://metacpan.org/pod/Locale%3A%3AUnicode) object either received or created upon object instantiation.
## date\_at\_time\_format\_full
my $str = $locale->date_at_time_format_full;
## date\_format\_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->date_format_full;
# EEEE, MMMM d, y
# Tuesday, July 23, 2024
Returns the [full date pattern](https://unicode.org/reports/tr35/tr35-dates.html#dateFormats)
See also ["calendar\_format\_l10n" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_format_l10n)
## date\_format\_long
Same as [date\_format\_full](#date_format_full), but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->date_format_long;
# MMMM d, y
# July 23, 2024
## datetime\_format\_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->datetime_format_full;
# EEEE, MMMM d, y, h:mm:ssâ¯a zzzz
# Tuesday, July 23, 2024, 1:53:27â¯AM UTC
Returns the [full datetime pattern](https://unicode.org/reports/tr35/tr35-dates.html#dateTimeFormats)
See also ["calendar\_datetime\_format" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_datetime_format)
## datetime\_format\_long
Same as [datetime\_format\_full](#datetime_format_full), but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->datetime_format_long;
# MMMM d, y, h:mm:ssâ¯a z
# July 23, 2024, 1:57:02â¯AM UTC
## day\_format\_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $days = $locale->day_format_abbreviated;
say @$days;
# Mon, Tue, Wed, Thu, Fri, Sat, Sun
Returns an array reference of week day names abbreviated format with Monday first and Sunday last.
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term)
## day\_format\_narrow
Same as [day\_format\_abbreviated](#day_format_abbreviated), but returns the narrow format days.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $days = $locale->day_format_abbreviated;
say @$days;
# M, T, W, T, F, S, S
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_format_abbreviated( $dt );
# après-midi
Returns a string representing the localised expression of the period of day the [DateTime](https://metacpan.org/pod/DateTime) object provided is.
If nothing relevant could be found somehow, this will return an empty string. `undef` is returned only if an error occurred.
This is used to provide the relevant value for the token `B` or `b` in the [Unicode LDML format patterns](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#Format-Patterns)
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term), ["day\_period" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#day_period) and [DateTime::For...
## day\_period\_format\_narrow
Same as [day\_period\_format\_abbreviated](#day_period_format_abbreviated), but returns the narrow format of day period.
my $dt = DateTime->new( year => 2024, hour => 7 );
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->day_period_format_narrow( $dt );
# in the morning
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_stand_alone_abbreviated( $dt );
# ap.m.
Returns a string representing the localised expression of the period of day the [DateTime](https://metacpan.org/pod/DateTime) object provided is.
If nothing relevant could be found somehow, this will return an empty string. `undef` is returned only if an error occurred.
This is used to provide a stand-alone word that can be used as a title, or in a different context.
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term), ["day\_period" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#day_period) and [DateTime::For...
## day\_period\_stand\_alone\_narrow
Same as [day\_period\_stand\_alone\_abbreviated](#day_period_stand_alone_abbreviated), but returns the narrow stand-alone version of the day period.
my $dt = DateTime->new( year => 2024, hour => 13 );
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_stand_alone_narrow( $dt );
# ap.m.
This returns the string `medium`
## era\_abbreviated
my $array = $locale->era_abbreviated;
say @$array;
# BC, AD
Returns an array reference of era names in abbreviated format.
See also ["calendar\_eras\_l10n" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_eras_l10n)
## era\_narrow
Same as [era\_abbreviated](#era_abbreviated), but returns the narrow format eras.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->era_narrow;
say @$array;
# B, A
Provided with the format ID of an [available format](#available_formats) and this will return the localised `CLDR` pattern.
Keep in mind that the `CLDR` formatting method of [DateTime](https://metacpan.org/pod/DateTime#format_cldr) does not recognise all the `CLDR` pattern tokens. Thus, for example, if you chose the standard available pattern `Bhm`, this method would retu...
my $now = DateTime->now( locale => "en", time_zone => "Asia/Tokyo" );
# Assuming $now = 2024-07-23T21:39:39
say $now->format_cldr( 'h:mm B' );
# 9:39 B
But `B` is the day period, which can be looked up with ["day\_period" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#day_period), which provides us with the day period token `night1`, which itself can be looked up wi...
You can use [DateTime::Format::Unicode](https://metacpan.org/pod/DateTime%3A%3AFormat%3A%3AUnicode) instead of the default [DateTime](https://metacpan.org/pod/DateTime) `CLDR` formatting if you want to get better support for all [CLDR pattern tokens]...
With Japanese:
my $locale = DateTime::Locale::FromCLDR->new( 'ja' );
my $pattern = $locale->format_for( 'Bhm' );
# BK:mm
my $now = DateTime->now( locale => "ja", time_zone => "Asia/Tokyo" );
say $now->format_cldr( 'BK:mm' );
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $diff = $locale->interval_greatest_diff( $dt1, $dt2, day_period_first => 1 );
# or, using an hash reference instead:
# my $diff = $locale->interval_greatest_diff( $dt1, $dt2, { day_period_first => 1 } );
Provided with 2 [DateTime objects](https://metacpan.org/pod/DateTime), and this will compute the [greatest difference](https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats).
Quoting from the [LDML specifications](https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats):
"The data supplied in CLDR requires the software to determine the calendar field with the greatest difference before using the format pattern. For example, the greatest difference in "Jan 10-12, 2008" is the day field, while the greatest difference i...
If both `DateTime` objects are identical, this will return an empty string.
You can alter the inner working of the algorithm by providing the option `day_period_first` with a true value. This will prioritise the day period over the AM/PM (morning vs afternoon). What this means, is that if you have two datetimes, one with an ...
This is important, because of the way almost all, but 4 locales (`bg`, `id`, `uz` and `zu`), have sliced up their day periods.
For the locale `en`, for example, the day periods are:
- `midnight`
## month\_format\_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_format_abbreviated;
say @$array;
# Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Returns an array reference of month names in abbreviated format from January to December.
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term)
## month\_format\_narrow
Same as [month\_format\_abbreviated](#month_format_abbreviated), but returns the months in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_format_narrow;
say @$array;
# J, F, M, A, M, J, J, A, S, O, N, D
## month\_stand\_alone\_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_stand_alone_abbreviated;
say @$array;
# Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Returns an array reference of month names in abbreviated stand-alone format from January to December.
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term)
Note that there is often little difference between the `format` and `stand-alone` format types.
See the [LDML specifications](https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_eras) for more information on the difference between the `format` and `stand-alone` types.
## month\_stand\_alone\_narrow
Same as [month\_stand\_alone\_abbreviated](#month_stand_alone_abbreviated), but returns the months in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
## quarter\_format\_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_format_abbreviated;
say @$array;
# Q1, Q2, Q3, Q4
Returns an array reference of quarter names in abbreviated format.
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term)
## quarter\_format\_narrow
Same as [quarter\_format\_abbreviated](#quarter_format_abbreviated), but returns the quarters in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_format_narrow;
say @$array;
# 1, 2, 3, 4
## quarter\_stand\_alone\_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_stand_alone_abbreviated;
say @$array;
# Q1, Q2, Q3, Q4
Returns an array reference of quarter names in abbreviated format.
See also ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term)
Note that there is often little difference between the `format` and `stand-alone` format types.
See the [LDML specifications](https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_eras) for more information on the difference between the `format` and `stand-alone` types.
## quarter\_stand\_alone\_narrow
Same as [quarter\_stand\_alone\_abbreviated](#quarter_stand_alone_abbreviated), but returns the quarters in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
This is an alias for [territory\_code](#territory_code)
## territory\_info
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $ref = $locale->territory_info;
which would yield:
{
calendars => undef,
contains => undef,
currency => "USD",
first_day => 7,
gdp => 19490000000000,
languages => [qw(
en es zh-Hant fr de fil it vi ko ru nv yi pdc hnj haw
frc chr esu dak cho lkt ik mus io cic cad jbo osa zh
)],
literacy_percent => 99,
min_days => 1,
territory_id => 297,
weekend => undef,
}
my $locale = DateTime::Locale::FromCLDR->new( 'en-GB' );
my $ref = $locale->territory_info;
which would yield:
{
calendars => undef,
contains => undef,
currency => "GBP",
first_day => 1,
gdp => 2925000000000,
languages => [qw(
en fr de es pl pa ur ta gu sco cy bn ar zh-Hant it lt pt
so tr ga gd kw en-Shaw
)],
literacy_percent => 99,
min_days => 4,
parent => 154,
population => 65761100,
status => "regular",
territory => "GB",
territory_id => 121,
weekend => undef,
}
Returns an hash reference of information related to the ISO3166 country code associated with the `locale`. If the `locale` has no country code associated, it will expand it using the Unicode LDML rule with ["likely\_subtag" in Locale::Unicode::Data](...
Keep in mind that the default or fallback data are stored in the special territory code `001` (World). Thus, for example, if the `calendars` field is empty, the default value would be in `001`, and would be `["gregorian"]`
## time\_format\_allowed
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->time_format_allowed;
Returns an array reference of [allowed time patterns](https://unicode.org/reports/tr35/tr35-dates.html#Time_Data) for the `locale`'s associated territory. If the locale has no `territory` associated with, it will check the [likely subtag](https://met...
## time\_format\_default
## time\_format\_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->time_format_full;
# h:mm:ssâ¯a zzzz
# 10:44:07â¯PM UTC
Returns the [full date pattern](https://unicode.org/reports/tr35/tr35-dates.html#dateFormats)
See also ["calendar\_format\_l10n" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_format_l10n)
## time\_format\_long
Same as [time\_format\_full](#time_format_full), but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->time_format_long;
# h:mm:ssâ¯a z
# 10:44:07â¯PM UTC
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
our $EMPTY_SET = "â
â
â
";
our $VERSION = 'v0.8.0';
};
use strict;
use warnings;
sub new
{
my $this = shift( @_ );
my $self = bless( { calendar => 'gregorian' } => ( ref( $this ) || $this ) );
my $locale = shift( @_ ) ||
return( $self->error( "No locale was provided." ) );
$locale = $self->_locale_object( $locale ) ||
return( $self->pass_error );
my $core = $locale->core;
unless( $core eq $locale )
{
$locale = Locale::Unicode->new( $core ) ||
return( $self->pass_error( Locale::Unicode->error ) );
}
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
}
elsif( !defined( $meth->( $self, $val ) ) )
{
if( defined( $val ) && $self->error )
{
return( $self->pass_error );
}
}
}
$self->{locale} = $locale;
$self->{calendar} //= 'gregorian';
$self->{_cldr} = Locale::Unicode::Data->new ||
return( $self->pass_error( Locale::Unicode::Data->error ) );
return( $self );
}
sub am_pm_abbreviated { return( shift->am_pm_format_abbreviated( @_ ) ); }
sub am_pm_format_abbreviated { return( shift->_am_pm(
context => [qw( format stand-alone )],
width => [qw( abbreviated wide )],
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
sub available_formats
{
my $self = shift( @_ );
my $ref;
unless( defined( $ref = $self->{available_formats} ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone!" );
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $calendar = $self->{calendar} || 'gregorian';
foreach my $loc ( @$tree )
{
my $all = $cldr->calendar_available_formats(
locale => $loc,
calendar => $calendar,
alt => undef,
# count might contain some value
);
return( $self->pass_error ) if( !defined( $all ) && $cldr->error );
if( $all && scalar( @$all ) )
{
# Make sure we have unique keys
my $uniq = sub
{
my %seen;
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
sub available_format_patterns
{
my $self = shift( @_ );
my $ref;
unless( defined( $ref = $self->{available_format_patterns} ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone!" );
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $calendar = $self->{calendar} || 'gregorian';
foreach my $loc ( @$tree )
{
my $all = $cldr->calendar_available_formats(
locale => $loc,
calendar => $calendar,
alt => undef,
# count might contain some value
);
return( $self->pass_error ) if( !defined( $all ) && $cldr->error );
if( $all && scalar( @$all ) )
{
$ref = +{ map{ $_->{format_id} => $_->{format_pattern} } @$all };
last;
}
}
$self->{available_format_patterns} = $ref;
}
return( $ref );
}
sub calendar
{
my $self = shift( @_ );
if( @_ )
{
my $cal_id = shift( @_ );
if( defined( $cal_id ) )
{
if( $cal_id !~ /^[a-zA-Z][a-zA-Z0-9]+(\-[a-zA-Z][a-zA-Z0-9]+)*$/ )
{
return( $self->error( "Calendar ID provided (", ( $cal_id // 'undef' ), ") is invalid." ) );
}
$cal_id = lc( $cal_id );
}
$self->{calendar} = $cal_id;
}
return( $self->{calendar} );
}
sub code { return( shift->{locale} ); }
sub date_at_time_format_full { return( shift->_datetime_format(
type => 'atTime',
width => 'full',
) ); }
sub date_at_time_format_long { return( shift->_datetime_format(
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
sub datetime_format_medium { return( shift->_datetime_format(
type => 'standard',
width => 'medium',
) ); }
sub datetime_format_short { return( shift->_datetime_format(
type => 'standard',
width => 'short',
) ); }
sub day_format_abbreviated { return( shift->_calendar_terms(
id => 'day_format_abbreviated',
type => 'day',
context => [qw( format stand-alone )],
width => [qw( abbreviated wide )],
) ); }
sub day_format_narrow { return( shift->_calendar_terms(
id => 'day_format_narrow',
type => 'day',
context => [qw( format stand-alone )],
width => [qw( narrow short abbreviated wide )],
) ); }
# NOTE: day short exists in CLDR, but is left out in DateTime::Locale::FromData
sub day_format_short { return( shift->_calendar_terms(
id => 'day_format_short',
type => 'day',
context => [qw( format stand-alone )],
width => [qw( short narrow abbreviated )],
) ); }
sub day_format_wide { return( shift->_calendar_terms(
id => 'day_format_wide',
type => 'day',
context => [qw( format stand-alone )],
width => 'wide',
) ); }
sub day_period_format_abbreviated { return( shift->_day_period({
context => 'format',
width => 'abbreviated',
}, @_ ) ); }
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
{
$periods->{ $ref->{day_period} } = [@$ref{qw( start until )}];
}
last;
}
}
}
return( $periods );
}
sub day_stand_alone_abbreviated { return( shift->_calendar_terms(
id => 'day_stand_alone_abbreviated',
type => 'day',
context => [qw( stand-alone format )],
width => [qw( abbreviated wide )],
) ); }
sub day_stand_alone_narrow { return( shift->_calendar_terms(
id => 'day_stand_alone_narrow',
type => 'day',
context => [qw( stand-alone format )],
width => [qw( narrow wide )],
) ); }
# NOTE: day short exists in CLDR, but is left out in DateTime::Locale::FromData
sub day_stand_alone_short { return( shift->_calendar_terms(
id => 'day_stand_alone_short',
type => 'day',
context => [qw( stand-alone format )],
width => [qw( short abbreviated )],
) ); }
sub day_stand_alone_wide { return( shift->_calendar_terms(
id => 'day_stand_alone_wide',
type => 'day',
context => [qw( stand-alone format )],
width => 'wide',
) ); }
sub default_date_format_length { return( shift->{default_date_format_length} ); }
sub default_time_format_length { return( shift->{default_time_format_length} ); }
sub era_abbreviated { return( shift->_calendar_eras(
id => 'era_abbreviated',
width => [qw( abbreviated wide )],
alt => undef,
) ); }
sub era_narrow { return( shift->_calendar_eras(
id => 'era_narrow',
width => [qw( narrow abbreviated wide )],
alt => undef,
) ); }
sub era_wide { return( shift->_calendar_eras(
id => 'era_wide',
width => [qw( wide abbreviated )],
alt => undef,
) ); }
sub error
{
my $self = shift( @_ );
if( @_ )
{
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
return( $self->error( "Invalid interval format ID provided." ) );
}
elsif( $greatest_diff !~ /^[a-zA-Z]$/ )
{
return( $self->error( "Invalid greatest difference value provided (", overload::StrVal( $greatest_diff ), ")" ) );
}
$locale = $self->_locale_object( $locale ) ||
return( $self->pass_error );
my $cldr = $self->{_cldr} ||
return( $self->error( "Unable to get the Locale::Unicode::Data object!" ) );
my $calendar = $self->{calendar} || 'gregorian';
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $ref;
foreach my $loc ( @$tree )
{
$ref = $cldr->calendar_interval_format(
locale => $loc,
calendar => $calendar,
format_id => $id,
greatest_diff_id => ( lc( $greatest_diff ) eq 'h' ? [ uc( $greatest_diff ), lc( $greatest_diff )] : $greatest_diff ),
);
if( !defined( $ref ) && $cldr->error )
{
return( $self->pass_error( $cldr->error ) );
}
elsif( $ref )
{
last;
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
my $self = shift( @_ );
my $formats;
unless( defined( $formats = $self->{interval_formats} ) )
{
my $locale = $self->{locale} ||
return( $self->error( "No locale is set!" ) );
$locale = $self->_locale_object( $locale ) ||
return( $self->pass_error );
my $cldr = $self->{_cldr} ||
return( $self->error( "Unable to get the Locale::Unicode::Data object!" ) );
my $calendar = $self->{calendar} || 'gregorian';
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
foreach my $loc ( @$tree )
{
$formats = $cldr->interval_formats(
locale => $loc,
calendar => $calendar,
) || return( $self->pass_error( $cldr->error ) );
if( !defined( $formats ) && $cldr->error )
{
return( $self->pass_error( $cldr->error ) );
}
last if( $formats && scalar( keys( %$formats ) ) );
}
$formats //= {};
$self->{interval_formats} = $formats;
}
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
width => 'long',
}, @_ ) ); }
sub metazone_standard_short { return( shift->_metazone_name({
type => 'standard',
width => 'short',
}, @_ ) ); }
# NOTE: "if the abbreviated format data for Gregorian does not exist in a language X (in the chain up to root), then it inherits from the wide format data in that same language X."
# <https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_eras>
sub month_format_abbreviated { return( shift->_calendar_terms(
id => 'month_format_abbreviated',
type => 'month',
context => 'format',
width => [qw( abbreviated wide )],
) ); }
sub month_format_narrow { return( shift->_calendar_terms(
id => 'month_format_narrow',
type => 'month',
context => 'format',
width => [qw( narrow wide )],
) ); }
# NOTE: There is no 'short' format for month, but there is for 'day'
sub month_format_wide { return( shift->_calendar_terms(
id => 'month_format_wide',
type => 'month',
context => 'format',
width => 'wide',
) ); }
sub month_stand_alone_abbreviated { return( shift->_calendar_terms(
id => 'month_stand_alone_abbreviated',
type => 'month',
context => 'stand-alone',
width => [qw( abbreviated wide )],
) ); }
sub month_stand_alone_narrow { return( shift->_calendar_terms(
id => 'month_stand_alone_narrow',
type => 'month',
context => 'stand-alone',
width => [qw( narrow wide )],
) ); }
# NOTE: There is no 'short' stand-alone for month, but there is for 'day'
sub month_stand_alone_wide { return( shift->_calendar_terms(
id => 'month_stand_alone_narrow',
type => 'month',
context => 'stand-alone',
width => 'wide',
) ); }
sub name
{
my $self = shift( @_ );
my $name;
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
my $self = shift( @_ );
my $pref = $self->time_format_preferred;
return( $self->pass_error ) if( !defined( $pref ) );
# 'H': 0-23
# 'k': 1-24
# 'h': 1-12
# 'K': 0-11
return( ( $pref eq 'H' || $pref eq 'k' ) ? 1 : 0 );
}
sub quarter_format_abbreviated { return( shift->_calendar_terms(
id => 'quarter_format_abbreviated',
type => 'quarter',
context => [qw( format stand-alone )],
width => [qw( abbreviated wide )],
) ); }
sub quarter_format_narrow { return( shift->_calendar_terms(
id => 'quarter_format_narrow',
type => 'quarter',
context => [qw( format stand-alone )],
width => [qw( narrow wide )],
) ); }
# NOTE: There is no 'short' format for quarter, but there is for 'day'
sub quarter_format_wide { return( shift->_calendar_terms(
id => 'quarter_format_wide',
type => 'quarter',
context => [qw( format stand-alone )],
width => 'wide',
) ); }
sub quarter_stand_alone_abbreviated { return( shift->_calendar_terms(
id => 'quarter_stand_alone_abbreviated',
type => 'quarter',
context => [qw( stand-alone format )],
width => [qw( abbreviated wide )],
) ); }
sub quarter_stand_alone_narrow { return( shift->_calendar_terms(
id => 'quarter_stand_alone_narrow',
type => 'quarter',
context => [qw( stand-alone format )],
width => [qw( narrow abbreviated wide )],
) ); }
# NOTE: There is no 'short' stand-alone for quarter, but there is for 'day'
sub quarter_stand_alone_wide { return( shift->_calendar_terms(
id => 'quarter_stand_alone_narrow',
type => 'quarter',
context => [qw( stand-alone format )],
width => 'wide',
) ); }
sub script
{
my $self = shift( @_ );
my $name;
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
$self->{territory_info} = $info;
}
return( $info );
}
sub time_format_allowed { return( shift->_time_formats( 'allowed', @_ ) ); }
sub time_format_default { return( shift->time_format_medium ); }
sub time_format_full { return( shift->_date_time_format(
calendar => 'gregorian',
type => 'time',
width => 'full',
) ); }
sub time_format_long { return( shift->_date_time_format(
calendar => 'gregorian',
type => 'time',
width => 'long',
) ); }
sub time_format_medium { return( shift->_date_time_format(
calendar => 'gregorian',
type => 'time',
width => 'medium',
) ); }
sub time_format_preferred { return( shift->_time_formats( 'preferred', @_ ) ); }
sub time_format_short { return( shift->_date_time_format(
calendar => 'gregorian',
type => 'time',
width => 'short',
) ); }
sub time_formats
{
my $self = shift( @_ );
my $formats = {};
foreach my $t ( qw( full long medium short ) )
{
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
die( "No width was provided to retrieve AM/PN localised terms." );
}
elsif( ref( $opts->{context} ) && ref( $opts->{context} ) ne 'ARRAY' && !overload::Method( $opts->{context} => '""' ) )
{
return( $self->error( "Context provided (", overload::StrVal( $opts->{context} ), ") is a reference that does not stringify!" ) );
}
elsif( ref( $opts->{width} ) && ref( $opts->{width} ) ne 'ARRAY' && !overload::Method( $opts->{width} => '""' ) )
{
return( $self->error( "Width provided (", overload::StrVal( $opts->{width} ), ") is a reference that does not stringify!" ) );
}
elsif( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
my $meth_id = 'am_pm_' . $calendar . '_' . $opts->{width} . '_' . $opts->{context};
my $ampm;
unless( defined( $ampm = $self->{ $meth_id } ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "The Locale::Unicode::Data object is gone!" );
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
# We do not want to fallback to the 'und' locale on this.
pop( @$tree );
my $widths = ref( $opts->{width} ) eq 'ARRAY' ? $opts->{width} : [$opts->{width}];
my $contexts = ref( $opts->{context} ) eq 'ARRAY' ? $opts->{context} : [$opts->{context}];
$ampm = [];
LOCALES: foreach my $loc ( @$tree )
{
foreach my $context ( @$contexts )
{
foreach my $width ( @$widths )
{
my $all = $cldr->calendar_term(
locale => $loc,
calendar => $calendar,
term_context => $context,
term_width => $width,
term_name => [qw( am pm )],
);
return( $self->pass_error ) if( !defined( $all ) );
if( scalar( @$all ) )
{
if( scalar( @$all ) != 2 )
{
return( $self->error( "Data seems to be corrupted for locale ${loc} in Locale::Unicode::Data. I received ", scalar( @$all ), " sets of data when I expected 2." ) );
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
die( "No format ID specified." );
}
elsif( !length( $opts->{id} // '' ) )
{
return( $self->error( "No format ID was provided" ) );
}
elsif( ref( $opts->{id} ) && !overload::Method( $opts->{id} => '""' ) )
{
return( $self->error( "Format ID provided (", overload::StrVal( $opts->{id} ), ") is a reference that does not stringify!" ) );
}
elsif( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
my $meth_id = 'available_formats_' . $calendar . '_' . $opts->{id};
my $pattern;
unless( defined( $pattern = $self->{ $meth_id } ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "Locale::Unicode::Data object is gone!" );
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $ref;
LOCALE: foreach my $loc ( @$tree )
{
$ref = $cldr->calendar_available_format(
locale => $loc,
calendar => $calendar,
format_id => $opts->{id},
count => [undef, qw( few many one other two zero)],
);
return( $self->pass_error ) if( !defined( $ref ) && $cldr->error );
if( $ref && $ref->{format_pattern} )
{
$pattern = $ref->{format_pattern};
last LOCALE;
}
}
$self->{ $meth_id } = $pattern;
}
return( $pattern );
}
sub _calendar_eras
{
my $self = shift( @_ );
my $opts = $self->_get_args_as_hash( @_ );
my $id = $opts->{id} || die( "Missing ID" );
die( "Missing width" ) if( !$opts->{width} );
if( ref( $opts->{id} ) && !overload::Method( $opts->{id} => '""' ) )
{
return( $self->error( "Format ID provided (", overload::StrVal( $opts->{id} ), ") is a reference that does not stringify!" ) );
}
elsif( ref( $opts->{width} ) && ref( $opts->{width} ) ne 'ARRAY' && !overload::Method( $opts->{width} => '""' ) )
{
return( $self->error( "Width provided (", overload::StrVal( $opts->{width} ), ") is a reference that does not stringify!" ) );
}
elsif( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
$opts->{width} = [$opts->{width}] unless( ref( $opts->{width} ) eq 'ARRAY' );
my $eras;
unless( defined( $eras = $self->{ "${id}_${calendar}" } ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "Locale::Unicode::Data object is gone!" );
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
$eras = [];
LOCALE: foreach my $loc ( @$tree )
{
foreach my $width ( @{$opts->{width}} )
{
my $all = $cldr->calendar_eras_l10n(
locale => $loc,
calendar => $calendar,
era_width => $width,
( exists( $opts->{alt} ) ? ( alt => $opts->{alt} ) : () ),
order => [era_id => 'integer'],
);
return( $self->pass_error( $cldr->error ) ) if( !defined( $all ) && $cldr->error );
if( $all && scalar( @$all ) )
{
@$eras = map( $_->{locale_name}, @$all );
last LOCALE;
}
}
}
$self->{ $id } = $eras;
}
return( $eras );
}
sub _calendar_terms
{
my $self = shift( @_ );
my $opts = $self->_get_args_as_hash( @_ );
my $id = $opts->{id} || die( "Missing ID" );
die( "Missing type" ) if( !$opts->{type} );
die( "Missing context" ) if( !$opts->{context} );
die( "Missing width" ) if( !$opts->{width} );
if( ref( $id ) && !overload::Method( $id => '""' ) )
{
return( $self->error( "Format ID provided (", overload::StrVal( $id ), ") is a reference that does not stringify!" ) );
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
return( $self->error( "Type provided (", overload::StrVal( $opts->{type} ), ") is a reference that does not stringify!" ) );
}
elsif( ref( $opts->{context} ) && ref( $opts->{context} ) ne 'ARRAY' && !overload::Method( $opts->{context} => '""' ) )
{
return( $self->error( "Context provided (", overload::StrVal( $opts->{context} ), ") is a reference that does not stringify!" ) );
}
elsif( ref( $opts->{width} ) && ref( $opts->{width} ) ne 'ARRAY' && !overload::Method( $opts->{width} => '""' ) )
{
return( $self->error( "Width provided (", overload::StrVal( $opts->{width} ), ") is a reference that does not stringify!" ) );
}
elsif( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
$opts->{width} = [$opts->{width}] unless( ref( $opts->{width} ) eq 'ARRAY' );
# If some type (e.g. short, narrow, etc) are missing in 'format', we can try to look for it in 'stand-alone'
$opts->{context} = [$opts->{context}] unless( ref( $opts->{context} ) eq 'ARRAY' );
my $meth_id = "${id}_${calendar}_type=$opts->{type}_context=" . join( ';', @{$opts->{context}} ) . '_width=' . join( ';', @{$opts->{width}} );
my $terms;
unless( defined( $terms = $self->{ $meth_id } ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "Locale::Unicode::Data object is gone!" );
my $locales = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $expects =
{
day => 7,
month => 12,
quarter => 4,
};
LOCALE: foreach my $loc ( @$locales )
{
foreach my $ctx ( @{$opts->{context}} )
{
foreach my $width ( @{$opts->{width}} )
{
my $all = $cldr->calendar_terms(
locale => $loc,
calendar => $calendar,
term_type => $opts->{type},
term_context => $ctx,
term_width => $width,
( $opts->{type} eq 'day' ? ( order_by_value => [term_name => [qw( mon tue wed thu fri sat sun )]] ) : () ),
( ( $opts->{type} eq 'month' || $opts->{type} eq 'quarter' ) ? ( order => [term_name => 'integer'] ) : () ),
);
return( $self->pass_error ) if( !defined( $all ) && $cldr->error );
if( $all && scalar( @$all ) >= $expects->{ $opts->{type} } )
{
$terms = [];
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
}
elsif( $opts->{type} ne 'date' &&
$opts->{type} ne 'time' )
{
die( "Invalid type provided. Please specify either 'date' or 'time'" );
}
elsif( ref( $opts->{width} ) && ref( $opts->{width} ) ne 'ARRAY' && !overload::Method( $opts->{width} => '""' ) )
{
return( $self->error( "Width provided (", overload::StrVal( $opts->{width} ), ") is a reference that does not stringify!" ) );
}
elsif( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $widths = ref( $opts->{width} ) eq 'ARRAY' ? $opts->{width} : [$opts->{width}];
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
my $meth_id = '_date_time_format_' . $opts->{type} . '_format_' . $calendar . '_' . $widths->[0];
my $pattern;
unless( defined( $pattern = $self->{ $meth_id } ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "Locale::Unicode::Data object is gone!" );
my $locales = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $ref;
LOCALE: foreach my $loc ( @$locales )
{
foreach my $width ( @$widths )
{
$ref = $cldr->calendar_format_l10n(
locale => $loc,
calendar => $calendar,
format_type => $opts->{type},
format_length => $width,
);
return( $self->pass_error ) if( !defined( $ref ) && $cldr->error );
if( $ref && $ref->{format_pattern} )
{
$pattern = $ref->{format_pattern};
last LOCALE;
}
}
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
}
elsif( ref( $opts->{type} ) && !overload::Method( $opts->{type} => '""' ) )
{
return( $self->error( "Type provided (", overload::StrVal( $opts->{type} ), ") is a reference that does not stringify!" ) );
}
elsif( $opts->{type} ne 'atTime' &&
$opts->{type} ne 'standard' )
{
die( "Invalid type provided. Please specify either 'atTime' or 'standard'" );
}
elsif( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
my $meth_id = "_datetime_format_" . $calendar . '_' . $opts->{width} . '_' . $opts->{type};
my $pattern;
unless( defined( $pattern = $self->{ $meth_id } ) )
{
my $locale = $self->{locale} || die( "Locale value is gone!" );
my $cldr = $self->{_cldr} || die( "Locale::Unicode::Data object is gone!" );
my $locales = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $ref;
LOCALE: foreach my $loc ( @$locales )
{
$ref = $cldr->calendar_datetime_format(
locale => $loc,
calendar => $calendar,
format_type => $opts->{type},
format_length => $opts->{width},
);
return( $self->pass_error ) if( !defined( $ref ) && $cldr->error );
if( $ref && $ref->{format_pattern} )
{
$pattern = $ref->{format_pattern};
last LOCALE;
}
}
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
my $self = shift( @_ );
my $def = shift( @_ );
my $dt = shift( @_ );
my $opts = $self->_get_args_as_hash( @_ );
my $period = $self->_find_day_period( $dt ) ||
return( $self->pass_error );
my $locale = $self->{locale} ||
return( $self->error( "The local value is gone!" ) );
my $cldr = $self->{_cldr} ||
return( $self->error( "The Locale::Unicode::Data object is gone!" ) );
if( $opts->{calendar} && ref( $opts->{calendar} ) && !overload::Method( $opts->{calendar} => '""' ) )
{
return( $self->error( "Calendar provided (", overload::StrVal( $opts->{calendar} ), ") is a reference that does not stringify!" ) );
}
my $calendar = $opts->{calendar} || $self->{calendar} || 'gregorian';
die( "No 'context' argument was provided." ) if( !exists( $def->{context} ) );
die( "No 'width' argument was provided." ) if( !exists( $def->{width} ) );
if( ref( $def->{context} ) && ref( $def->{context} ) ne 'ARRAY' && !overload::Method( $def->{context} => '""' ) )
{
return( $self->error( "Context provided (", overload::StrVal( $def->{context} ), ") is a reference that does not stringify!" ) );
}
elsif( ref( $def->{width} ) && ref( $def->{width} ) ne 'ARRAY' && !overload::Method( $def->{width} => '""' ) )
{
return( $self->error( "Width provided (", overload::StrVal( $def->{width} ), ") is a reference that does not stringify!" ) );
}
my $width = ref( $def->{width} ) eq 'ARRAY' ? $def->{width} : [$def->{width}];
my $tree = $cldr->make_inheritance_tree( $locale ) ||
return( $self->pass_error( $cldr->error ) );
my $name;
LOCALE: foreach my $loc ( @$tree )
{
foreach my $width ( @$width )
{
my $ref = $cldr->calendar_term(
locale => $loc,
calendar => $calendar,
term_context => $def->{context},
term_width => $width,
term_name => $period,
);
if( !defined( $ref ) && $cldr->error )
{
return( $self->pass_error( $cldr->error ) );
}
if( $ref )
{
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
$self->{ $meth_id } = $name;
}
return( $name );
}
sub FREEZE
{
my $self = CORE::shift( @_ );
my $serialiser = CORE::shift( @_ ) // '';
my $class = CORE::ref( $self );
my @keys = qw( locale calendar default_date_format_length default_time_format_length fatal );
my %hash = ();
@hash{ @keys } = @$self{ @keys };
# Return an array reference rather than a list so this works with Sereal and CBOR
# On or before Sereal version 4.023, Sereal did not support multiple values returned
CORE::return( [$class, %hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
# But Storable want a list with the first element being the serialised element
CORE::return( $class, \%hash );
}
sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head1 NAME
DateTime::Locale::FromCLDR - DateTime Localised Data from Unicode CLDR
=head1 SYNOPSIS
use DateTime::Locale::FromCLDR;
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP' ) ||
die( DateTime::Locale::FromCLDR->error );
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
my $array = $locale->am_pm_abbreviated;
my $array = $locale->available_formats;
$locale->calendar( 'hebrew' );
my $str = $locale->calendar;
# a Locale::Unicode object that stringifies to the initial locale value (ja-Kana-JP)
my $obj = $locale->code;
my $str = $locale->date_at_time_format_full;
my $str = $locale->date_at_time_format_long;
my $str = $locale->date_at_time_format_medium;
my $str = $locale->date_at_time_format_short;
my $str = $locale->date_format_default;
my $str = $locale->date_format_full;
my $str = $locale->date_format_long;
my $str = $locale->date_format_medium;
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
die( DateTime::Locale::FromCLDR->error );
# Okinawan as spoken in Japan Southern islands
my $locale = DateTime::Locale::FromCLDR->new( 'ryu-Kana-JP-t-de-t0-und-x0-medical' ) ||
die( DateTime::Locale::FromCLDR->error );
use Locale::Unicode;
my $loc = Locale::Unicode->new( 'fr-FR' );
my $locale = DateTime::Locale::FromCLDR->new( $loc ) ||
die( DateTime::Locale::FromCLDR->error );
Specifying a calendar ID other than the default C<gregorian>:
my $locale = DateTime::Locale::FromCLDR->new( 'ja-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
or, using an hash reference:
my $locale = DateTime::Locale::FromCLDR->new( 'ja-JP', { calendar => 'japanese' } ) ||
die( DateTime::Locale::FromCLDR->error );
Instantiate a new L<DateTime::Locale::FromCLDR> object based on a C<locale> provided, and returns it. By default, it uses the calendar C<gregorian>, but you can specify a different one with the C<calendar> option.
You can provide any C<locale>, even complex one as shown above, and only its core part will be retained. So, for example:
my $locale = DateTime::Locale::FromCLDR->new( 'ryu-Kana-JP-t-de-t0-und-x0-medical' ) ||
die( DateTime::Locale::FromCLDR->error );
say $locale; # ryu-Kana-JP
If an error occurs, it sets an L<exception object|DateTime::Locale::FromCLDR::Exception> and returns C<undef> in scalar context, or an empty list in list context, or possibly a special C<DateTime::Locale::FromCLDR::NullObject> in object context. See ...
The object is overloaded and stringifies into the core part of the original string provided upon instantiation.
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
say @$ampm; # AM, PM
my $locale = DateTime::Locale::FromCLDR->new( 'ja' );
my $ampm = $locale->am_pm_abbreviated
say @$ampm; # åå, åå¾
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
my $ampm = $locale->am_pm_abbreviated
say @$ampm; # Empty
See L<Locale::Unicode::Data/calendar_term>
=head2 am_pm_format_narrow
Same as L<am_pm_format_abbreviated|/am_pm_format_abbreviated>, but returns the narrow format of the AM/PM terms.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->am_pm_format_narrow;
=head2 am_pm_format_wide
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=for Pod::Coverage as_string
=head2 available_formats
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->available_formats;
Returns an array reference of all the format ID available for this C<locale>
See L<Locale::Unicode::Data/calendar_available_format>
=head2 available_format_patterns
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $ref = $locale->available_format_patterns;
Returns an hash reference of all the available format ID to their corresponding pattern for the C<locale>
See L<Locale::Unicode::Data/calendar_available_format>
=head2 calendar
my $locale = DateTime::Locale::FromCLDR->new( 'ja-Kana-JP', calendar => 'japanese' ) ||
die( DateTime::Locale::FromCLDR->error );
my $str = $locale->calendar; # japanese
$locale->calendar( 'gregorian' );
Sets or gets the L<calendar ID|Locale::Unicode::Data/calendar> used to perform queries along with the given C<locale>
=head2 code
my $obj = $locale->code;
Returns the L<Locale::Unicode> object either received or created upon object instantiation.
=head2 date_at_time_format_full
my $str = $locale->date_at_time_format_full;
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 date_format_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->date_format_full;
# EEEE, MMMM d, y
# Tuesday, July 23, 2024
Returns the L<full date pattern|https://unicode.org/reports/tr35/tr35-dates.html#dateFormats>
See also L<Locale::Unicode::Data/calendar_format_l10n>
=head2 date_format_long
Same as L<date_format_full|/date_format_full>, but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->date_format_long;
# MMMM d, y
# July 23, 2024
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 datetime_format_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->datetime_format_full;
# EEEE, MMMM d, y, h:mm:ssâ¯a zzzz
# Tuesday, July 23, 2024, 1:53:27â¯AM UTC
Returns the L<full datetime pattern|https://unicode.org/reports/tr35/tr35-dates.html#dateTimeFormats>
See also L<Locale::Unicode::Data/calendar_datetime_format>
=head2 datetime_format_long
Same as L<datetime_format_full|/datetime_format_full>, but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->datetime_format_long;
# MMMM d, y, h:mm:ssâ¯a z
# July 23, 2024, 1:57:02â¯AM UTC
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 day_format_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $days = $locale->day_format_abbreviated;
say @$days;
# Mon, Tue, Wed, Thu, Fri, Sat, Sun
Returns an array reference of week day names abbreviated format with Monday first and Sunday last.
See also L<Locale::Unicode::Data/calendar_term>
=head2 day_format_narrow
Same as L<day_format_abbreviated|/day_format_abbreviated>, but returns the narrow format days.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $days = $locale->day_format_abbreviated;
say @$days;
# M, T, W, T, F, S, S
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_format_abbreviated( $dt );
# après-midi
Returns a string representing the localised expression of the period of day the L<DateTime> object provided is.
If nothing relevant could be found somehow, this will return an empty string. C<undef> is returned only if an error occurred.
This is used to provide the relevant value for the token C<B> or C<b> in the L<Unicode LDML format patterns|Locale::Unicode::Data/"Format Patterns">
See also L<Locale::Unicode::Data/calendar_term>, L<Locale::Unicode::Data/day_period> and L<DateTime::Format::Unicode>
=head2 day_period_format_narrow
Same as L<day_period_format_abbreviated|/day_period_format_abbreviated>, but returns the narrow format of day period.
my $dt = DateTime->new( year => 2024, hour => 7 );
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->day_period_format_narrow( $dt );
# in the morning
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_stand_alone_abbreviated( $dt );
# ap.m.
Returns a string representing the localised expression of the period of day the L<DateTime> object provided is.
If nothing relevant could be found somehow, this will return an empty string. C<undef> is returned only if an error occurred.
This is used to provide a stand-alone word that can be used as a title, or in a different context.
See also L<Locale::Unicode::Data/calendar_term>, L<Locale::Unicode::Data/day_period> and L<DateTime::Format::Unicode>
=head2 day_period_stand_alone_narrow
Same as L<day_period_stand_alone_abbreviated|/day_period_stand_alone_abbreviated>, but returns the narrow stand-alone version of the day period.
my $dt = DateTime->new( year => 2024, hour => 13 );
my $locale = DateTime::Locale::FromCLDR->new( 'fr' );
say $locale->day_period_stand_alone_narrow( $dt );
# ap.m.
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
This returns the string C<medium>
=head2 era_abbreviated
my $array = $locale->era_abbreviated;
say @$array;
# BC, AD
Returns an array reference of era names in abbreviated format.
See also L<Locale::Unicode::Data/calendar_eras_l10n>
=head2 era_narrow
Same as L<era_abbreviated|/era_abbreviated>, but returns the narrow format eras.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->era_narrow;
say @$array;
# B, A
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
Provided with the format ID of an L<available format|/available_formats> and this will return the localised C<CLDR> pattern.
Keep in mind that the C<CLDR> formatting method of L<DateTime|DateTime/format_cldr> does not recognise all the C<CLDR> pattern tokens. Thus, for example, if you chose the standard available pattern C<Bhm>, this method would return the localised patte...
my $now = DateTime->now( locale => "en", time_zone => "Asia/Tokyo" );
# Assuming $now = 2024-07-23T21:39:39
say $now->format_cldr( 'h:mm B' );
# 9:39 B
But C<B> is the day period, which can be looked up with L<Locale::Unicode::Data/day_period>, which provides us with the day period token C<night1>, which itself can be looked up with L<Locale::Unicode::Data/calendar_term> and gives us the localised s...
You can use L<DateTime::Format::Unicode> instead of the default L<DateTime> C<CLDR> formatting if you want to get better support for all L<CLDR pattern tokens|Locale::Unicode::Data/"Format Patterns">.
With Japanese:
my $locale = DateTime::Locale::FromCLDR->new( 'ja' );
my $pattern = $locale->format_for( 'Bhm' );
# BK:mm
my $now = DateTime->now( locale => "ja", time_zone => "Asia/Tokyo" );
say $now->format_cldr( 'BK:mm' );
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $diff = $locale->interval_greatest_diff( $dt1, $dt2, day_period_first => 1 );
# or, using an hash reference instead:
# my $diff = $locale->interval_greatest_diff( $dt1, $dt2, { day_period_first => 1 } );
Provided with 2 L<DateTime objects|DateTime>, and this will compute the L<greatest difference|https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats>.
Quoting from the L<LDML specifications|https://unicode.org/reports/tr35/tr35-dates.html#intervalFormats>:
"The data supplied in CLDR requires the software to determine the calendar field with the greatest difference before using the format pattern. For example, the greatest difference in "Jan 10-12, 2008" is the day field, while the greatest difference i...
If both C<DateTime> objects are identical, this will return an empty string.
You can alter the inner working of the algorithm by providing the option C<day_period_first> with a true value. This will prioritise the day period over the AM/PM (morning vs afternoon). What this means, is that if you have two datetimes, one with an...
This is important, because of the way almost all, but 4 locales (C<bg>, C<id>, C<uz> and C<zu>), have sliced up their day periods.
For the locale C<en>, for example, the day periods are:
=over 8
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 month_format_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_format_abbreviated;
say @$array;
# Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Returns an array reference of month names in abbreviated format from January to December.
See also L<Locale::Unicode::Data/calendar_term>
=head2 month_format_narrow
Same as L<month_format_abbreviated|/month_format_abbreviated>, but returns the months in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_format_narrow;
say @$array;
# J, F, M, A, M, J, J, A, S, O, N, D
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 month_stand_alone_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->month_stand_alone_abbreviated;
say @$array;
# Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Returns an array reference of month names in abbreviated stand-alone format from January to December.
See also L<Locale::Unicode::Data/calendar_term>
Note that there is often little difference between the C<format> and C<stand-alone> format types.
See the L<LDML specifications|https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_eras> for more information on the difference between the C<format> and C<stand-alone> types.
=head2 month_stand_alone_narrow
Same as L<month_stand_alone_abbreviated|/month_stand_alone_abbreviated>, but returns the months in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 quarter_format_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_format_abbreviated;
say @$array;
# Q1, Q2, Q3, Q4
Returns an array reference of quarter names in abbreviated format.
See also L<Locale::Unicode::Data/calendar_term>
=head2 quarter_format_narrow
Same as L<quarter_format_abbreviated|/quarter_format_abbreviated>, but returns the quarters in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_format_narrow;
say @$array;
# 1, 2, 3, 4
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 quarter_stand_alone_abbreviated
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->quarter_stand_alone_abbreviated;
say @$array;
# Q1, Q2, Q3, Q4
Returns an array reference of quarter names in abbreviated format.
See also L<Locale::Unicode::Data/calendar_term>
Note that there is often little difference between the C<format> and C<stand-alone> format types.
See the L<LDML specifications|https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_eras> for more information on the difference between the C<format> and C<stand-alone> types.
=head2 quarter_stand_alone_narrow
Same as L<quarter_stand_alone_abbreviated|/quarter_stand_alone_abbreviated>, but returns the quarters in narrow format.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
This is an alias for L<territory_code|/territory_code>
=head2 territory_info
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $ref = $locale->territory_info;
which would yield:
{
calendars => undef,
contains => undef,
currency => "USD",
first_day => 7,
gdp => 19490000000000,
languages => [qw(
en es zh-Hant fr de fil it vi ko ru nv yi pdc hnj haw
frc chr esu dak cho lkt ik mus io cic cad jbo osa zh
)],
literacy_percent => 99,
min_days => 1,
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
territory_id => 297,
weekend => undef,
}
my $locale = DateTime::Locale::FromCLDR->new( 'en-GB' );
my $ref = $locale->territory_info;
which would yield:
{
calendars => undef,
contains => undef,
currency => "GBP",
first_day => 1,
gdp => 2925000000000,
languages => [qw(
en fr de es pl pa ur ta gu sco cy bn ar zh-Hant it lt pt
so tr ga gd kw en-Shaw
)],
literacy_percent => 99,
min_days => 4,
parent => 154,
population => 65761100,
status => "regular",
territory => "GB",
territory_id => 121,
weekend => undef,
}
Returns an hash reference of information related to the ISO3166 country code associated with the C<locale>. If the C<locale> has no country code associated, it will expand it using the Unicode LDML rule with L<Locale::Unicode::Data/likely_subtag>
Keep in mind that the default or fallback data are stored in the special territory code C<001> (World). Thus, for example, if the C<calendars> field is empty, the default value would be in C<001>, and would be C<["gregorian"]>
=head2 time_format_allowed
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
my $array = $locale->time_format_allowed;
Returns an array reference of L<allowed time patterns|https://unicode.org/reports/tr35/tr35-dates.html#Time_Data> for the C<locale>'s associated territory. If the locale has no C<territory> associated with, it will check the L<likely subtag|Locale::U...
=head2 time_format_default
lib/DateTime/Locale/FromCLDR.pm view on Meta::CPAN
=head2 time_format_full
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->time_format_full;
# h:mm:ssâ¯a zzzz
# 10:44:07â¯PM UTC
Returns the L<full date pattern|https://unicode.org/reports/tr35/tr35-dates.html#dateFormats>
See also L<Locale::Unicode::Data/calendar_format_l10n>
=head2 time_format_long
Same as L<time_format_full|/time_format_full>, but returns the long format pattern.
my $locale = DateTime::Locale::FromCLDR->new( 'en' );
say $locale->time_format_long;
# h:mm:ssâ¯a z
# 10:44:07â¯PM UTC
t/01.locale.t view on Meta::CPAN
can_ok( $locale, 'am_pm_abbreviated' );
can_ok( $locale, 'am_pm_format_abbreviated' );
can_ok( $locale, 'am_pm_format_narrow' );
can_ok( $locale, 'am_pm_format_wide' );
can_ok( $locale, 'am_pm_standalone_abbreviated' );
can_ok( $locale, 'am_pm_standalone_narrow' );
can_ok( $locale, 'am_pm_standalone_wide' );
can_ok( $locale, 'as_string' );
can_ok( $locale, 'available_formats' );
can_ok( $locale, 'available_format_patterns' );
can_ok( $locale, 'calendar' );
can_ok( $locale, 'code' );
can_ok( $locale, 'date_at_time_format_full' );
can_ok( $locale, 'date_at_time_format_long' );
can_ok( $locale, 'date_at_time_format_medium' );
can_ok( $locale, 'date_at_time_format_short' );
can_ok( $locale, 'date_format_default' );
can_ok( $locale, 'date_format_full' );
can_ok( $locale, 'date_format_long' );
can_ok( $locale, 'date_format_medium' );
can_ok( $locale, 'date_format_short' );
t/01.locale.t view on Meta::CPAN
yMd => "M/d/y",
yMEd => "E, M/d/y",
yMMM => "MMM y",
yMMMd => "MMM d, y",
yMMMEd => "E, MMM d, y",
yMMMM => "MMMM y",
yQQQ => "QQQ y",
yQQQQ => "QQQQ y",
yw => "'week' w 'of' Y",
},
calendar => q{gregorian},
code => q{en},
date_at_time_format_full => q{EEEE, MMMM d, y 'at' h:mm:ssâ¯a zzzz},
date_at_time_format_long => q{MMMM d, y 'at' h:mm:ssâ¯a z},
date_at_time_format_medium => q{MMM d, y, h:mm:ssâ¯a},
date_at_time_format_short => q{M/d/yy, h:mmâ¯a},
date_format_default => q{MMM d, y},
date_format_full => q{EEEE, MMMM d, y},
date_format_long => q{MMMM d, y},
date_format_medium => q{MMM d, y},
date_format_short => q{M/d/yy},
t/01.locale.t view on Meta::CPAN
quarter_format_narrow => ["1", "2", "3", "4"],
quarter_format_wide => ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
quarter_stand_alone_abbreviated => ["Q1", "Q2", "Q3", "Q4"],
quarter_stand_alone_narrow => ["1", "2", "3", "4"],
quarter_stand_alone_wide => ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
script => undef,
script_code => undef,
territory => undef,
territory_code => undef,
territory_info => {
calendars => undef,
contains => undef,
currency => "USD",
first_day => 7,
gdp => 24660000000000,
languages => [qw(
en es zh-Hant fr de fil it vi ko ru nv yi pdc hnj haw
frc chr esu dak cho lkt ik mus io cic cad jbo osa zh
)],
literacy_percent => 99,
min_days => 1,
t/01.locale.t view on Meta::CPAN
available_format_patterns => {
GyMd => "dd/MM/y G",
GyMMMEEEEd => "EEEE, d MMM y G",
MEd => "E dd/MM",
MMMEd => "E d MMM",
MMMEEEEd => "EEEE d MMM",
MMMMEEEEd => "EEEE d MMMM",
yMMMEEEEd => "EEEE, d MMM y",
yMMMMEEEEd => "EEEE, d MMMM y",
},
calendar => q{gregorian},
code => q{en-GB},
date_at_time_format_full => q{EEEE, d MMMM y 'at' HH:mm:ss zzzz},
date_at_time_format_long => q{d MMMM y 'at' HH:mm:ss z},
date_at_time_format_medium => q{d MMM y, HH:mm:ss},
date_at_time_format_short => q{dd/MM/y, HH:mm},
date_format_default => q{d MMM y},
date_format_full => q{EEEE, d MMMM y},
date_format_long => q{d MMMM y},
date_format_medium => q{d MMM y},
date_format_short => q{dd/MM/y},
t/01.locale.t view on Meta::CPAN
quarter_format_narrow => ["1", "2", "3", "4"],
quarter_format_wide => ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
quarter_stand_alone_abbreviated => ["Q1", "Q2", "Q3", "Q4"],
quarter_stand_alone_narrow => ["1", "2", "3", "4"],
quarter_stand_alone_wide => ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
script => undef,
script_code => undef,
territory => q{United Kingdom},
territory_code => q{GB},
territory_info => {
calendars => undef,
contains => undef,
currency => "GBP",
first_day => 1,
gdp => 3700000000000,
languages => [qw(
en fr de es pl pa ur ta gu sco cy ro bn ar zh-Hant it lt
pt so tr ga gd kw en-Shaw
)],
literacy_percent => 99,
min_days => 4,
t/01.locale.t view on Meta::CPAN
yMMM => "MMM y",
yMMMd => "d MMM y",
yMMMEd => "EEE, d MMM y",
yMMMM => "MMMM 'de' y",
yMMMMd => "d 'de' MMMM 'de' y",
yMMMMEd => "EEE, d 'de' MMMM 'de' y",
yQQQ => "QQQ y",
yQQQQ => "QQQQ 'de' y",
yw => "'semana' w 'de' Y",
},
calendar => q{gregorian},
code => q{es-005-valencia},
date_at_time_format_full => q{EEEE, d 'de' MMMM 'de' y H:mm:ss (zzzz)},
date_at_time_format_long => q{d 'de' MMMM 'de' y H:mm:ss z},
date_at_time_format_medium => q{d MMM y H:mm:ss},
date_at_time_format_short => q{d/M/yy H:mm},
date_format_default => q{d MMM y},
date_format_full => q{EEEE, d 'de' MMMM 'de' y},
date_format_long => q{d 'de' MMMM 'de' y},
date_format_medium => q{d MMM y},
date_format_short => q{d/M/yy},
t/01.locale.t view on Meta::CPAN
quarter_format_narrow => ["1.er trimestre", "2.º trimestre", "3.er trimestre", "4.º trimestre"],
quarter_format_wide => ["1.er trimestre", "2.º trimestre", "3.er trimestre", "4.º trimestre"],
quarter_stand_alone_abbreviated => ["T1", "T2", "T3", "T4"],
quarter_stand_alone_narrow => ["T1", "T2", "T3", "T4"],
quarter_stand_alone_wide => ["1.er trimestre", "2.º trimestre", "3.er trimestre", "4.º trimestre"],
script => undef,
script_code => undef,
territory => q{South America},
territory_code => q{005},
territory_info => {
calendars => undef,
contains => undef,
currency => "EUR",
first_day => 1,
gdp => 2242000000000,
languages => [qw( es en ca gl eu ast ext an oc )],
literacy_percent => 97.7,
min_days => 4,
parent => "039",
population => 47280400,
status => "regular",
t/01.locale.t view on Meta::CPAN
yMM => "y/MM",
yMMM => "yå¹´Mæ",
yMMMd => "yå¹´Mædæ¥",
yMMMEd => "yå¹´Mædæ¥(E)",
yMMMEEEEd => "yå¹´Mædæ¥EEEE",
yMMMM => "yå¹´Mæ",
yQQQ => "y/QQQ",
yQQQQ => "yå¹´QQQQ",
yw => "Y年第wé±",
},
calendar => q{gregorian},
code => q{ja-Latn-fonipa-hepburn-heploc},
date_at_time_format_full => q{yå¹´Mædæ¥EEEE Hæmmåssç§ zzzz},
date_at_time_format_long => q{yå¹´Mædæ¥ H:mm:ss z},
date_at_time_format_medium => q{y/MM/dd H:mm:ss},
date_at_time_format_short => q{y/MM/dd H:mm},
date_format_default => q{y/MM/dd},
date_format_full => q{yå¹´Mædæ¥EEEE},
date_format_long => q{yå¹´Mædæ¥},
date_format_medium => q{y/MM/dd},
date_format_short => q{y/MM/dd},
t/01.locale.t view on Meta::CPAN
quarter_format_narrow => ["第1ååæ", "第2ååæ", "第3ååæ", "第4ååæ"],
quarter_format_wide => ["第1ååæ", "第2ååæ", "第3ååæ", "第4ååæ"],
quarter_stand_alone_abbreviated => ["Q1", "Q2", "Q3", "Q4"],
quarter_stand_alone_narrow => ["Q1", "Q2", "Q3", "Q4"],
quarter_stand_alone_wide => ["第1ååæ", "第2ååæ", "第3ååæ", "第4ååæ"],
script => q{Latin},
script_code => q{Latn},
territory => undef,
territory_code => undef,
territory_info => {
calendars => [qw( gregorian japanese )],
contains => undef,
currency => "JPY",
first_day => 7,
gdp => 5761000000000,
languages => [qw( ja ryu ko )],
literacy_percent => 99,
min_days => undef,
parent => "030",
population => 123202000,
status => "regular",