/** * Add the specified days, years and months to this date value and return a * new date object containing the result. */ public Date add(final int years, final int months, final int days) { final Period add = new Period(years, months, 0, days, 0, 0, 0, 0); final DateTime newDate = date.plus(add); return new Date(newDate); }
/** * Calculates, and returns, a date representing the last day of the month * relative to the current date. * * @author Joshua Cassidy */ public Date endOfMonth() { return new Date(date.dayOfMonth().withMaximumValue()); }
/** * Calculates, and returns, a date representing the first day of the week * relative to the current date. */ public Date startOfWeek() { return new Date(date.dayOfWeek().withMinimumValue()); }
/** * Calculates, and returns, a date representing the first day of the month * relative to the current date. */ public Date startOfMonth() { return new Date(date.dayOfMonth().withMinimumValue()); }
@Before public void setUp() throws Exception { TestClock.initialize(); actual = new Date(2000, 3, 14); }
@Test public void testParseEntryOfKeywordToday() throws Exception { final Date parsed = adapter.parseTextEntry(date, "today"); assertEquals(new Date(2003, 8, 17), parsed); }
@Test public void testParseEntryOfWeeksBeforeDate() throws Exception { final Date parsed = adapter.parseTextEntry(date, "-3w"); assertEquals(new Date(2001, 1, 14), parsed); }
@Test public void testParseEntryOfMonthsAfterToToday() throws Exception { final Date parsed = adapter.parseTextEntry(null, "+4m"); assertEquals(new Date(2003, 12, 17), parsed); }
@Test public void testParseEntryOfMonthsBeforeDate() throws Exception { final Date parsed = adapter.parseTextEntry(date, "-3m"); assertEquals(new Date(2000, 11, 4), parsed); }
@Test public void testParseEntryOfMonthsBeforeToToday() throws Exception { final Date parsed = adapter.parseTextEntry(null, "-4m"); assertEquals(new Date(2003, 4, 17), parsed); }
@Test public void testParseEntryOfDaysBeforeDate() throws Exception { final Date parsed = adapter.parseTextEntry(date, "-7"); assertEquals(new Date(2001, 1, 28), parsed); }
@Test public void testParseEntryOfDaysBeforeToToday() throws Exception { final Date parsed = adapter.parseTextEntry(null, "-5"); assertEquals(new Date(2003, 8, 12), parsed); }
@Test public void testParseEntryOfWeeksBeforeDate() throws Exception { final Date parsed = adapter.parseTextEntry(date, "-3w"); assertEquals(new Date(2001, 1, 14), parsed); }
@Test public void testParseEntryOfMonthsAfterToToday() throws Exception { final Date parsed = adapter.parseTextEntry(null, "+4m"); assertEquals(new Date(2003, 12, 17), parsed); }
@Test public void roundtripWhenParsingDateFormatWithAdjustBy() { final DateConverterForApplibDate converter = new DateConverterForApplibDate(settings, -1); final Date dt = converter.convertToObject("2013-05-11", null); assertThat(dt, is(new Date(2013, 05, 12))); final String str = converter.convertToString(dt, null); assertThat(str, is("2013-05-11")); }
@Test public void roundtripWhenParsingDateFormat() { final DateConverterForApplibDate converter = new DateConverterForApplibDate(settings, 0); final Date dt = converter.convertToObject("2013-05-11", null); assertThat(dt, is(new Date(2013, 05, 11))); final String str = converter.convertToString(dt, null); assertThat(str, is("2013-05-11")); }
@Test public void testDate() { actual = new Date(2001, 3, 7); assertEquals("day", 7, actual.getDay()); assertEquals("month", 3, actual.getMonth()); assertEquals("year", 2001, actual.getYear()); }