diff options
Diffstat (limited to 'datetime.h')
-rw-r--r-- | datetime.h | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -131,6 +131,8 @@ class date_t out << to_string(format); } + void parse(std::istream& in); + friend class datetime_t; friend struct interval_t; }; @@ -158,6 +160,11 @@ inline std::ostream& operator<<(std::ostream& out, const date_t& moment) { return out; } +inline std::istream& operator>>(std::istream& in, date_t& moment) { + moment.parse(in); + return in; +} + class datetime_error : public error { public: datetime_error(const std::string& reason) throw() : error(reason) {} @@ -225,6 +232,8 @@ class datetime_t : public date_t int sec() const { return localtime()->tm_sec; } + + void parse(std::istream& in); }; inline long operator-(const datetime_t& left, const datetime_t& right) { @@ -245,13 +254,11 @@ inline datetime_t operator-(const datetime_t& left, const long seconds) { return temp; } -inline std::ostream& operator<<(std::ostream& out, - const datetime_t& moment) { - char buf[64]; - std::strftime(buf, 63, (date_t::output_format + " %H:%M:%S").c_str(), - moment.localtime()); - out << buf; - return out; +std::ostream& operator<<(std::ostream& out, const datetime_t& moment); + +inline std::istream& operator>>(std::istream& in, datetime_t& moment) { + moment.parse(in); + return in; } struct interval_t |