DateTime-Format-Unicode

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        DateTime format_cldr does not support all of the CLDR pattern tokens
        <https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patter
        ns>, but DateTime::Format::Unicode does.

        Known pattern tokens unsupported by DateTime are:

        *       "b"

                Period of the day, such as "am", "pm", "noon", "midnight"

                See "calendar_term" in Locale::Unicode::Data and its
                corollary "day_period" in Locale::Unicode::Data

        *       "B"

                Flexible day periods, such as "at night"

                See "calendar_term" in Locale::Unicode::Data and its
                corollary "day_period" in Locale::Unicode::Data

        *       "O"

                Zone, such as "O" to get the short localized GMT format
                "GMT-8", or "OOOO" to get the long localized GMT format
                "GMT-08:00"

        *       "r"

                Related Gregorian year (numeric).

                The documentation states that "For the Gregorian calendar,
                the ‘r’ year is the same as the ‘u’ year."

        *       "U"

                Cyclic year name. However, since this is for non gregorian
                calendars, like Chinese or Hindu calendars, and since
                DateTime only supports gregorian calendar, we do not support
                it either.

        *       "x"

                Timezone, such as "x" would be -08, "xx" -0800 or +0800,
                "xxx" would be "-08:00" or "+08:00", "xxxx" would be -0800
                or +0000 and "xxxxx" would be "-08:00", or "-07:52:58" or
                "+00:00"

        *       "X"

README.md  view on Meta::CPAN

