ensure UTC can be used where GMT is

This commit is contained in:
Adrian Cole 2012-11-27 11:22:28 -08:00
parent c5215f9c48
commit 60454274de
2 changed files with 17 additions and 10 deletions

View File

@ -180,7 +180,12 @@ public class DateServiceTest extends PerformanceTest {
Date date = dateService.fromSeconds(seconds);
assertEquals(dateService.iso8601SecondsDateFormat(date), "2009-09-26T23:37:05Z");
}
@Test
void testUTCIsGMT() {
assertEquals(dateService.iso8601SecondsDateParse("2012-11-26T17:32:31UTC+0000").getTime(), dateService.iso8601SecondsDateParse("2012-11-26T17:32:31UTC+0000").getTime());
}
@Test
void testTz() {
assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T02:14:13-04:00").getTime(), 1306390453000l);
@ -263,4 +268,4 @@ public class DateServiceTest extends PerformanceTest {
executeMultiThreadedPerformanceTest("testParseIso8601DatePerformanceInParallel", tasks);
}
}
}

View File

@ -113,22 +113,24 @@ public class JodaDateService implements DateService {
public final Date iso8601DateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
String tz = findTZ(toParse);
toParse = trimToMillis(toParse);
toParse = trimTZ(toParse);
toParse += tz;
toParse = adjustTz(toParse);
if (toParse.charAt(10) == ' ')
toParse = new StringBuilder(toParse).replace(10, 11, "T").toString();
return iso8601DateFormatter.parseDateTime(toParse).toDate();
}
public final Date iso8601SecondsDateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
private String adjustTz(String toParse) {
String tz = findTZ(toParse);
toParse = trimToMillis(toParse);
toParse = trimTZ(toParse);
toParse += tz;
return toParse.replace("UTC", "");
}
public final Date iso8601SecondsDateParse(String toParse) {
if (toParse.length() < 10)
throw new IllegalArgumentException("incorrect date format " + toParse);
toParse = adjustTz(toParse);
return iso8601SecondsDateFormatter.parseDateTime(toParse).toDate();
}
@ -146,4 +148,4 @@ public class JodaDateService implements DateService {
public final Date rfc1123DateParse(String toParse) {
return rfc1123DateFormat.parseDateTime(toParse).toDate();
}
}
}