ensure UTC can be used where GMT is

This commit is contained in:
Adrian Cole 2012-11-27 11:22:28 -08:00
parent fcde81ea7c
commit 1b1bb39deb
2 changed files with 15 additions and 8 deletions

View File

@ -181,6 +181,11 @@ public class DateServiceTest extends PerformanceTest {
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);

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();
}