Menu

#5 testDateConversions fails with GMT-14

rel-1.1.18
closed-fixed
None
5
2015-12-27
2015-12-10
No

Hi,

testDateConversions in TestBeanConverter fails when the system timezone is set to GMT-14 (with dpkg-reconfigure tzdata on Debian/Ubuntu systems).

Here is the error:

Tests run: 28, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.03 sec <<< FAILURE! - in net.sf.practicalxml.converter.bean.TestBeanConverter
testDateConversions(net.sf.practicalxml.converter.bean.TestBeanConverter) Time elapsed: 0.007 sec <<< ERROR!
net.sf.practicalxml.converter.ConversionException: unable to parse: Thu Aug 29 13:12:27 GMT+14:00 2013
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.parseDateDefault(Xml2BeanConverter.java:536)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.tryConvertAsDate(Xml2BeanConverter.java:304)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.convertWithoutCast(Xml2BeanConverter.java:156)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.convertChildren(Xml2BeanConverter.java:480)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.tryConvertAsBean(Xml2BeanConverter.java:350)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.convertWithoutCast(Xml2BeanConverter.java:160)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.convert(Xml2BeanConverter.java:109)
at net.sf.practicalxml.converter.BeanConverter.convertToJava(BeanConverter.java:114)
at net.sf.practicalxml.converter.BeanConverter.convertToJava(BeanConverter.java:96)
at net.sf.practicalxml.converter.bean.TestBeanConverter.testDateConversions(TestBeanConverter.java:488)
Caused by: java.text.ParseException: Unparseable date: "Thu Aug 29 13:12:27 GMT+14:00 2013"
at java.text.DateFormat.parse(DateFormat.java:366)
at net.sf.practicalxml.converter.bean.Xml2BeanConverter.parseDateDefault(Xml2BeanConverter.java:531)
... 31 more

Discussion

  • Keith D Gregory

    Keith D Gregory - 2015-12-10
    • assigned_to: Keith D Gregory
     
    • Keith D Gregory

      Keith D Gregory - 2015-12-10

      I will take a look at this in the next few days. I'm surprised by the output: it appears to be a standard toString(), whereas I believe it should be ISO 8601 format.

       
  • Keith D Gregory

    Keith D Gregory - 2015-12-20

    I was unable to reproduce this.

    I started by simply trying to parse the specified date on my development machine and was successful, using the following program:

    public static void main(String[] argv) throws Exception
    {
        System.out.println("running on" + System.getProperty("java.version"));
    
        Date now = new Date();        
        SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
        String str = fmt.format(now);
        System.out.println(str);
        System.out.println(fmt.parse(str));
    }
    

    Then I spun up an EC2 instance (AMI: ubuntu-trusty-14.04-amd64-server-20150325), and ran dpkg-reconfigure tzdata to set the timezone to GMT-14. Running the test program (which printed and parsed the current date) I got the following output:

    Mon Dec 21 13:19:45 GMT+14:00 2015

    It seems strange that I set the timezone to GMT-14 but the output was GMT+14 (when, if anything, I would have expected GMT+10). But the program successfully formatted and parsed the date.

    I then built practicalxml using the following JDK installs:

    • jdk1.6.0_45
    • jdk1.7.0_79
    • jdk1.8.0_31
    • openjdk-7-jdk (1.7.0_91, installed via apt-get)

    Unless you can provide a specific Java and/or Ubuntu version that causes this this to fail, I have to close the issue.

     
  • Emmanuel Bourg

    Emmanuel Bourg - 2015-12-21

    I managed to reproduce this test failure with:

    • practicalxml trunk (revision 305)
    • Debian 8 "Jessie"
    • openjdk-7-jdk or openjdk-8-jdk
    • dpkg-reconfigure tzdata -> GMT-14
    • dpkg-reconfigure locales -> fr_FR.UTF-8
    • logout and log back in
     

    Last edit: Emmanuel Bourg 2015-12-21
  • Keith D Gregory

    Keith D Gregory - 2015-12-27

    It was actually the French locale setting that did it.

    Date.toString() formats strings using en_US always, where DateFormat.parse() attempts to match locale-specific day and month names. Decimal conversions are also affected, as the decimal point is replaced by a comma.

    I think that the appropriate solution is to explicitly set the locale on these formats. For decimals it's easy, because that's required by the spec. For dates it's a little less obvious, however the goal is to handle default formatting, and that's what the JDK (currently) does.

     
  • Keith D Gregory

    Keith D Gregory - 2015-12-27

    Updates made, and released as 1.1.19.

    Tested with:

    • Maven 2.2, Oracle JDK 1.6
    • Maven 3.3, Oracle JDK 1.7 and 1.8
    • Maven 3.3, OpenJDK 1.7
     

    Last edit: Keith D Gregory 2015-12-27
  • Keith D Gregory

    Keith D Gregory - 2015-12-27
    • status: open --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.