The formats returned by "$locale->available_formats" are keys that you use
to access the localized format from "$locale->format_for($key)".

So what you wanted to write was this:

```
use DateTime;

my $dt = DateTime->now( locale => 'en-US' );

for my $fmt ( $dt->locale->available_formats ) {
    my $val = $dt->format_cldr( $dt->locale->format_for($fmt) );
    say "$fmt : $val";
}
```

Each locale will implement some subset of the possible keys, but the keys
themselves are the same between locales. In other words, for all locales
that have a format for "abbreviated month with numeric day", the key will
be "MMMd", but the actual formats returned by `$local->format_for('MMMd')`
will differ.


Cheers,

Dave Rolsky
http://blog.urth.org
https://github.com/autarch


On Tue, Feb 23, 2021 at 11:27 PM BPJ <melr...@gmail.com> wrote:

> Please consider this code:
>
> ``````perl
> use DateTime;
>
> my $dt = DateTime->now( locale => 'sv' );
>
> for my $fmt ( $dt->locale->available_formats ) {
>   my $val = $dt->format_cldr($fmt);
>   say "$fmt : $val";
> }
> ``````
>
> Most of the formatted strings seem to be missing some whitespace and have
> things in a surprisising order.
> E.g. `MMMd` gives `feb.23` where I would have expected `23 feb.`.
>
> I don't know if/what I'm doing wrong, or whether this is a DateTime,
> DateTime::Locale or CLDR bug or indeed if it is a bug at all.
>
>
> --
> Better --help|less than helpless
>

Reply via email to