diff options
Diffstat (limited to 'src/times.h')
-rw-r--r-- | src/times.h | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/src/times.h b/src/times.h index 51cc8491..02b39ef7 100644 --- a/src/times.h +++ b/src/times.h @@ -51,8 +51,8 @@ namespace ledger { DECLARE_EXCEPTION(datetime_error, std::runtime_error); DECLARE_EXCEPTION(date_error, std::runtime_error); -typedef boost::posix_time::ptime datetime_t; -typedef datetime_t::time_duration_type time_duration_t; +typedef boost::posix_time::ptime datetime_t; +typedef datetime_t::time_duration_type time_duration_t; inline bool is_valid(const datetime_t& moment) { return ! moment.is_not_a_date_time(); @@ -89,14 +89,14 @@ typedef optional<date_t::year_type> optional_year; datetime_t parse_datetime(const char * str, optional_year current_year = none); inline datetime_t parse_datetime(const std::string& str, - optional_year current_year = none) { + optional_year current_year = none) { return parse_datetime(str.c_str(), current_year); } date_t parse_date(const char * str, optional_year current_year = none); inline date_t parse_date(const std::string& str, - optional_year current_year = none) { + optional_year current_year = none) { return parse_date(str.c_str(), current_year); } @@ -105,18 +105,18 @@ enum format_type_t { }; std::string format_datetime(const datetime_t& when, - const format_type_t format_type = FMT_PRINTED, - const optional<const char *>& format = none); + const format_type_t format_type = FMT_PRINTED, + const optional<const char *>& format = none); void set_datetime_format(const char * format); std::string format_date(const date_t& when, - const format_type_t format_type = FMT_PRINTED, - const optional<const char *>& format = none); + const format_type_t format_type = FMT_PRINTED, + const optional<const char *>& format = none); void set_date_format(const char * format); void set_input_date_format(const char * format); inline void to_xml(std::ostream& out, const datetime_t& when, - bool wrap = true) + bool wrap = true) { if (wrap) { push_xml x(out, "datetime"); @@ -127,7 +127,7 @@ inline void to_xml(std::ostream& out, const datetime_t& when, } inline void to_xml(std::ostream& out, const date_t& when, - bool wrap = true) + bool wrap = true) { if (wrap) { push_xml x(out, "date"); @@ -144,8 +144,8 @@ struct date_traits_t bool has_day; date_traits_t(bool _has_year = false, - bool _has_month = false, - bool _has_day = false) + bool _has_month = false, + bool _has_day = false) : has_year(_has_year), has_month(_has_month), has_day(_has_day) { TRACE_CTOR(date_traits_t, "bool, bool, bool"); } @@ -160,16 +160,16 @@ struct date_traits_t } date_traits_t& operator=(const date_traits_t& traits) { - has_year = traits.has_year; + has_year = traits.has_year; has_month = traits.has_month; - has_day = traits.has_day; + has_day = traits.has_day; return *this; } bool operator==(const date_traits_t& traits) const { - return (has_year == traits.has_year && - has_month == traits.has_month && - has_day == traits.has_day); + return (has_year == traits.has_year && + has_month == traits.has_month && + has_day == traits.has_day); } #if defined(HAVE_BOOST_SERIALIZATION) @@ -249,11 +249,11 @@ struct date_duration_t out << length << ' '; switch (quantum) { - case DAYS: out << "day"; break; - case WEEKS: out << "week"; break; + case DAYS: out << "day"; break; + case WEEKS: out << "week"; break; case MONTHS: out << "month"; break; case QUARTERS: out << "quarter"; break; - case YEARS: out << "year"; break; + case YEARS: out << "year"; break; default: assert(false); break; @@ -287,31 +287,31 @@ class date_specifier_t public: #if 0 - typedef date_t::year_type year_type; + typedef date_t::year_type year_type; #else - typedef unsigned short year_type; + typedef unsigned short year_type; #endif - typedef date_t::month_type month_type; - typedef date_t::day_type day_type; + typedef date_t::month_type month_type; + typedef date_t::day_type day_type; typedef date_t::day_of_week_type day_of_week_type; protected: - optional<year_type> year; - optional<month_type> month; - optional<day_type> day; + optional<year_type> year; + optional<month_type> month; + optional<day_type> day; optional<day_of_week_type> wday; public: date_specifier_t(const optional<year_type>& _year = none, - const optional<month_type>& _month = none, - const optional<day_type>& _day = none, - const optional<day_of_week_type>& _wday = none) + const optional<month_type>& _month = none, + const optional<day_type>& _day = none, + const optional<day_of_week_type>& _wday = none) : year(_year), month(_month), day(_day), wday(_wday) { TRACE_CTOR(date_specifier_t, - "year_type, month_type, day_type, day_of_week_type"); + "year_type, month_type, day_type, day_of_week_type"); } date_specifier_t(const date_t& date, - const optional<date_traits_t>& traits = none) { + const optional<date_traits_t>& traits = none) { TRACE_CTOR(date_specifier_t, "date_t, date_traits_t"); if (! traits || traits->has_year) year = date.year(); @@ -333,7 +333,7 @@ public: date_t end(const optional_year& current_year = none) const; bool is_within(const date_t& date, - const optional_year& current_year = none) const { + const optional_year& current_year = none) const { return date >= begin(current_year) && date < end(current_year); } @@ -390,7 +390,7 @@ class date_range_t public: date_range_t(const optional<date_specifier_t>& _range_begin = none, - const optional<date_specifier_t>& _range_end = none) + const optional<date_specifier_t>& _range_end = none) : range_begin(_range_begin), range_end(_range_end), end_inclusive(false) { TRACE_CTOR(date_range_t, "date_specifier_t, date_specifier_t"); @@ -413,16 +413,16 @@ public: optional<date_t> end(const optional_year& current_year = none) const { if (range_end) { if (end_inclusive) - return range_end->end(current_year); + return range_end->end(current_year); else - return range_end->begin(current_year); + return range_end->begin(current_year); } else { return none; } } bool is_within(const date_t& date, - const optional_year& current_year = none) const { + const optional_year& current_year = none) const { optional<date_t> b = begin(current_year); optional<date_t> e = end(current_year); bool after_begin = b ? date >= *b : true; @@ -527,19 +527,19 @@ private: class date_interval_t : public equality_comparable<date_interval_t> { public: - static date_t add_duration(const date_t& date, - const date_duration_t& duration); - static date_t subtract_duration(const date_t& date, - const date_duration_t& duration); + static date_t add_duration(const date_t& date, + const date_duration_t& duration); + static date_t subtract_duration(const date_t& date, + const date_duration_t& duration); optional<date_specifier_or_range_t> range; - optional<date_t> start; // the real start, after adjustment - optional<date_t> finish; // the real end, likewise - bool aligned; - optional<date_t> next; + optional<date_t> start; // the real start, after adjustment + optional<date_t> finish; // the real end, likewise + bool aligned; + optional<date_t> next; optional<date_duration_t> duration; - optional<date_t> end_of_duration; + optional<date_t> end_of_duration; explicit date_interval_t() : aligned(false) { TRACE_CTOR(date_interval_t, ""); @@ -564,7 +564,7 @@ public: bool operator==(const date_interval_t& other) const { return (start == other.start && - (! start || *start == *other.start)); + (! start || *start == *other.start)); } operator bool() const { @@ -580,8 +580,8 @@ public: void parse(const string& str); - void resolve_end(); - void stabilize(const optional<date_t>& date = none); + void resolve_end(); + void stabilize(const optional<date_t>& date = none); bool is_valid() const { return start; |