Skip to content
Permalink
Browse files

[Fix JENKINS-29857] Java 6 refuses X argument for date parsing

  • Loading branch information...
MarkEWaite committed Aug 8, 2015
1 parent 8c29e95 commit c6f0d49815a6f0a22e97b0acb73ca5b80aa3ac9d
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/main/java/hudson/plugins/git/GitChangeSet.java
@@ -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;
}
}
}

0 comments on commit c6f0d49

Please sign in to comment.
You can’t perform that action at this time.