Thanks for testing it on so many browsers! The one browser that I was using was the hosted browser, and that's where it fails.
Thank you. It's the first time I experience something that's different from Firefox/IE/etc. to hosted browser, and I guess can be different from browser to browser. Will be more vigilient in the future. Thanks for the pointers. Chris On Dec 3, 12:50 am, Thomas Broyer <[email protected]> wrote: > On 2 déc, 21:32, Chris <[email protected]> wrote: > > > > > Hi > > > I have a small question about GWT DateTimeFormat. I'm trying to > > display a date with the format: > > > "yyyy G" (ie. 1AD, 100BC, 3000BC) etc. > > > so i create my new Date and format it: > > Date d = new Date(-156805891175010L); > > new DateTimeFormat("yyyy G").format(d) > > > Unfortunately I get 3000AD which is incorrect. I should be 3000BC. > > Looking at the date object, I can see it represented as "B.C.E. > > 3000-02-01T00:00:24.990Z" which therefore looks alright... > > > Am I doing something wrong? Is this a bug? Can anyone thing of a work > > around? > > > It seems the DateTimeFormat gets the year right, but it comes to the > > Era, it does some crazy comparaison, which I don't really understand: > > > date.getYear() >= - JS_START_YEAR > > > How is this ever supposed to work? > > So for 3000BC, I might get +1100 for Date.getYear() and yet it's in > > the BC ERA. Using the comparaison: > > > -1100 >= -1900 so we end up with AD > > For 3000BC, getYear() returns -3000 - 1900 = -4900 (verified in > Chrome, IE8, FF3.5 and Opera 10.10). > -4900 < -1900, so 'value' should be 0 in formatEra, so era should be > "BC" > > (note: date.getYear() >= -JS_START_YEAR is equivalent to date.getYear > () + JS_START_YEAR >= 0, which is adjusting the date from Java's "1900 > is 0" to "1900 really is 1900", but involves a bit less computations) > > But it seems browsers are not very good when dealing with dates far in > the past (tested Chrome 3, FF3.5, IE8 and Opera 10.10): > - IE8's toJSON() has a leading 0 in front of the minus sign > ("0-2999-01-08T00:00:24Z") > - IE8 and Opera's getYear() return -2999 instead of -4899 > (fortunately, GWT uses getFullYear() which is OK in all four tested > browsers) > - Chrome and FF3.5 are unable to parse negative years from strings > (new Date(d.toString()) is an invalid date, Date.parse(d.toString()) > returns null) > - Opera mistakenly ignores years before 1000 when parsing strings, > and substitutes the current year (new Date("Thu, Jan 08 -2999 00:00:24 > GMT").toUTCString() returns "Thu, Jan 08 2009 00:00:24 GMT") > - IE8 uses the "B.C." annotation to denote negative years in toString > () and toUTCString(), and it will only parse years as negative if > using this notation too ("-2000" will be parsed as "2000", whereas > "2000 BC" will be parsed as "2000 B.C.") -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
