DateTim...romData(3)

πŸ’… DateTime::Locale::FromData β€” the whole vibe

okay so real talk, this page is from User Contributed Perl Documentation (yes, DateTim...romData(3), the truncated little legend), and it's all about a class that hands you locale objects built out of pre-baked data. let's get into it bestie 🫢


✨ NAME ✨

DateTime::Locale::FromData β€” a class for locale objects that get instantiated from pre-defined data. that's it, that's the whole personality πŸŽ€


🌸 VERSION 🌸

version 1.44 β€” periodt, that's the one.


πŸ¦‹ SYNOPSIS πŸ¦‹

  my $locale = DateTime::Locale::FromData->new(%lots_of_data)

literally just hand it a big pile of data and it gives you a locale. iconic behaviour honestly.


πŸ’– DESCRIPTION πŸ’–

so this class is the one that represents locales that got instantiated from the data living inside the DateTime::Locale::Data module. it's giving "I'm a locale, but make it data-driven" ✨


πŸ‘‘ METHODS πŸ‘‘

this class provides the following methods, and yes we're going through all of them, no skipping, no cap πŸ’…

πŸ“ $locale->code

the complete locale id, something like "en-US".

πŸ“ $locale->language_code

the language portion of the code, like "en".

πŸ“ $locale->script_code

the script portion of the code, like "Hant".

πŸ“ $locale->territory_code

the territory portion of the code, like "US".

πŸ“ $locale->variant_code

the variant portion of the code, like "POSIX".

πŸ“ $locale->name

the locale's complete name, which always includes at least a language component, plus optional territory and variant components. something like "English United States". and the value returned will always be in English. no exceptions, that's the rule.

πŸ“ $locale->language, $locale->script, $locale->territory, $locale->variant

the relevant component from the locale's complete name, like "English" or "United States". pick your fighter.

πŸ“ $locale->native_name

the locale's complete name in localized form as a UTF-8 string. so it's the name, but in its own language. slay 🌈

πŸ“ $locale->native_language, $locale->native_script, $locale->native_territory, $locale->native_variant

the relevant component from the locale's complete native name as a UTF-8 string. same deal as above, just the native flavour.

πŸ“ $locale->month_format_wide

πŸ“ $locale->month_format_abbreviated

πŸ“ $locale->month_format_narrow

πŸ“ $locale->month_stand_alone_wide

πŸ“ $locale->month_stand_alone_abbreviated

πŸ“ $locale->month_stand_alone_narrow

πŸ“ $locale->day_format_wide

πŸ“ $locale->day_format_abbreviated

πŸ“ $locale->day_format_narrow

πŸ“ $locale->day_stand_alone_wide

πŸ“ $locale->day_stand_alone_abbreviated

πŸ“ $locale->day_stand_alone_narrow

πŸ“ $locale->quarter_format_wide

πŸ“ $locale->quarter_format_abbreviated

πŸ“ $locale->quarter_format_narrow

πŸ“ $locale->quarter_stand_alone_wide

πŸ“ $locale->quarter_stand_alone_abbreviated

πŸ“ $locale->quarter_stand_alone_narrow

πŸ“ $locale->am_pm_abbreviated

πŸ“ $locale->era_wide

πŸ“ $locale->era_abbreviated

πŸ“ $locale->era_narrow

okay so all of these methods return an array reference containing the specified data. πŸ“š

the methods with "format" in the name should return strings that you can use as part of a string, like "the month of July". the stand alone values are for stuff like calendars, as opposed to a sentence β€” different vibe, same data.

the narrow forms may not be unique (for example, in the day column heading for a calendar it's totally okay to have "T" for both Tuesday and Thursday β€” no one's fighting about it).

the wide name should always be the full name of the thing in question. the narrow name should be just one or two characters. short and sweet.

⚠️ okay bestie, listen: these methods return a reference to the data stored in the locale object. if you change this reference's contents, that will affect the data in the locale object! so if you wanna modify it, clone the data first. don't be out here mutating the original, i'm begging 😭

πŸ“ $locale->date_format_full

πŸ“ $locale->date_format_long

πŸ“ $locale->date_format_medium

πŸ“ $locale->date_format_short

πŸ“ $locale->time_format_full

πŸ“ $locale->time_format_long

πŸ“ $locale->time_format_medium

πŸ“ $locale->time_format_short

πŸ“ $locale->datetime_format_full

πŸ“ $locale->datetime_format_long

πŸ“ $locale->datetime_format_medium

πŸ“ $locale->datetime_format_short

these ones return strings appropriate for the "DateTime->format_cldr" method. chef's kiss πŸ”₯

πŸ“ $locale->format_for($name)

you access these by passing a name to "$locale->format_for(...)", where the name is a CLDR-style format specifier.

the return value is a string suitable for passing to "$dt->format_cldr", so you can do something like this:

  print $dt->format_cldr( $dt->locale->format_for('MMMdd') )

which for the "en" locale would print out something like "08 Jul". cute.

note that the localization may also include additional text specific to the locale. for example, the "MMMMd" format for the "zh" locale includes the Chinese characters for "day" (ζ—₯) and month (月), so you get something like "8月23ζ—₯". the way that just works 🧚

πŸ“ $locale->available_formats

this should return a list of all the format names that could be passed to "$locale->format_for".

see the documentation for individual locales for details and examples of these formats. the format names that are available vary by locale, so don't assume, check first πŸ’œ

πŸ“ $locale->glibc_datetime_format

πŸ“ $locale->glibc_date_format

πŸ“ $locale->glibc_date_1_format

πŸ“ $locale->glibc_time_format

πŸ“ $locale->glibc_time_12_format

these methods return strings appropriate for the "DateTime->strftime" method.

⚠️ but you are strongly encouraged to use the other format methods, the ones that use the CLDR format data. these glibc ones are primarily included for the benefit of DateTime::Format::Strptime. so like, they're here, they work, but they're not the main character πŸ‘‘

πŸ“ $locale->version

the CLDR version from which this locale was generated. receipts included 🧾

πŸ“ $locale->prefers_24_hour_time

returns a boolean indicating whether or not the locale prefers 24-hour time. some of us are 24-hour girlies, some of us are not ⭐

πŸ“ $locale->first_day_of_week

returns a number from 1 to 7 indicating the local first day of the week, with Monday being 1 and Sunday being 7. yes, Monday. not Sunday. i don't make the rules.

πŸ“ $locale->locale_data

returns a clone of the original data used to create this locale as a hash. this is here to facilitate creating custom locales via DateTime::Locale->register_data_locale. build your own, bestie πŸŽ€


🫢 SUPPORT 🫢

bugs may be submitted at <https://github.com/houseabsolute/DateTime-Locale/issues>.

there's a mailing list available for users of this distribution: <mailto:datetime@perl.org>. come say hi ✨


πŸ” SOURCE πŸ”

the source code repository for DateTime-Locale can be found at <https://github.com/houseabsolute/DateTime-Locale>. go snoop, it's fine πŸ’–


πŸ’œ AUTHOR πŸ’œ

Dave Rolsky <autarch@urth.org>


this software is copyright (c) 2003 - 2024 by Dave Rolsky.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

the full text of the license can be found in the LICENSE file included with this distribution.


and that's the page, bestie πŸŽ€ ngl it was a long one but we got through every single method. this was DateTim...romData(3) from User Contributed Perl Documentation, running on perl v5.42.0, dated 2024-12-12 β€” go drink some water, you earned it πŸ’…βœ¨

πŸ“¦ where this page comes from