Skip to content
Permalink
Browse files

[FIXED JENKINS-17965 JENKINS-17383] parse timezone in server response

  • Loading branch information...
Michael Clarke
Michael Clarke committed Oct 21, 2013
1 parent 469bed8 commit 8432f1431829bb75ab305eec5b72da804e91272b
Showing with 19 additions and 2 deletions.
  1. +19 −2 src/main/java/org/netbeans/lib/cvsclient/response/ModTimeResponse.java
@@ -47,6 +47,7 @@
package org.netbeans.lib.cvsclient.response;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
@@ -68,6 +69,12 @@
*/
protected static final DateFormat dateFormatter;

private static final SimpleDateFormat rfc822DateFormats[] = new SimpleDateFormat[] {
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH),
new SimpleDateFormat("EEE, d MMM yyyy HH:mm z", Locale.ENGLISH),
new SimpleDateFormat("d MMM yyyy HH:mm z", Locale.ENGLISH),
new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.ENGLISH) };

/**
* The way the server formats dates
*/
@@ -95,9 +102,19 @@ public void process(final LoggedDataInputStream dis, final ResponseServices serv
// We remove the ending because SimpleDateFormat does not parse
// +xxxx, only GMT+xxxx and this avoid us having to do String
// concat
final Date date;
Date date = null;
synchronized (dateFormatter) {
date = dateFormatter.parse(dateString.substring(0, dateString.length() - 6));
for (DateFormat dateFormat : rfc822DateFormats) {
try {
date = dateFormat.parse(dateString);
break;
} catch (ParseException ex) {
//ignore - we'll fall through to another format
}
}
if (date == null) {
date = dateFormatter.parse(dateString.substring(0, dateString.length() - 6));
}
}
if (date.getTime() < 0) {
// now we're in trouble - see #18232 issue.

0 comments on commit 8432f14

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