Skip to content

Commit

Permalink
Fix to avoid exception for times before 1970 with non-zero milli-of-s…
Browse files Browse the repository at this point in the history
…econd
  • Loading branch information
jodastephen committed Sep 13, 2012
1 parent 5d0f10b commit a9f1ae9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Expand Up @@ -55,6 +55,10 @@ Bug fixes since 2.1
Addition and subtraction in MonthDay was fixed. Addition and subtraction in MonthDay was fixed.
It previously didn't work when the start value was 29th February. It previously didn't work when the start value was 29th February.


- LocalDateTime.fromDateFields()
This used to fail before 1970 when the input had a milli-of-second field
Fixed to not throw an exception

- DateTimeFormatter.parseInto() [3522138] - DateTimeFormatter.parseInto() [3522138]
The v2.0 changes to handle parsing of month/day on their own (for Feb 29th) cause The v2.0 changes to handle parsing of month/day on their own (for Feb 29th) cause
parseInto() to lose the year. This fix reverts behaviour to v1.x so that parseInto() parseInto() to lose the year. This fix reverts behaviour to v1.x so that parseInto()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/joda/time/LocalDateTime.java
Expand Up @@ -238,7 +238,7 @@ public static LocalDateTime fromDateFields(Date date) {
date.getHours(), date.getHours(),
date.getMinutes(), date.getMinutes(),
date.getSeconds(), date.getSeconds(),
(int) (date.getTime() % 1000) (((int) (date.getTime() % 1000)) + 1000) % 1000
); );
} }


Expand Down
13 changes: 12 additions & 1 deletion src/test/java/org/joda/time/TestLocalDateTime_Constructors.java
Expand Up @@ -114,7 +114,7 @@ public void testFactory_FromCalendarFields() throws Exception {
} }


//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testFactory_FromDateFields() throws Exception { public void testFactory_FromDateFields_after1970() throws Exception {
GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6); GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6);
cal.set(Calendar.MILLISECOND, 7); cal.set(Calendar.MILLISECOND, 7);
LocalDateTime expected = new LocalDateTime(1970, 2, 3, 4, 5 ,6, 7); LocalDateTime expected = new LocalDateTime(1970, 2, 3, 4, 5 ,6, 7);
Expand All @@ -125,6 +125,17 @@ public void testFactory_FromDateFields() throws Exception {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }


public void testFactory_FromDateFields_before1970() throws Exception {
GregorianCalendar cal = new GregorianCalendar(1969, 1, 3, 4, 5, 6);
cal.set(Calendar.MILLISECOND, 7);
LocalDateTime expected = new LocalDateTime(1969, 2, 3, 4, 5 ,6, 7);
assertEquals(expected, LocalDateTime.fromDateFields(cal.getTime()));
try {
LocalDateTime.fromDateFields((Date) null);
fail();
} catch (IllegalArgumentException ex) {}
}

//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testConstructor() throws Throwable { public void testConstructor() throws Throwable {
LocalDateTime test = new LocalDateTime(); LocalDateTime test = new LocalDateTime();
Expand Down

0 comments on commit a9f1ae9

Please sign in to comment.