Skip to content

Commit

Permalink
Relative dates without a year should use the next year if appropriate
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
Joe Stelmach authored and Joe Stelmach committed Jan 16, 2016
1 parent a146a38 commit 0fe495d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/joestelmach/natty/WalkerState.java
Expand Up @@ -91,7 +91,7 @@ public void seekToDayOfWeek(String direction, String seekType, String seekAmount
else if(seekType.equals(SEEK_BY_DAY)) {
// find the closest day
do {
_calendar.roll(Calendar.DAY_OF_YEAR, sign);
_calendar.add(Calendar.DAY_OF_YEAR, sign);
} while(_calendar.get(Calendar.DAY_OF_WEEK) != dayOfWeekInt);

// now add/subtract any additional days
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/joestelmach/natty/DateTimeTest.java
Expand Up @@ -88,6 +88,11 @@ public void testRelative() throws Exception {
validateDateTime("wed evening at 8:30", 3, 2, 2011, 20, 30, 0);
validateDateTime("750 minutes from now", 2, 24, 2011, 12, 30, 0);
validateDateTime("1500 minutes from now", 2, 25, 2011, 1, 0, 0);

// year boundary
reference = DateFormat.getDateInstance(DateFormat.SHORT).parse("12/29/2015");
CalendarSource.setBaseDate(reference);
validateDateTime("Friday 2pm", 1, 1, 2016, 14, 0, 0);
}

@Test
Expand Down

0 comments on commit 0fe495d

Please sign in to comment.