mirror of https://github.com/apache/jclouds.git
silently parse mildly incorrect dates
This commit is contained in:
parent
296462ecb5
commit
2cd11f6b18
|
@ -138,6 +138,8 @@ public class SimpleDateFormatDateService implements DateService {
|
||||||
toParse = trimToMillis(toParse);
|
toParse = trimToMillis(toParse);
|
||||||
toParse = trimTZ(toParse);
|
toParse = trimTZ(toParse);
|
||||||
toParse += tz;
|
toParse += tz;
|
||||||
|
if (toParse.charAt(10) == ' ')
|
||||||
|
toParse = new StringBuilder(toParse).replace(10, 11, "T").toString();
|
||||||
synchronized (iso8601SimpleDateFormat) {
|
synchronized (iso8601SimpleDateFormat) {
|
||||||
try {
|
try {
|
||||||
return iso8601SimpleDateFormat.parse(toParse);
|
return iso8601SimpleDateFormat.parse(toParse);
|
||||||
|
|
|
@ -168,6 +168,11 @@ public class DateServiceTest extends PerformanceTest {
|
||||||
assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T02:14:13-04:00").getTime(), 1306390453000l);
|
assertEquals(dateService.iso8601SecondsDateParse("2011-05-26T02:14:13-04:00").getTime(), 1306390453000l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTzNoT() throws ExecutionException, InterruptedException {
|
||||||
|
assertEquals(dateService.iso8601DateParse("2011-05-25 16:12:21.656+0000").getTime(), 1306339941656l);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRfc822DateFormatResponseTime() throws ExecutionException, InterruptedException {
|
void testRfc822DateFormatResponseTime() throws ExecutionException, InterruptedException {
|
||||||
for (int i = 0; i < LOOP_COUNT; i++)
|
for (int i = 0; i < LOOP_COUNT; i++)
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class DateUtilsTest {
|
||||||
assertEquals("NO_MILLIS.123Z", DateUtils.trimToMillis("NO_MILLIS.12345690123345678Z"));
|
assertEquals("NO_MILLIS.123Z", DateUtils.trimToMillis("NO_MILLIS.12345690123345678Z"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this test is failing on my jvm which is in IST
|
@Test
|
||||||
@Test(enabled = false)
|
|
||||||
public void testTrimsToMillisNoTimezone() {
|
public void testTrimsToMillisNoTimezone() {
|
||||||
assertEquals("NO_MILLIS", DateUtils.trimToMillis("NO_MILLIS"));
|
assertEquals("NO_MILLIS", DateUtils.trimToMillis("NO_MILLIS"));
|
||||||
assertEquals("NO_MILLIS.1", DateUtils.trimToMillis("NO_MILLIS.1"));
|
assertEquals("NO_MILLIS.1", DateUtils.trimToMillis("NO_MILLIS.1"));
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.date.joda;
|
package org.jclouds.date.joda;
|
||||||
|
|
||||||
import static org.jclouds.date.internal.DateUtils.*;
|
import static org.jclouds.date.internal.DateUtils.findTZ;
|
||||||
import static org.jclouds.date.internal.DateUtils.trimToMillis;
|
|
||||||
import static org.jclouds.date.internal.DateUtils.trimTZ;
|
import static org.jclouds.date.internal.DateUtils.trimTZ;
|
||||||
|
import static org.jclouds.date.internal.DateUtils.trimToMillis;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -112,6 +112,8 @@ public class JodaDateService implements DateService {
|
||||||
toParse = trimToMillis(toParse);
|
toParse = trimToMillis(toParse);
|
||||||
toParse = trimTZ(toParse);
|
toParse = trimTZ(toParse);
|
||||||
toParse += tz;
|
toParse += tz;
|
||||||
|
if (toParse.charAt(10) == ' ')
|
||||||
|
toParse = new StringBuilder(toParse).replace(10, 11, "T").toString();
|
||||||
return iso8601DateFormatter.parseDateTime(toParse).toDate();
|
return iso8601DateFormatter.parseDateTime(toParse).toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue