int main() { Year year; int choice; short month, day; char s[80]; year.read(); choice = getChoice(); while(choice != 0) { if(choice == 1) { getDate(month, day); year.searchDate(month, day); } else // choice == 2 { getSubject(s); year.searchSubject(s); } choice = getChoice(); } // while choice not Done return 0; } // main()
/** * Insert a year into the year list * @param the year to insert * @return true if a year of that key wasn't already in the list */ bool Municipality::addYear(Year &year) { if(!_years->contains(year.name())){ _years->insert(year.name(),year); return true; } return false; }
int main() { Year year; int choice; short month, day; char s[80]; year.read(); choice = getChoice(); while(choice != 0) { switch (choice) { case 1: { getDate(month, day); year.searchDate(month, day); break; } case 2: { getSubject(s); year.searchSubject(s); break; } case 3: { getDate(month, day); addAppointment(year, month, day); break; } } choice = getChoice(); } // while choice not Done return 0; } // main()
void MonthDayRuleTest::test_utilities() { int yearIndex; SetDate date; Year year ( DateUtil::year()); Date newYearDate (year, Month(1), DayOfMonth(1)); Date july4Date (year, Month(7), DayOfMonth(4)); Date christmasDate(year, Month(12), DayOfMonth(25)); //test: MontDayRule::virtual Date calcDate(const Year& year) const ; MonthDayRule newYearRule ("Rule", Month(1), DayOfMonth(1)); date = newYearRule.calcDate(year); CPPUNIT_ASSERT(newYearDate == *date.begin()); for (yearIndex = year.getValue(); yearIndex <= year.getValue() + 50; ++yearIndex){ date = newYearRule.calcDate(Year(yearIndex)); CPPUNIT_ASSERT(newYearDate == *date.begin()); newYearDate.addYear(1); } MonthDayRule july4Rule ("July4Rule", Month(7), DayOfMonth(4)); date = july4Rule.calcDate(year); CPPUNIT_ASSERT(july4Date == *date.begin()); MonthDayRule christmasRule("ChristmasRule", Month(12), DayOfMonth(25)); date = christmasRule.calcDate(year); CPPUNIT_ASSERT(christmasDate == *date.begin()); //Test for weekendAdjustment WeekendRuleSharedPtr weekendRulePtr(new WeekendRule("WeekendRule")); weekendRulePtr->addDay(WeekDay::Saturday); weekendRulePtr->addDay(WeekDay::Sunday); MonthDayRule adjustingNewYearRule ("AdjustingNewYear", Month(1), DayOfMonth(1)); adjustingNewYearRule.setStartEffectiveDate(20110101); adjustingNewYearRule.setWeekendAdjustment(WeekendAdjustment::ClosestWeekDay); adjustingNewYearRule.setWeekendRule(weekendRulePtr); //First check for Saturday -> prior Friday date = adjustingNewYearRule.calcDate(Year(2011)); CPPUNIT_ASSERT(Date(20101231) == *date.begin()); //First check for Sunday -> next Monday date = adjustingNewYearRule.calcDate(Year(2012)); CPPUNIT_ASSERT(Date(20120102) == *date.begin()); //Check for no adjustment is required date = adjustingNewYearRule.calcDate(Year(2013)); CPPUNIT_ASSERT(Date(20130101) == *date.begin()); //Rule is disabled try{ newYearRule.setEnabledFlag(false); newYearRule.calcDate(year); } catch (BaseException& ex){ CAUGHT_EXCEPTION(ex,"Calculation called on disabled rule"); } newYearRule.setEnabledFlag(true); //Rule start date year > calc year try{ newYearRule.calcDate(Year(2010)); } catch (BaseException& ex){ CAUGHT_EXCEPTION(ex,"Calculation called for year before rule is in effect"); } //Rule calc year > rule end date year try{ newYearRule.setEndEffectiveDate(20121231); newYearRule.calcDate(Year(2030)); } catch (BaseException& ex){ CAUGHT_EXCEPTION(ex,"Calculation called for year after rule is in effect"); } }