Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a date and timezone from GAE server to GWT client

OK folks, I have been going around this problem for about 2 weeks now trying everything I can think of and looking at tons of answers on here that feel like they are going to answer it, but I just cant work out how I am meant to do what I am trying to do and it is driving me absolutely NUTS! No one seems to have an answer anywhere, there are half answers all over the place, but none seem to actually do what I need it to do, surely SOMEONE has solved this problem before! Please excuse the REALLY long question, but its important that the question is asked right, so that the answers actually answer the need! :D

Also please don't bother reading any further if you are likely to provide any answer which does not take into account that my datastore/server is Google App Engine (GAE), and my Client is written in Google Web Toolkit (GWT) and everything is written in Java, I dont know anything about Python or MySQL or PHP or anything like that

Finally if anyone knows of a better place to figure stuff out like this, PLEASE do let me know as I keep coming up with issues like this and have no idea how to find a solution other than in here, or spend hours and hours searching google for someone else who has already managed to figure it out. I also dont understand how to figure anything out from JavaDocs - sorry, but until someone explains it to me, Im just not going to get it

I have a datetime stored on the server (in UTC obviously) I also have stored on the server a TimeZone for each business owner stored as a string (eg "America/New_York"). This string is obtained by using java.util.TimeZone.getAvailableIDs() on the server and getting the business owner to select the relavant timezone for their business (default is "Europe/London" if they don't choose anything - no need to get hung up on that bit) I need to pass any datetimes back to the client PC at some point in the future, IGNORING the local timezone on their PC, because the datetime needs to be displayed according to the timezone of the business owner.

So as an example the business owner is a hairdressers in London and they have an online appointment schedule which is available to be viewed by any potential customer of theirs. One of these customers (also in London) wants to book an appointment, sees a slot at 9am BST on Monday 3rd September and books it.

This is then stored in the Datastore as the UTC time (which is actually 0800 as BST is UTC+1), and of course the business owner has selected "Europe/London" as their timezone. Everything fine so far.

NOW, at some point in the future, the customer is on a business meeting in New York, and realises that they have an appointment the following week for a haircut in London and they want to move it by a week, so they then try to VIEW the appointment (in the hairdressers appointment book), but they don't want to see it as 4am New York Time, they want to see it as 9am British time.

So my problem is that when the customer clicks to VIEW appointments on 3rd September, the server can send back a UTC datetime of 0800 and a java.util.TimeZone ID String of "Europe/London"

But because on the client I can only use

com.google.gwt.i18n.client.TimeZone

it doesn't allow me to use the function

TimeZone bizTimeZone=TimeZone.getTimeZone("Europe/London")
(which works for `java.util.TimeZone`)

as it causes the error

"The method getTimeZone(String) is undefined for the type TimeZone"

it suggests changing it to

com.google.gwt.i18n.client.TimeZone.createTimeZone("Europe/London")

but this version, is expecting a GWT com.google.gwt.i18n.client.TimeZoneConstants "object" (example shown at the end of this message) and not the simple string that the java.util.TimeZone.createTimeZone() will accept.

I can create this by using:

final TimeZoneConstants constTz = GWT.create(TimeZoneConstants.class);
final TimeZone timeZoneCali = TimeZone.createTimeZone(constTz.europeLondon());

But I dont know how to do this when Im starting with "Europe/London" and/or I dont know how to store this object into the App Engine DataBase and then retrieve it later.

Incidentally amongst the commented text I have also tried using the following lines:

//Calendar tmad = new GregorianCalendar(TimeZone.getTimeZone("Europe/London"));
//Calendar cal = Calendar.getInstance(someTimeZone);
//DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//df1.setTimeZone(TimeZone.getTimeZone("Europe/London"));
//final TimeZone timeZoneClient = TimeZone.createTimeZone("Europe/London");
//dtf.format(date,timeZoneClient)

There MUST be a standard way of doing this SURELY, I really cant be the first person to ever have to solve this issue!

constTz.europeLondon()={"transitions": [19394, 60, 24770, 0, 28130, 60, 33506, 0, 36866, 60, 42242, 0, 45602, 60, 50978, 0, 54506, 60, 59714, 0, 63242, 60, 68450, 0, 71978, 60, 77354, 0, 80714, 60, 86090, 0, 89450, 60, 94826, 0, 98521, 60, 103561, 0, 107257, 60, 112297, 0, 115993, 60, 121033, 0, 124729, 60, 129937, 0, 133633, 60, 138673, 0, 142369, 60, 147409, 0, 151105, 60, 156145, 0, 159841, 60, 164881, 0, 168577, 60, 173785, 0, 177313, 60, 182521, 0, 186217, 60, 191257, 0, 194953, 60, 199993, 0, 203689, 60, 208729, 0, 212425, 60, 217465, 0, 221161, 60, 226201, 0, 230065, 60, 235105, 0, 238801, 60, 243841, 0, 247537, 60, 252577, 0, 256273, 60, 261481, 0, 265009, 60, 270217, 0, 273745, 60, 278953, 0, 282649, 60, 287689, 0, 291385, 60, 296425, 0, 300121, 60, 305329, 0, 308857, 60, 314065, 0, 317593, 60, 322801, 0, 326329, 60, 331537, 0, 335233, 60, 340273, 0, 343969, 60, 349009, 0, 352705, 60, 357913, 0, 361441, 60, 366649, 0, 370177, 60, 375385, 0, 379081, 60, 384121, 0, 387817, 60, 392857, 0, 396553, 60, 401593, 0, 405289, 60, 410497, 0, 414025, 60, 419233, 0, 422761, 60, 427969, 0, 431665, 60, 436705, 0, 440401, 60, 445441, 0, 449137, 60, 454345, 0, 457873, 60, 463081, 0, 466609, 60, 471817, 0, 475513, 60, 480553, 0, 484249, 60, 489289, 0, 492985, 60, 498025, 0, 501721, 60, 506929, 0, 510457, 60, 515665, 0, 519193, 60, 524401, 0, 528097, 60, 533137, 0, 536833, 60, 541873, 0, 545569, 60, 550777, 0, 554305, 60, 559513, 0, 563041, 60, 568249, 0, 571777, 60, 576985, 0, 580681, 60, 585721, 0, 589417, 60, 594457, 0], "names": ["GMT", "Greenwich Mean Time", "BST", "British Summer Time"], "id": "Europe/London", "std_offset": 0}

like image 870
johnvdenley Avatar asked Aug 16 '12 14:08

johnvdenley


1 Answers

I have a similar issue with v2.4.

I think Riley Lark is right.

TimeZone.createTimeZone("Asia/Tokyo") did not work in GWT 2.4

However, I found I could get the Tokyo zone by using the browser's default setting via:

Date d = new Date();
TimeZone timezone = TimeZone.createTimeZone(d.getTimezoneOffset());

That is really what Riley Lark is suggesting for you since europeLondon has "std_offset": 0...

TimeZone timezone = TimeZone.createTimeZone(0);

like image 145
user1258245 Avatar answered Oct 29 '22 12:10

user1258245