Closed Bug 923639 Opened 11 years ago Closed 7 years ago

Date.prototype.toLocaleFormat() returns unexpected values for years < 1900

Categories

(Core :: JavaScript Engine, defect)

24 Branch
x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 818634

People

(Reporter: c.c.williams, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0 (Beta/Release) Build ID: 20130910160258 Steps to reproduce: (new Date(1898, 0, 2, 12, 0, 0, 0)).toLocaleFormat("%C") (new Date(-1, 0, 2, 12, 0, 0, 0)).toLocaleFormat("%y") (new Date(-1, 0, 2, 12, 0, 0, 0)).toLocaleFormat("%Y") User agent string, for reference, is: "Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0" Actual results: "99" "99" "-1" Expected results: "18" ( == Math.floor(1898 / 100) ) "01" "-0001" (%Y should be four digits if I'm interpreting the strftime documentation correctly)
Manye bugs have been filed about "date" issues, like bug 868496, bug 911649.
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
I can confirm the *results*, but I cannot confirm the bug because the "expected results" are arguable. I would split this bug to three child bugs if I were you, one for each format. For %C, yes, it is indeed a bug for year between 1 and 1899. By the way, it's totally broken for Windows platform. For year 0, it's arguable in definition whether it exists or not -- AFAIK, in ISO8601, year 0 = 1 BC, so it's quite confusing. For years less than 0, maybe they are simply undefined as far as JavaScript is concerned at current stage? CF notes below For %y, for year bigger than 0, the result is correct. So the summary is not correct for this case. Problem arises when year is less than 0 and we're back to the same discussion above for %C. For %Y, it's never written that %Y should be four digits. From http://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html : %Y is replaced by the year with century as a decimal number. (new Date(993, 0, 2, 12, 0, 0, 0)).toLocaleFormat("%Y") gives 993 seems alright to me. But for (new Date(-1, 0, 2, 12, 0, 0, 0)).toLocaleFormat("%Y") which gives -1 it's hard to say. Either it should be undefined, or it should be -1XX because century zero does not exist. ________ After a rough reading, I can only find the following extracts relevant to our problem here. Note#1: (Extracted ECMAScript Edition 5) To represent years before 0 or after 9999, ISO 8601 permits the expansion of the year representation, but only by prior agreement between the sender and the receiver. Note#2:(Extracted from ISO 8601:2004) Calendar years are numbered in ascending order according to the Gregorian calendar by values in the range [0000] to [9999]. Values in the range [0000] through [1582] shall only be used by mutual agreement of the partners in information interchange.
toLocaleFormat was removed in bug 818634.
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.