Search code examples
javagwtdatetimetimezonesmartgwt

SmartGWT timezones


I'm trying to figure out how to use SmartGWT's TimeItem, Calendar and DateItem. I'm stuck since all of these components convert their data to client's timezone. For the sake of the argument let us take TimeItem.

I have a DynamicForm which has a TimeItem inside if you set the value to (Java.Util.Date)12:00 the dynamicform displays 19:30. If you get that value via TimeItem.getValue it returns (com.smartgwt.client.util.LogicalTime)13:30. The code example is below

    DateTimeFormat timeFormatter = DateTimeFormat.getFormat("HHmmss");

    layout = new VLayout();
    form = new DynamicForm();
    item = new TimeItem("TIME","TIME");
    form.setItems(item);
    layout.addMember(form);
    Button btn = new Button("put");
    btn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Date parse = timeFormatter.parse("120000");
            System.out.println(parse.toString());// prints out Tue Aug 20 12:00:00 VET 2013
            form.getField("TIME").setValue(parse); // sets 19:30 seen by the user
            //form.getField("TIME").setValue("120000");
        }
    });

    Button btn2 = new Button("get");
    btn2.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Object value = form.getField("TIME").getValue();
            System.out.println(value.toString());// prints out Thu Jan 01 13:30:00 VET 1970
            //However if the value is set using a simple string,
            //(like so "form.getField("TIME").setValue("120000");")
            //this line
            //prints out Thu Jan 01 06:00:00 VET 1970
        }
    });

    layout.addMember(btn);
    layout.addMember(btn2);

    layout.draw();

My computers timezone is set to: (UTC+02:00) Istanbul, if that clears anything up

Thank you in advance for any help.


Solution

  • This is really interesting a friend of mine told me that this was due to some annoying behaviour on Windows. I've no idea why or how but the solution is as follows. If my time zone is set to +2 Istanbul the above bug can be reproduced however if i change my time zone settings on my machine to Athens +2 the bug disappears so... All I did was change my settings such that my time zone is set to Athens +2. Hope this helps anybody in the future.