00001 #ifndef DVUTIL_PERIOD_H
00002 #define DVUTIL_PERIOD_H
00003
00004
00005 #include <stdexcept>
00006 #include <dvutil/date.h>
00007 #include <dvutil/convert.h>
00008
00009 namespace Dv {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 class Duration {
00023 public:
00024
00025 Duration(size_t years, size_t months, size_t seconds): years_(years),
00026 months_(months), seconds_(seconds) {}
00027
00028
00029 static Duration mins(size_t mins, size_t secs = 0);
00030
00031 static Duration hrs(size_t hrs, size_t mins=0, size_t secs = 0);
00032
00033 static Duration days(size_t days, size_t hrs=0, size_t mins=0, size_t secs = 0);
00034
00035 static Duration weeks(size_t wks, size_t days=0, size_t hrs=0, size_t mins=0, size_t secs = 0);
00036
00037 static Duration months(size_t months);
00038
00039 static Duration years(size_t years, size_t months=0);
00040
00041
00042 Duration operator+(const Duration& d) const;
00043
00044 Duration operator+=(const Duration& d);
00045
00046
00047 friend std::ostream& operator<<(std::ostream& os, const Duration& u);
00048
00049
00050 size_t years() const { return years_; }
00051
00052 size_t months() const { return months_; }
00053
00054 size_t seconds() const { return seconds_; }
00055
00056
00057
00058
00059
00060
00061
00062 std::string str() const { return Dv::tostring(*this); }
00063
00064 private:
00065 size_t years_;
00066 size_t months_;
00067 unsigned long seconds_;
00068 };
00069
00070
00071
00072 class Period {
00073 public:
00074
00075
00076
00077
00078 Period(const Date& start, const Duration& size): start_(start), size_(size) {}
00079
00080
00081
00082
00083 Period(Date start, Date end) throw (std::runtime_error);
00084
00085
00086 Date start() const { return start_; }
00087
00088 Date end() const;
00089
00090 const Duration& size() const { return size_; }
00091 private:
00092 Date start_;
00093 Duration size_;
00094 };
00095
00096
00097 bool
00098 operator==(const Duration& u1, const Duration& u2);
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 Date operator+(const Date& date, const Duration& duration);
00109
00110 }
00111 #endif
00112