Monday, September 19, 2016

Re: DateTimeFormat issue


On Mon, Sep 19, 2016 at 2:39 AM, Freddy Boucher <freddy.boucher@gmail.com> wrote:
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.

--
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+unsubscribe@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.

--
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+unsubscribe@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.

No comments:

Post a Comment