- 4. It supports more pattern tokens

    [DateTime](https://metacpan.org/pod/DateTime) [format\_cldr](https://metacpan.org/pod/DateTime#format_cldr) does not support all of the [CLDR pattern tokens](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns), but [DateTime::F...

    Known pattern tokens unsupported by [DateTime](https://metacpan.org/pod/DateTime) are:

    - `b`

        Period of the day, such as `am`, `pm`, `noon`, `midnight`

        See ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term) and its corollary ["day\_period" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#day_period...

    - `B`

        Flexible day periods, such as `at night`

        See ["calendar\_term" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#calendar_term) and its corollary ["day\_period" in Locale::Unicode::Data](https://metacpan.org/pod/Locale%3A%3AUnicode%3A%3AData#day_period...

    - `O`

        Zone, such as `O` to get the short localized GMT format `GMT-8`, or `OOOO` to get the long localized GMT format `GMT-08:00`

    - `r`

        Related Gregorian year (numeric).

        The documentation states that "For the Gregorian calendar, the ‘r’ year is the same as the ‘u’ year."

    - `U`

        Cyclic year name. However, since this is for non gregorian calendars, like Chinese or Hindu calendars, and since [DateTime](https://metacpan.org/pod/DateTime) only supports gregorian calendar, we do not support it either.

    - `x`

        Timezone, such as `x` would be `-08`, `xx` `-0800` or `+0800`, `xxx` would be `-08:00` or `+08:00`, `xxxx` would be `-0800` or `+0000` and `xxxxx` would be `-08:00`, or `-07:52:58` or `+00:00`

    - `X`

        Timezone, such as `X` (`-08` or `+0530` or `Z`), `XX` (`-0800` or `Z`), `XXX` (`-08:00`), `XXXX` (`-0800` or `-075258` or `Z`), `XXXXX` (`-08:00` or `-07:52:58` or `Z`)

[DateTime::Format::Unicode](https://metacpan.org/pod/DateTime%3A%3AFormat%3A%3AUnicode) only formats `CLDR` datetime patterns, and does not parse them back into a [DateTime](https://metacpan.org/pod/DateTime) object. If you want to achieve that, ther...

lib/DateTime/Format/Unicode.pm  view on Meta::CPAN

    }
    else
    {
        warn( "Unknown length '${len}' to format am/pm" ) if( warnings::enabled() );
        return( $token x $len );
    }
}

# NOTE: pattern U
# Missing in DateTime
# "If the calendar does not provide cyclic year name data, or if the year value to be formatted is out of the range of years for which cyclic name data is provided, then numeric formatting is used (behaves like 'y')."
sub _format_cyclic_year_name
{
    my( $self, $token, $len, $dt ) = @_;
    my $unicode = $self->{_unicode} || die( "DateTime::Locale::FromCLDR object is gone!" );
    my $year = $dt->year;
    # Abbreviated
    if( $len >= 1 && $len <= 3 )
    {
        my $era = $unicode->era_abbreviated->[ $year < 0 ? 0 : 1 ];
        $era = $year if( !length( $era // '' ) );

lib/DateTime/Format/Unicode.pm  view on Meta::CPAN

L<DateTime> L<format_cldr|DateTime/format_cldr> does not support all of the L<CLDR pattern tokens|https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns>, but L<DateTime::Format::Unicode> does.

Known pattern tokens unsupported by L<DateTime> are:

=over 8

=item * C<b>

Period of the day, such as C<am>, C<pm>, C<noon>, C<midnight>

See L<Locale::Unicode::Data/calendar_term> and its corollary L<Locale::Unicode::Data/day_period>

=item * C<B>

Flexible day periods, such as C<at night>

See L<Locale::Unicode::Data/calendar_term> and its corollary L<Locale::Unicode::Data/day_period>

=item * C<O>

Zone, such as C<O> to get the short localized GMT format C<GMT-8>, or C<OOOO> to get the long localized GMT format C<GMT-08:00>

=item * C<r>

Related Gregorian year (numeric).

The documentation states that "For the Gregorian calendar, the ‘r’ year is the same as the ‘u’ year."

=item * C<U>

Cyclic year name. However, since this is for non gregorian calendars, like Chinese or Hindu calendars, and since L<DateTime> only supports gregorian calendar, we do not support it either.

=item * C<x>

Timezone, such as C<x> would be C<-08>, C<xx> C<-0800> or C<+0800>, C<xxx> would be C<-08:00> or C<+08:00>, C<xxxx> would be C<-0800> or C<+0000> and C<xxxxx> would be C<-08:00>, or C<-07:52:58> or C<+00:00>

=item * C<X>

Timezone, such as C<X> (C<-08> or C<+0530> or C<Z>), C<XX> (C<-0800> or C<Z>), C<XXX> (C<-08:00>), C<XXXX> (C<-0800> or C<-075258> or C<Z>), C<XXXXX> (C<-08:00> or C<-07:52:58> or C<Z>)

=back

t/002_format.t  view on Meta::CPAN

            {
                data => { year => 2024, month => 9, day => 9, hour => 7, minute => 12, second => 10, time_zone => 'UTC' },
                pattern => 'XXXXX',
                expects => 'Z',
            },
        ],
    },
    # NOTE: y (Calendar year numeric)
    {
        locale => 'en',
        name => 'calendar year numeric',
        tests => [
            {
                data => { year => 2024, month => 9, day => 9, hour => 7, minute => 12, second => 10, time_zone => 'UTC' },
                pattern => 'y',
                expects => '2024',
            },
            {
                data => { year => 2024, month => 9, day => 9, hour => 7, minute => 12, second => 10, time_zone => 'UTC' },
                pattern => 'yy',
                expects => '24',

t/002_format.t  view on Meta::CPAN

            {
                data => { year => 2024, month => 9, day => 9, hour => 7, minute => 12, second => 10, time_zone => 'UTC' },
                pattern => 'yyyyy',
                expects => '02024',
            },
        ],
    },
    # NOTE: Y (Week of Year)
    {
        locale => 'en',
        name => 'calendar year numeric',
        tests => [
            {
                data => { year => 2024, month => 9, day => 9, hour => 7, minute => 12, second => 10, time_zone => 'UTC' },
                pattern => 'Y',
                expects => '2024',
            },
        ],
    },
    # NOTE: z (zone)
    {



( run in 0.524 second using v1.01-cache-2.11-cpan-5dc5da66d9d )