From 1b1bb39deb916c6492d284866a5e8894a8c9e2e9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 27 Nov 2012 11:22:28 -0800 Subject: [PATCH] ensure UTC can be used where GMT is --- .../java/org/jclouds/date/DateServiceTest.java | 7 ++++++- .../org/jclouds/date/joda/JodaDateService.java | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/test/java/org/jclouds/date/DateServiceTest.java b/core/src/test/java/org/jclouds/date/DateServiceTest.java index 8ad70ab51d..439c1b4203 100644 --- a/core/src/test/java/org/jclouds/date/DateServiceTest.java +++ b/core/src/test/java/org/jclouds/date/DateServiceTest.java @@ -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); diff --git a/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java b/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java index ff8b145f24..7927bb5985 100644 --- a/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java +++ b/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java @@ -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(); }