mirror of https://github.com/apache/jclouds.git
ensure UTC can be used where GMT is
This commit is contained in:
parent
fcde81ea7c
commit
1b1bb39deb
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue