Skip to content

Commit

Permalink
Handle only milisec timestamps and ISO8601 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkojotic committed Feb 21, 2019
1 parent 013f3c8 commit 656957d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,14 @@ public static DateTime utc(long instant)
public static DateTime of(String instant)
{
try {
Integer seconds = Integer.valueOf(instant);
return new DateTime(seconds * 1000L, ISOChronology.getInstanceUTC());
return new DateTime(instant, ISOChronology.getInstanceUTC());
}
catch (NumberFormatException ex) {
catch (IllegalArgumentException ex) {
try {
return new DateTime(Long.valueOf(instant), ISOChronology.getInstanceUTC());
}
catch (IllegalArgumentException ex2) {
try {
return new DateTime(instant, ISOChronology.getInstanceUTC());
}
catch (Exception ex3) {
throw ex;
}
throw ex;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void testCommonDateTimePattern()
}

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

Expand All @@ -50,8 +50,8 @@ public void testStringTimestampToDateTimeConversion()
Assert.assertEquals("2018-01-30T06:00:00.000Z", dt1.toString());
}

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

0 comments on commit 656957d

Please sign in to comment.