Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ public static DateTime utc(long instant)

public static DateTime of(String instant)
{
return new DateTime(instant, ISOChronology.getInstanceUTC());
try {
return new DateTime(instant, ISOChronology.getInstanceUTC());
}
catch (IllegalArgumentException ex) {
try {
return new DateTime(Long.valueOf(instant), ISOChronology.getInstanceUTC());
}
catch (IllegalArgumentException ex2) {
throw ex;
}
}
}

public static DateTime of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ public void testCommonDateTimePattern()
Assert.assertTrue(DateTimes.COMMON_DATE_TIME_PATTERN.matcher(dt.toString()).matches());
}
}

@Test
public void testStringToDateTimeConversion()
{
String seconds = "2018-01-30T06:00:00";
DateTime dt2 = DateTimes.of(seconds);
Assert.assertEquals("2018-01-30T06:00:00.000Z", dt2.toString());

String milis = "1517292000000";
DateTime dt1 = DateTimes.of(milis);
Assert.assertEquals("2018-01-30T06:00:00.000Z", dt1.toString());
}

@Test(expected = IllegalArgumentException.class)
public void testStringToDateTimeConverstion_RethrowInitialException()
{
String invalid = "51729200AZ";
DateTimes.of(invalid);
}
}