Menu

#53 ParseDate fails on specific dates

Outstanding
closed
nobody
None
1
2014-07-21
2014-07-20
No

The ParseDate cellProcessor generates a ParseException for valid datetimes around March 29, 2014, 0200 UTC.

example date: "2014-03-09T02:06:21.000Z"
example format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

code to reproduce:

public static void main(String[] args) {
ParseDate parser = new ParseDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String format = "2014-03-09T%02d:%02d:21.000Z";

for (int i = 0; i < 60; i++) {
    String date = String.format(format, 2, i);
    try {
        parser.execute(date, null);
        System.out.println("pass: " + date);
    }
    catch (SuperCsvCellProcessorException e) {
        System.out.println("fail: " + date);
    }
}

for (int i = 0; i < 24; i++) {
    String date = String.format(format, i, 49);
    try {
        parser.execute(date, null);
        System.out.println("pass: " + date);
    }
    catch (SuperCsvCellProcessorException e) {
        System.out.println("fail: " + date);
    }
}

}

result:

anything within hour 02 hour will fail, times in any other hour pass.

SimpleDateFormat.parse works fine with the same format string on all these dates.

Discussion

  • Jonathan Esterhazy

    nvm. SimpleDateFormat is lenient by default, and fails on same dates when lenient is false.

     
  • Kasper B. Graversen

    I think it could be something with daylight savings?

     
    • Jonathan Esterhazy

      Yes... the dates were being parsed as my local time zone, not UTC. DST
      meant that hour didn't exist in local TZ (US/Pacific). After fixing TZ
      problem, ParseDate works as expected.

       

      Last edit: Jonathan Esterhazy 2014-07-20
  • James Bassett

    James Bassett - 2014-07-21
    • status: open --> closed
     

Log in to post a comment.