Skip to content

Commit

Permalink
[Fix JENKINS-29857] Java 6 refuses X argument for date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Aug 8, 2015
1 parent 8c29e95 commit c6f0d49
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/hudson/plugins/git/GitChangeSet.java
Expand Up @@ -214,6 +214,19 @@ public long getTimestamp() {
return new SimpleDateFormat(ISO_8601_WITH_TZ).parse(getDate()).getTime();
} catch (ParseException e) {
return -1;
} catch (IllegalArgumentException ia) {
/* Java 6 does not accept "X" as a format string, use "Z"
* instead and remove the ':' from the source time zone
* string to satisfy that format string.
* http://stackoverflow.com/questions/15505658/unparseable-date-using-dateformat-parse
*/
final String java6FormatDef = ISO_8601_WITH_TZ.replace("X", "Z");
final String java6Date = getDate().replaceAll(":(\\d\\d)$", "$1");
try {
return new SimpleDateFormat(java6FormatDef).parse(java6Date).getTime();
} catch (ParseException e) {
return -1;
}
}
}

Expand Down

0 comments on commit c6f0d49

Please sign in to comment.