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
Cheers
Chris
private void formatEra(StringBuffer buf, int count, Date date) {
int value = date.getYear() >= -JS_START_YEAR ? 1 : 0;
if (count >= 4) {
buf.append(dateTimeConstants.eraNames()[value]);
} else {
buf.append(dateTimeConstants.eras()[value]);
}
}
private void formatYear(StringBuffer buf, int count, Date date) {
int value = date.getYear() + JS_START_YEAR;
if (value < 0) {
value = -value;
}
if (count == 2) {
zeroPaddingNumber(buf, value % 100, 2);
} else {
// count != 2
buf.append(Integer.toString(value));
}
}
--
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.