From: Philipp Gesang Date: Tue, 30 Jan 2018 09:24:03 +0000 (+0100) Subject: extend Time class with string formatters X-Git-Tag: v2.11~1^2~14 X-Git-Url: http://developer.intra2net.com/git/?p=libi2ncommon;a=commitdiff_plain;h=72acd54c52bf6dd5f1d2f9c18e29deea41480a94 extend Time class with string formatters Add convenience member functions for the existing formatters. Note that the make_*() group of functions all use ``localtime_r()`` internally so unit tests must be guarded by an explicit time zone change to UTC. --- diff --git a/src/timefunc.cpp b/src/timefunc.cpp index 6d4b365..0abdfcb 100644 --- a/src/timefunc.cpp +++ b/src/timefunc.cpp @@ -1011,6 +1011,37 @@ namespace clock { return *this; } + boost::optional + Time::format_iso8601 (const bool utc, + const bool date, + const bool time, + const bool tz) const + { + time_breakdown_fn breakdown = utc ? gmtime_r : localtime_r; + struct tm tm; + + if (breakdown (&this->value.tv_sec, &tm) == NULL) { + return boost::none; + } + + return ::format_iso8601 (tm, date, time, tz); + } + + boost::optional + Time::make_nice_time (void) const + { + /* XXX the cast below results in loss of precision with 64 bit time_t! */ + return ::make_nice_time (static_cast (this->value.tv_sec)); + } + + boost::optional + Time::format_full_time (void) const + { return ::format_full_time (this->value.tv_sec); } + + boost::optional + Time::format_date (void) const + { return ::format_date (this->value.tv_sec); } + boost::optional