DateTimeFormat issue

102 views
Skip to first unread message

Freddy Boucher

unread,
Sep 18, 2016, 9:39:08 PM9/18/16
to GWT Users
Hi,

Can someone help me to understand why this test fails (I'm using GWT 2.7.0):

package com.threatmetrix.ccc.portal.widgets.barchart.client;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.TimeZone;
import com.google.gwtmockito.GwtMockitoTestRunner;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Date;

@RunWith(GwtMockitoTestRunner.class)
public class DateTimeTest {
   
@Test
    public void working() {
       
Date date = new Date(1457395200000l);
       
DateTimeFormat format = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.ISO_8601);
       
String formattedDate = format.format(date, TimeZone.createTimeZone(0));

       
Assert.assertEquals("2016-03-08T00:00:00.000+00:00", formattedDate);
       
Assert.assertEquals(date, format.parse(formattedDate));
   
}


   
@Test
    public void notWorking() {
       
Date date = new Date(1459639080000l);
       
DateTimeFormat format = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.ISO_8601);
       
String formattedDate = format.format(date, TimeZone.createTimeZone(0));

       
Assert.assertEquals("2016-04-03T23:18:00.000+00:00", formattedDate);
       
Assert.assertEquals(date, format.parse(formattedDate));
   
}
}

Results:
  • DateTimeTest#working(): OK
  • DateTimeTest#notWorking(): there is a difference of 1 day between the Expected and the Actual date

Log:

java.lang.AssertionError: 
Expected :Sun Apr 03 09:18:00 AEST 2016
Actual   :Mon Apr 04 09:18:00 AEST 2016
  <Click to see difference>



at com.threatmetrix.ccc.portal.widgets.barchart.client.DateTimeTest.notWorking(DateTimeTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.gwtmockito.GwtMockitoTestRunner.run(GwtMockitoTestRunner.java:301)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Thanks.

Paul Robinson

unread,
Sep 19, 2016, 7:10:21 AM9/19/16
to google-we...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Freddy Boucher

unread,
Sep 19, 2016, 9:17:56 PM9/19/16
to GWT Users
Thanks!

I tested the patch and it fixes the issue.

I opened a GitHub ticket to track it: https://github.com/gwtproject/gwt/issues/9427

To post to this group, send email to google-we...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages