00001 #pragma once
00002 #ifndef date_h
00003 #define date_h
00004
00005 #include ".\types.h"
00006 #include <stdio.h>
00007
00012 typedef ShortNatural Day;
00013 typedef ShortNatural Year;
00014
00015 enum Weekday { Sunday = 1,
00016 Monday = 2,
00017 Tuesday = 3,
00018 Wednesday = 4,
00019 Thursday = 5,
00020 Friday = 6,
00021 Saturday = 7
00022 };
00023
00024 enum Month { January = 1,
00025 February = 2,
00026 March = 3,
00027 April = 4,
00028 May = 5,
00029 June = 6,
00030 July = 7,
00031 August = 8,
00032 September = 9,
00033 October = 10,
00034 November = 11,
00035 December = 12
00036 };
00037
00038 enum TimeUnit { Days,
00039 Weeks,
00040 Months,
00041 Years
00042 };
00043
00044 enum Frequency { NoFrequency = -1,
00045 Once = 0,
00046 Annual = 1,
00047 Semiannual = 2,
00048 EveryFourthMonth = 3,
00049 Quarterly = 4,
00050 Bimonthly = 6,
00051 Monthly = 12
00052 };
00053
00054 enum BusinessDayConvention {
00055 Unadjusted,
00056 Preceding,
00057
00058 ModifiedPreceding,
00059
00060
00061
00062 Following,
00063
00064 ModifiedFollowing,
00065
00066
00067
00068 MonthEndReference
00069
00070
00071
00072 };
00073
00074 enum DayCountConvention {
00075 ACT_365,
00076 ACT_360,
00077 Day30_365,
00078 Day30_360
00079 };
00080
00081 class Date
00082 {
00083 public:
00085 Date(void);
00087 Date(LongInteger serialNumber);
00089 Date(Day d, Month m, Year y);
00091 Date(Day d, ShortNatural m, Year y);
00092 ~Date(void);
00093
00094 Weekday weekday() const;
00095 Day dayOfMonth() const;
00096 Day dayOfYear() const;
00097 Month month() const;
00098 Year year() const;
00099 LongInteger serialNumber() const;
00100 bool isEndOfMonth() const;
00101 Day lastDayOfMonth() const;
00102
00104 void setDateToToday();
00105
00107 Date& operator+=(LongInteger days);
00109 Date& operator-=(LongInteger days);
00111 Date& operator++();
00113 Date operator++(int );
00115 Date& operator--();
00117 Date operator--(int );
00119 Date operator+(LongInteger days) const;
00121 Date operator-(LongInteger days) const;
00122
00123 inline bool operator==(const Date& d2){return (_serialNumber == d2.serialNumber());};
00124 inline bool operator!=(const Date&d2){return (_serialNumber != d2.serialNumber());};
00125 inline bool operator<(const Date& d2){return (_serialNumber < d2.serialNumber());};
00126 inline bool operator<=(const Date& d2){return (_serialNumber <= d2.serialNumber());};
00127 inline bool operator>(const Date& d2){return (_serialNumber > d2.serialNumber());};
00128 inline bool operator>=(const Date& d2){return (_serialNumber >= d2.serialNumber());};
00129
00130 Date plusDays(Integer n) const;
00131
00132 Date plusWeeks(Integer n) const;
00133
00134 Date plusMonths(Integer n) const;
00135
00136 Date plusYears(Integer n) const;
00137
00138 Date plus(Integer n, TimeUnit units) const;
00139
00141 static Date minDate();
00143 static Date maxDate();
00145 static bool isLeap(Year y);
00147 static Date endOfMonth(const Date& d);
00149 static bool isEOM(const Date& d);
00151 static Date nextWeekday(const Date& d, Weekday);
00153 static Date nthWeekday(ShortInteger n, Weekday, Month m, Year y);
00154
00156 bool isBusinessDay();
00157 void applyConvention(BusinessDayConvention convention=Following);
00158 Date returnDateConvention(const Date& date, BusinessDayConvention convention=Following);
00159
00161 Real dayCount(const Date& d,DayCountConvention dayconvention=ACT_365) const;
00162
00164 char* toString() const;
00165
00166 private:
00167 LongInteger _serialNumber;
00168 static Date advance(const Date& d, Integer units, TimeUnit);
00169 static Integer monthLength(Month m, bool leapYear);
00170 static Integer monthOffset(Month m, bool leapYear);
00171 static LongInteger yearOffset(Year y);
00172 static LongInteger minimumSerialNumber();
00173 static LongInteger maximumSerialNumber();
00174 };
00175
00176 #endif