date.hpp
Go to the documentation of this file.
1 #ifndef JULIAN_DATE_HPP
2 #define JULIAN_DATE_HPP
3 
4 #include <stdlib.h>
5 
6 #include <iostream>
7 #include <string>
8 
9 #include <dates/timeUnit.hpp>
10 #include <dates/tenor.hpp>
11 #include <boost/serialization/export.hpp>
12 
13 namespace julian {
27  class Date {
28  public:
31  enum class Format {
32  date1 ,
33  date2 ,
34  date3 ,
35  date4 ,
36  date5 ,
37  date6
38  };
39 
40  Date();
41  Date(int year, int month, int day);
42  Date(int yyyymmdd);
43  Date(std::string, Date::Format);
44 
45 
46 
47  std::string getString() const;
48  int getDay() const;
49  int getMonth() const;
50  int getYear() const;
51  int getN() const;
52 
53  void setDay(int);
54  void setMonth(int);
55  void setYear(int);
56 
57  void moveToEndOfMonth();
58  void moveToEndOfYear();
59 
60  bool isValid() const;
61  bool isLeapYear() const;
62  bool isEndOfMonth() const;
63  bool isEndOfYear() const;
64 
65  void operator++();
66  void operator--();
67 
68  void operator+=(Tenor t);
69  void operator-=(Tenor t);
70 
71 
72  friend class boost::serialization::access;
75  template<class Archive>
76  void serialize(Archive & ar, const unsigned int) {
77  ar & BOOST_SERIALIZATION_NVP(year_);
78  ar & BOOST_SERIALIZATION_NVP(month_);
79  ar & BOOST_SERIALIZATION_NVP(day_);
80  }
81  private:
82  int year_;
83  int month_;
84  int day_;
86  int yearOffset() const;
87  int monthOffset() const;
88  };
89 
90 
91  std::ostream& operator<<(std::ostream& s, Date& d);
92 
95  inline Date operator+(Date d, Tenor t) {
96  d += t;
97  return d;
98  }
101  inline Date operator-(Date d, Tenor t) {
102  d -= t;
103  return d;
104  }
107  inline bool operator==(const Date& d1, const Date& d2) {
108  return d1.getN() == d2.getN();
109  }
112  inline bool operator!=(const Date& d1, const Date& d2) {
113  return d1.getN() != d2.getN();
114  }
117  inline bool operator<(const Date& d1, const Date& d2) {
118  return d1.getN() < d2.getN();
119  }
122  inline bool operator>(const Date& d1, const Date& d2) {
123  return d1.getN() > d2.getN();
124  }
127  inline bool operator<=(const Date& d1, const Date& d2) {
128  return d1.getN() <= d2.getN();
129  }
132  inline bool operator>=(const Date& d1, const Date& d2) {
133  return (d1.getN() >= d2.getN() );
134  }
137  inline Tenor operator*(int a, TimeUnit unit_) {
138  return Tenor(a, unit_);
139  }
142  inline Tenor operator*(TimeUnit unit_, int a) {
143  return Tenor(a, unit_);
144  }
145 
146 } // namespace julian
147 #endif
Format
Date formats.
Definition: date.hpp:31
void operator-=(Tenor t)
Subtracts tenor.
Definition: date.cpp:373
int monthOffset() const
Auxiliary method.
Definition: date.cpp:409
int day_
This is the integer value representing number of days.
Definition: date.hpp:84
TimeUnit
Definition: timeUnit.hpp:21
bool isValid() const
Checks is date valid.
Definition: date.cpp:277
bool operator!=(const Date &d1, const Date &d2)
checks if dates are not equal
Definition: date.hpp:112
Definition: cadHoliday.cpp:3
int month_
This is the integer value representing number of months.
Definition: date.hpp:83
bool operator<(const Date &d1, const Date &d2)
checks if date d1 is earlier than d2
Definition: date.hpp:117
int getN() const
Calculate number of date.
Definition: date.cpp:149
bool isEndOfYear() const
Checks if date is end of year.
Definition: date.cpp:322
bool operator>=(const Date &d1, const Date &d2)
checks if date d1 is not later than d2
Definition: date.hpp:132
int year_
This is the integer value representing number of years.
Definition: date.hpp:82
bool isLeapYear() const
Checks if date is in leap year.
Definition: date.cpp:304
bool operator==(const Date &d1, const Date &d2)
checks if dates are equal
Definition: date.hpp:107
void moveToEndOfYear()
Moves to end of year.
Definition: date.cpp:268
void operator++()
Moves date to next date.
Definition: date.cpp:178
bool isEndOfMonth() const
Checks if date is end of month.
Definition: date.cpp:312
std::ostream & operator<<(std::ostream &os, Frequency &f)
Overloading << operator for Frequency enumeration.
Definition: timeUnit.hpp:78
Date operator-(Date d, Tenor t)
moves date backward by a tenor
Definition: date.hpp:101
int yearOffset() const
Auxiliary method.
Definition: date.cpp:429
Date()
Default constructor.
Definition: date.cpp:34
Class implements a date object.
Definition: date.hpp:27
Date operator+(Date d, Tenor t)
moves date forward by a tenor
Definition: date.hpp:95
void operator--()
Moves date back to last day.
Definition: date.cpp:211
File contains definition of tenor class.
void serialize(Archive &ar, const unsigned int)
interface used by Boost serialization library
Definition: date.hpp:76
Class implements a tenor object.
Definition: tenor.hpp:23
bool operator>(const Date &d1, const Date &d2)
checks if date d1 is later than d2
Definition: date.hpp:122
void moveToEndOfMonth()
Moves to end of month.
Definition: date.cpp:250
bool operator<=(const Date &d1, const Date &d2)
checks if date d1 is not earlier than d2
Definition: date.hpp:127
File contain time units and other useful enumerations.
Tenor operator*(int a, TimeUnit unit_)
creates tenor
Definition: date.hpp:137
void operator+=(Tenor t)
Adds tenor.
Definition: date.cpp:332