public void testIsHoliday() { CalendarDate newYearEve = CalendarDate.from(2004, 1, 1); // it's a assertTrue("New Years Eve is a holiday.", businessCalendar().isHoliday(newYearEve)); assertFalse( "The day after New Years Eve is not a holiday.", businessCalendar().isHoliday(newYearEve.nextDay())); }
public static String getDateString(CalendarDate d) { String dayName = CalendarDate.getDay(d.day, d.month, d.year); return dayName.substring(0, 1) + dayName.toLowerCase().substring(1, dayName.length()) + " " + d.toString(); }
public List<Appointment> getAppointmentsBetweenDates(CalendarDate start, CalendarDate end) { // given a start and end date, returns a list of appointments that recur between these dates int startID = CalendarDate.getDateID(start); int endID = CalendarDate.getDateID(end); List<Appointment> aps = new ArrayList<Appointment>(); Appointment ap; ListIterator<Appointment> it = appList.listIterator(); int ap_ID; while (it.hasNext()) { ap = (Appointment) it.next(); List<CalendarDate> cd = ap.getRecurrenceDates(startID, endID); if (cd.size() > 0) { aps.add(ap); } } return aps; }
public void testElapsedBusinessDays() { CalendarDate nov1 = CalendarDate.from(2004, 11, 1); CalendarDate nov30 = CalendarDate.from(2004, 11, 30); CalendarInterval interval = CalendarInterval.inclusive(nov1, nov30); assertEquals(Duration.days(30), interval.length()); // 1 holiday (Thanksgiving on a Thursday) + 8 weekend days. assertEquals(21, businessCalendar().getElapsedBusinessDays(interval)); }
public void testBusinessDaysIterator() { CalendarDate start = CalendarDate.from(2004, 2, 5); CalendarDate end = CalendarDate.from(2004, 2, 8); CalendarInterval interval = CalendarInterval.inclusive(start, end); Iterator it = businessCalendar().businessDaysOnly(interval.daysIterator()); assertTrue(it.hasNext()); assertEquals(start, it.next()); assertTrue(it.hasNext()); assertEquals(CalendarDate.from(2004, 2, 6), it.next()); assertFalse(it.hasNext()); }
public void testIsBusinessDay() { CalendarDate day = CalendarDate.from(2004, 1, 12); // it's a Monday for (int i = 0; i < 5; i++) { assertTrue("another working day", businessCalendar().isBusinessDay(day)); day = day.nextDay(); } assertFalse("finally, saturday arrived ...", businessCalendar().isBusinessDay(day)); assertFalse("... then sunday", businessCalendar().isBusinessDay(day.nextDay())); CalendarDate newYearEve = CalendarDate.from(2004, 1, 1); // it's a assertFalse("hey, it's a holiday", businessCalendar().isBusinessDay(newYearEve)); }
public void testBusinessDayReverseIterator() { CalendarDate friday = CalendarDate.from(2006, 06, 16); CalendarDate nextTuesday = CalendarDate.from(2006, 06, 20); CalendarInterval interval = CalendarInterval.inclusive(friday, nextTuesday); Iterator it = businessCalendar().businessDaysOnly(interval.daysInReverseIterator()); assertTrue(it.hasNext()); assertEquals(nextTuesday, it.next()); assertTrue(it.hasNext()); CalendarDate nextMonday = CalendarDate.from(2006, 06, 19); assertEquals(nextMonday, it.next()); assertTrue(it.hasNext()); assertEquals(friday, it.next()); assertFalse(it.hasNext()); }
public void testNearestBusinessDay() { CalendarDate saturday = CalendarDate.from(2004, 1, 10); CalendarDate sunday = saturday.nextDay(); CalendarDate monday = sunday.nextDay(); assertEquals(monday, businessCalendar().nearestBusinessDay(saturday)); assertEquals(monday, businessCalendar().nearestBusinessDay(sunday)); assertEquals(monday, businessCalendar().nearestBusinessDay(monday)); CalendarDate newYearEve = CalendarDate.from(2004, 1, 1); // it's a assertEquals( "it's a holiday & a thursday; wait till friday", newYearEve.nextDay(), businessCalendar().nearestBusinessDay(newYearEve)); CalendarDate christmas = CalendarDate.from(2004, 12, 24); // it's a assertEquals( "it's a holiday & a friday; wait till monday", CalendarDate.from(2004, 12, 27), businessCalendar().nearestBusinessDay(christmas)); }
public boolean saveCalendar(String fileName) { // saves the calendar to the file of given file name. FileOutputStream out; PrintStream p; try { out = new FileOutputStream(fileName); p = new PrintStream(out); Appointment ap; ListIterator<Appointment> it = appList.listIterator(); while (it.hasNext()) { ap = (Appointment) it.next(); p.println("<"); p.println(ap.getID()); p.println(CalendarDate.getDateID(ap.date)); p.println(ap.start_time.hr); p.println(ap.start_time.min); p.println(ap.end_time.hr); p.println(ap.end_time.min); p.println(ap.description); p.println(ap.location); p.println(ap.category); p.println(Appointment.IntFromRecurrence(ap.recur)); p.println(ap.reminder); p.println(">"); // ap.printAppointment(); // System.out.println("\n"); } } catch (Exception e) { System.err.println("Error writing to file"); return false; } return true; }
public void testIsWeekend() { CalendarDate saturday = CalendarDate.from(2004, 1, 10); assertTrue(businessCalendar().isWeekend(saturday)); CalendarDate sunday = saturday.nextDay(); assertTrue(businessCalendar().isWeekend(sunday)); CalendarDate day = sunday; for (int i = 0; i < 5; i++) { day = day.nextDay(); assertFalse("it's a midweek day", businessCalendar().isWeekend(day)); } day = day.nextDay(); assertTrue("finally, the weekend is here...", businessCalendar().isWeekend(day)); CalendarDate newYearEve = CalendarDate.from(2004, 1, 1); // it's a assertFalse( "a holiday is not necessarily a weekend day", businessCalendar().isWeekend(newYearEve)); }
public void testMinusNonBusinessDayZero() { CalendarDate saturday = CalendarDate.from(2006, 06, 17); CalendarDate friday = CalendarDate.from(2006, 06, 16); CalendarDate actual = businessCalendar().minusBusinessDays(saturday, 0); assertEquals(friday, actual); }
public void testPlusNonBusinessDayZero() { CalendarDate saturday = CalendarDate.from(2006, 06, 17); CalendarDate monday = CalendarDate.from(2006, 06, 19); CalendarDate actual = businessCalendar().plusBusinessDays(saturday, 0); assertEquals(monday, actual); }
public void testNextBusinessDayOverWeekday() { CalendarDate monday = CalendarDate.from(2006, 06, 19); CalendarDate tuesday = CalendarDate.from(2006, 06, 20); CalendarDate actual = businessCalendar().nextBusinessDay(monday); assertEquals(tuesday, actual); }
public void testNextBusinessDayOverWeekend() { CalendarDate friday = CalendarDate.from(2006, 06, 16); CalendarDate monday = CalendarDate.from(2006, 06, 19); CalendarDate actual = businessCalendar().nextBusinessDay(friday); assertEquals(monday, actual); }
public boolean normalize(CalendarDate date) { if (date.isNormalized()) { return true; } normalizeYear(date); Date ldate = (Date) date; // Normalize it as a Gregorian date and get its millisecond value super.normalize(ldate); boolean hasMillis = false; long millis = 0; int year = ldate.getNormalizedYear(); int i; Era era = null; for (i = eras.length - 1; i >= 0; --i) { era = eras[i]; if (era.isLocalTime()) { CalendarDate sinceDate = era.getSinceDate(); int sinceYear = sinceDate.getYear(); if (year > sinceYear) { break; } if (year == sinceYear) { int month = ldate.getMonth(); int sinceMonth = sinceDate.getMonth(); if (month > sinceMonth) { break; } if (month == sinceMonth) { int day = ldate.getDayOfMonth(); int sinceDay = sinceDate.getDayOfMonth(); if (day > sinceDay) { break; } if (day == sinceDay) { long timeOfDay = ldate.getTimeOfDay(); long sinceTimeOfDay = sinceDate.getTimeOfDay(); if (timeOfDay >= sinceTimeOfDay) { break; } --i; break; } } } } else { if (!hasMillis) { millis = super.getTime(date); hasMillis = true; } long since = era.getSince(date.getZone()); if (millis >= since) { break; } } } if (i >= 0) { ldate.setLocalEra(era); int y = ldate.getNormalizedYear() - era.getSinceDate().getYear() + 1; ldate.setLocalYear(y); } else { // Set Gregorian year with no era ldate.setEra(null); ldate.setLocalYear(year); ldate.setNormalizedYear(year); } ldate.setNormalized(true); return true; }