PDA

View Full Version : Arizona Problem



neelepl
3 Jan 2012, 12:43 AM
In my application I am showing a window with start and end of week date.

For that I am using the code like:
Date start = getDate(getThisWeek(), 7 * offset + 1);
and,
private static Date getThisWeek() {
Calendar calendar = Calendar.getInstance();
//Sunday Issue
if(calendar.getTime().getDay() == 0){
calendar.add(Calendar.DATE, -7);
}
calendar.set(Calendar.DAY_OF_WEEK, 1);
return getOnlyDate(calendar.getTime());
}
and,
public static Date getDate(Date dt, int offset) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dt);
calendar.add(Calendar.DAY_OF_YEAR, offset);
return getOnlyDate(calendar.getTime());
}

getOnlyDate method is setting the hour, min and seconds to zero.

and offset value is 0 for current week, 1 for next week and -1 for prev week.

So the ultimate result is like start of week is always Monday date and end of week is always Sunday.
So on Jan 3, if we hit the system it will show the start of week as Jan 2 and end of week as Jan 8.

But when we are changing the local machine timezone to Arizona..it is going one day back, means it is showing start of week as Jan 1 and end of week as Jan 7.

When I am trying to debug, it is showing proper date as expected. But when the code is deployed on server and timezone is changed to Arizona it is giving the problem. For any other timezone it is showing correctly.

Can anyone suggest any solution...I am really out of clue :((. Is there any way to send client timezone to server? I am using GXT framework. The server is located at Detroit(USA).

PhiLho
4 Jan 2012, 5:05 AM
That's more a Java problem than a GWT/GXT one... ;)

But well, have you tried to use Calendar.getInstance() with a time zone parameter (instead of using the default, system one)? Using a reference time zone might help, if I understood correctly your issue (time zone and DST issues are always hard to fix...).

neelepl
10 Jan 2012, 10:23 PM
Using Calendar.getInstance() in server will always give the server timezone only...in my case it will be Detroit( USA), so it won't come into my help...I like to ask the same question...without prompting user to input their timezone, is there any way we can send client timezone to server?

PhiLho
11 Jan 2012, 1:46 AM
Ah, I missed this question. To my knowledge (I just checked), the client doesn't send time information in their GET/POST requests. So, no timezone available directly.
Perhaps your best bet is to analyze the IP address with a geo-localization service / database. Not very precise, but generaly enough for TZ info.
Or, indeed, just ask the user.