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