extend Time class with string formatters
[libi2ncommon] / src / timefunc.cpp
index 6d4b365..0abdfcb 100644 (file)
@@ -1011,6 +1011,37 @@ namespace clock {
         return *this;
     }
 
+    boost::optional<std::string>
+    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<std::string>
+    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<int> (this->value.tv_sec));
+    }
+
+    boost::optional<std::string>
+    Time::format_full_time (void) const
+    { return ::format_full_time (this->value.tv_sec); }
+
+    boost::optional<std::string>
+    Time::format_date (void) const
+    { return ::format_date (this->value.tv_sec); }
+
     boost::optional<Time>
     now (const enum type::id id, const enum type::variant var) NOEXCEPT
     {