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>
πΈ COPYRIGHT AND LICENSE πΈ
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
- opensuse-leap 16.0: perl-DateTime-Locale 1.440000-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms