extend Time class with string formatters
[libi2ncommon] / test / test_timefunc.cpp
index 658950d..e5b4adf 100644 (file)
@@ -997,6 +997,60 @@ BOOST_AUTO_TEST_SUITE(Clock)
         BOOST_CHECK_EQUAL(ts.size (), 2);
     }
 
+    BOOST_AUTO_TEST_CASE(FormatISO8601_T)
+    {
+        I2n::clock::Time t (42, 42);
+        boost::optional<std::string> s = t.format_iso8601 (true, false, true, false);
+
+        BOOST_CHECK_EQUAL("00:00:42", *s);
+    }
+
+    BOOST_AUTO_TEST_CASE(FormatISO8601_DT)
+    {
+        I2n::clock::Time t (1541934671, 0);
+        boost::optional<std::string> s = t.format_iso8601 (true, true, true, false);
+
+        BOOST_CHECK_EQUAL("2018-11-11T11:11:11", *s);
+    }
+
+    BOOST_AUTO_TEST_CASE(FormatISO8601_DTZ)
+    {
+        I2n::clock::Time t (1541934671, 0);
+        boost::optional<std::string> s = t.format_iso8601 (true, true, true, true);
+
+        BOOST_CHECK_EQUAL("2018-11-11T11:11:11Z+0000", *s);
+    }
+
+    BOOST_AUTO_TEST_CASE(Format_make_nice_time)
+    {
+        I2n::clock::Time t (111111, 0);
+        boost::optional<std::string> s = t.make_nice_time ();
+
+        BOOST_CHECK_EQUAL("1 day, 06:51:51", *s);
+    }
+
+    BOOST_AUTO_TEST_CASE(Format_format_full_time)
+    {
+        I2n::clock::Time t (1541934671, 0);
+        /*
+         * brr, the old formatters use localtime without a way to opt out of
+         * it!
+         */
+        setenv ("TZ", "UTC", 1);
+        tzset();
+        boost::optional<std::string> s = t.format_full_time ();
+
+        BOOST_CHECK_EQUAL("11.11.2018 11:11", *s);
+    }
+
+    BOOST_AUTO_TEST_CASE(Format_format_date)
+    {
+        I2n::clock::Time t (1541934671, 0);
+        boost::optional<std::string> s = t.format_date ();
+
+        BOOST_CHECK_EQUAL("11.11.2018", *s);
+    }
+
 BOOST_AUTO_TEST_SUITE_END() /* [Clock] */
 
 BOOST_AUTO_TEST_SUITE_END()