Skip to content

Commit

Permalink
[FIXED JENKINS-17965 JENKINS-17383] parse timezone in server response
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Clarke committed Oct 21, 2013
1 parent 469bed8 commit 8432f14
Showing 1 changed file with 19 additions and 2 deletions.
Expand Up @@ -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;
Expand All @@ -68,6 +69,12 @@ class ModTimeResponse implements Response {
*/
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
*/
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8432f14

Please sign in to comment.