change DateBox default time

1,729 views
Skip to first unread message

Joey Li

unread,
Aug 16, 2012, 12:26:23 AM8/16/12
to google-we...@googlegroups.com
I try to use GWT DateBox. When i click the DatePicker, the date and time will be shown in the box. But it looks like the default time is 12:00pm (noon)
For example, If I picked 2012, Aug, 16th in the datePicker, and my code is the following:
date.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("yyyy-MMM-dd HH:mm:ss a")));
Then it will show [2012-Aug-16 12:00:00 pm] in the box.
1. How can I change the default time to midnight, which is  [2012-Aug-16 00:00:00 am].

Also, I found that if I try to show my TimeZone by writing the following: date.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("yyyy-MMM-dd HH:mm:ss a z"))); it shows my timezone is UTC-4:00.
But in my computer, my timezone is UTC-5:00.

2. Why the TimeZone is not the same as my computer. Did I write anything wrong there? Isn't it suppose to be the same the client's timezone? If not, how to make the GWT show my timezone (Client's timezone).

Thanks.



Jens

unread,
Aug 16, 2012, 4:45:37 AM8/16/12
to google-we...@googlegroups.com

1. How can I change the default time to midnight, which is  [2012-Aug-16 00:00:00 am].

The DatePicker sets the time to 12:00 pm because some countries seems to do their day light saving correction at 0:00 am (which would mean that 0:00 am would not exists on these days because it becomes 1:00 am). Not sure where exactly when 12:00 is set but one method in GWT that does this correction is CalendarUtil.resetTime(). Maybe thats a good starting point for reference searches.
 
2. Why the TimeZone is not the same as my computer. Did I write anything wrong there? Isn't it suppose to be the same the client's timezone? If not, how to make the GWT show my timezone (Client's timezone).

Do you have daylight saving time where you live? It could very well be that the browser thinks no DST is active while your computer does think it is active. I recently had some problems with DST, you can read it up here: https://groups.google.com/d/topic/google-web-toolkit/e7IqbcJIzTY/discussion

-- J.

Joey Li

unread,
Aug 16, 2012, 1:06:51 PM8/16/12
to google-we...@googlegroups.com
there is DST in where I am living. In my app, I want to show users their correct TimeZone no matter where they live. For example, in Eastern America/Canada users, the app shoulde show UTC-5 in summer time( DST ), and In winter, it should show UTC-4 (PDT).
However, my app is always showing UTC-4 no matter we are using DST or PDT.  Is there any way to fix this or any workaround?

Joey Li

unread,
Aug 16, 2012, 1:24:50 PM8/16/12
to google-we...@googlegroups.com
Oh, never mind. I made a mistake. UTC-4 is what it should be right now. The clock in computer shows that I am at UTC-5 which is the standard time. It does not consider DST time. UTC-4 should be the correct one. So my 2nd question is resolved. Computer Clock makes me confused and thought my app is incorrect.

I am still struggling with my 1st problem. How to change the default time in datebox from noon to midnight.. Jens suggests using CalendarUtil.resetTime() , but i have no idea how.
any ideas?
Thanks

Andrei

unread,
Aug 16, 2012, 1:43:59 PM8/16/12
to google-we...@googlegroups.com
There is no such thing as "00:00 am" :)  Midnight is 12:00 pm, so there is no problem in your app.

Jens

unread,
Aug 16, 2012, 2:11:14 PM8/16/12
to google-we...@googlegroups.com

There is no such thing as "00:00 am" :)  

Hehe yeah I am used to 24 hours and I actually meant 12:00 a.m. = 00:00 (24-hour clock) = midnight. So some countries activate their DST on midnight and thats why GWTs date picker chooses noon by default.
 
Midnight is 12:00 pm, so there is no problem in your app.

Midnight is 12:00 a.m. and Noon is 12:00 p.m. See: http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight 

-- J.

Jens

unread,
Aug 16, 2012, 2:19:08 PM8/16/12
to google-we...@googlegroups.com

Jens suggests using CalendarUtil.resetTime() , but i have no idea how.

I suggested to do reference searches in your IDE starting from that method and to find out how the date picker may uses this method indirectly. Then you can see what you need to overwrite to change the DatePicker behavior.

DatePicker allows you do provide custom implementations for MonthSelector, CalendarView and CalendarModel via its constructor (http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/user/datepicker/client/DatePicker.html). I guess a custom CalendarModel is what you need but I am not sure about it as I have never customized DatePicker so far.

-- J.

Andrei

unread,
Sep 7, 2012, 9:33:08 AM9/7/12
to google-we...@googlegroups.com
Jens,

You were right about DatePicker setting dates to noon. I created an issue:


It's a minor problem, of course, since you can always do

Long date = datePicker.getValue().getTime();
return new Date(date - date % (24 * 60 * 60 * 1000));

to set any date object to midnight. Still, it was a headache as I was implementing time zone management in my app. Thank you for pointing this issue.

Andrei

Patrick Tucker

unread,
Sep 7, 2012, 10:03:39 AM9/7/12
to google-we...@googlegroups.com
They chose to set it to noon because certain timezones do not have a 0 at day light savings time.  If you set the time to 0 on one of these date/timezone combinations, if I understood correctly, the date will roll back and not forward.  Causing the date to be set to the previous day instead of the correct day.
 
I'm not sure I agree with the solution but it is probably the simplest solution with the least amount of overhead.  It is what it is...
 
I don't recall where this was recorded, but if you do some digging there are issues or threads out there with more information.  Also, the problem has been recorded in the issue tracker: http://code.google.com/p/google-web-toolkit/issues/detail?id=4785

Jens

unread,
Sep 7, 2012, 10:32:03 AM9/7/12
to google-we...@googlegroups.com
Noon is totally fine because of DST that can occur at midnight in some countries. You would get an invalid date otherwise.

Assume a country does its DST on 20.06.2012 12:00:00 a.m (midnight). The valid dates are 

19.06.2012 11:59:59 p.m. 
20.06.2012 01:00:00 a.m. (DST active. There is no 20.06.2012 12:00:00 a.m.)

Thats why GWT has chosen noon as default time in DatePicker. That way you are still correct if you choose a day on which DST will be activated.

-- J.


Reply all
Reply to author
Forward
0 new messages