ecma402 icon indicating copy to clipboard operation
ecma402 copied to clipboard

Negative Gregorian years do not render by default in DateTimeFormat

Open sffc opened this issue 4 years ago • 4 comments

In Chrome and Firefox, the following code loses the sign of the year.

new Date(-753, 5, 21).toLocaleDateString()
// "6/21/754"

My expected output would be for the Gregorian calendar to apply an era format automatically, producing "6/21/754 BC".

CC @FrankYFTang @jswalden @anba @justingrant

sffc avatar Nov 03 '20 07:11 sffc

The reason is era is not specified.

FrankYFTang avatar Nov 03 '20 07:11 FrankYFTang

The reason is era is not specified.

I get that; specifying era will work around the issue. The bug is that DateTimeFormat is taking a date which has a negative year, and is formatting it without any sign that it is negative. This is an incorrect result. DateTimeFormat should force the era field to be displayed when the year is negative, just like it forces the era field in the Japanese calendar and the day period field when a 12-hour clock is used.

sffc avatar Nov 03 '20 08:11 sffc

Let me mention the link with #426. In current life, when you mention a date, you do not specify "AD" or "Common Era", whereas you do when the year is before origin. The display tools (toString) and the formatting tools ( Intl.DateTimeFormat.format() ) should do the same.

Louis-Aime avatar Nov 04 '20 15:11 Louis-Aime

This issue is covered by the eraDisplay proposal.

sffc avatar Feb 10 '22 06:02 sffc