Date Calendar::adjust(const Date& d, BusinessDayConvention c) const { QL_REQUIRE(d != Date(), "null date"); if (c == Unadjusted) return d; Date d1 = d; if (c == Following || c == ModifiedFollowing) { while (isHoliday(d1)) d1++; if (c == ModifiedFollowing) { if (d1.month() != d.month()) { return adjust(d,Preceding); } } } else if (c == Preceding || c == ModifiedPreceding) { while (isHoliday(d1)) d1--; if (c == ModifiedPreceding && d1.month() != d.month()) { return adjust(d,Following); } } else { QL_FAIL("unknown business-day convention"); } return d1; }
void Date::shift ( void ){//Shift this date to previous working days (useful for benchmarks) if ( ! set() ) return ; while(isHoliday(*this)||isweekend()){ date->tm_mday -= 1 ; mktime ( date ); } }
int main(int argc,char **argv) { _Bool holiday = isHoliday(7); if(holiday) { printf("Today is holiday.\n"); } else { printf("Today is not holiday.\n"); } int age=30; if(age > 18) { printf("you are old enough to get a work.\n"); } else { printf("you should go to school.\n"); } int day=6; switch(day) { case 1: printf("Today is Monday.\n"); break; case 2: printf("Today is Tuesday.\n"); break; case 3: printf("Today is Wednesday.\n"); break; case 4: printf("Today is Thursday.\n"); break; case 5: printf("Today is Friday.\n"); break; case 6: printf("Today is Saturday.\n"); break; case 7: printf("Today is Sunday.\n"); break; default: printf("Today is Unknown Day.\n"); break; } for(day=0;day<10;day++) { print_day(day); } }
Date Calendar::advance(const Date& d, Integer n, TimeUnit unit, BusinessDayConvention c, bool endOfMonth) const { QL_REQUIRE(d!=Date(), "null date"); if (n == 0) { return adjust(d,c); } else if (unit == Days) { Date d1 = d; if (n > 0) { while (n > 0) { d1++; while (isHoliday(d1)) d1++; n--; } } else { while (n < 0) { d1--; while(isHoliday(d1)) d1--; n++; } } return d1; } else if (unit == Weeks) { Date d1 = d + n*unit; return adjust(d1,c); } else { Date d1 = d + n*unit; // we are sure the unit is Months or Years if (endOfMonth && isEndOfMonth(d)) return Calendar::endOfMonth(d1); return adjust(d1, c); } }