Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

date.h

Go to the documentation of this file.
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,     //null frequency
00045                  Once = 0,             //zero-coupon
00046                  Annual = 1,           //once a year
00047                  Semiannual = 2,       //twice a year
00048                  EveryFourthMonth = 3, //every fourth month
00049                  Quarterly = 4,        //every quarter
00050                  Bimonthly = 6,        //every two months
00051                  Monthly = 12          //once a month
00052 };
00053 
00054 enum BusinessDayConvention {
00055         Unadjusted,         /* Do not adjust. */
00056         Preceding,          /* first business day before
00057                                the given holiday. */
00058         ModifiedPreceding,  /* first business day before
00059                                the given holiday unless it belongs to a
00060                                different month, in which case choose the
00061                                first business day after the holiday. */
00062         Following,          /* first business day after
00063                                the given holiday. */
00064         ModifiedFollowing,  /* first business day after
00065                                the given holiday unless it belongs to a
00066                                different month, in which case choose the
00067                                first business day before the holiday. */
00068         MonthEndReference   /* first business day after
00069                                the given holiday, if the original date falls
00070                                on last business day of month result reverts
00071                                to first business day before month-end */
00072 };
00073 
00074 enum DayCountConvention {
00075                 ACT_365,                //exact number of days but 365 in a year
00076                 ACT_360,                //exact number of days but 360 in a year
00077                 Day30_365,                      //30 days per month and 365 in a year
00078                 Day30_360                       //30 days per month and 360 in a year
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         /* \deprecated use date + n*Weeks instead */
00132         Date plusWeeks(Integer n) const;
00133         /* \deprecated use date + n*Months instead */
00134         Date plusMonths(Integer n) const;
00135         /* \deprecated use date + n*Years instead */
00136         Date plusYears(Integer n) const;
00137         /* \deprecated use date + n*units instead */
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

Note: Generated nightly - reload for latest version
Generated on Thu Dec 22 23:12:36 2005 for terreneuve by doxygen 1.3.6