robisim74 / angular-l10n

Angular library to translate texts, dates and numbers
MIT License
380 stars 59 forks source link

Incorrect date format #337

Closed andreiflorian closed 2 years ago

andreiflorian commented 2 years ago

Hi,

I'm using this library to translate and format dates, numbers in my application. After update to version 13 'short' date format use only 2 digits for the year. Intl.DateTimeFormat use 4 digits for 'short' date format. How can I use 4 digits instead of 2 ?

robisim74 commented 2 years ago

Hi @andreiflorian ,

that's wired, because the library has always used a custom parser for dateStyle: 'short': projects/angular-l10n/src/lib/models/utils.ts, to support old browsers and to follow Angular DatePipe format.

Hovewer, you can override the behavior in two ways: 1) remove the options object and get the default Intl behavior:<p>{{ today | l10nDate:locale.language }}</p> 2) force always to 4 digits: <p>{{ today | l10nDate:locale.language:{ dateStyle: 'short', year:'numeric'} }}</p>

andreiflorian commented 2 years ago

Hi @robisim74,

Thanks for solution. It works.

Actually I upgraded from version 7.2.0 to latest version. I think in 7.2.0 the date format was done with other library or in other way, I didn't checked that.