explicitly set timezone for tests that depend on it
[libi2ncommon] / test / test_timefunc.cpp
index 885bb67..ebc22ae 100644 (file)
@@ -69,13 +69,13 @@ protected:
       used_check_files.clear();
    } // eo remove_check_files
 
-   void set_utc (void)
+   void set_tz (const std::string &tzname)
    {
         errno = 0;
-        if (setenv ("TZ", "UTC", 1) == -1)
+        if (setenv ("TZ", tzname.c_str (), 1) == -1)
         {
             std::cerr
-                << "error setting environment 'TZ': [" << this->tz << "]"
+                << "error setting environment 'TZ': [" << tzname << "]"
                 << std::endl
                 ;
             return;
@@ -84,6 +84,11 @@ protected:
         tzset ();
    }
 
+   inline void set_utc (void)
+   {
+       this->set_tz ("UTC");
+   }
+
 public:
     TestTimeFuncFixture()
         : tz (secure_getenv ("TZ") ?: "")
@@ -475,6 +480,7 @@ BOOST_AUTO_TEST_CASE(WeekDisplayString13)
 
 BOOST_AUTO_TEST_CASE(FormatFullTime)
 {
+    this->set_tz ("CET");
     time_t seconds = 1318844005;
 
     BOOST_CHECK_EQUAL("17.10.2011 11:33", format_full_time(seconds));
@@ -482,12 +488,14 @@ BOOST_AUTO_TEST_CASE(FormatFullTime)
 
 BOOST_AUTO_TEST_CASE(DateToSeconds1)
 {
+    this->set_tz ("CET");
     // no DST
     BOOST_CHECK_EQUAL(1325372400, date_to_seconds("2012-01-01"));
 }
 
 BOOST_AUTO_TEST_CASE(DateToSeconds2)
 {
+    this->set_tz ("CET");
     // DST
     BOOST_CHECK_EQUAL(1341093600, date_to_seconds("2012-07-01"));
 }
@@ -501,6 +509,7 @@ BOOST_AUTO_TEST_CASE(FormatISO8601_T)
 
 BOOST_AUTO_TEST_CASE(FormatISO8601_TZ_local)
 {
+    this->set_tz ("CET");
     const time_t moment = 1515492684;
     BOOST_CHECK_EQUAL("11:11:24Z+0100",
                       format_iso8601 (moment, false, false, true, true));
@@ -515,6 +524,7 @@ BOOST_AUTO_TEST_CASE(FormatISO8601_TZ)
 
 BOOST_AUTO_TEST_CASE(FormatISO8601_DTZ_local)
 {
+    this->set_tz ("CET");
     const time_t moment = 1515492684;
     BOOST_CHECK_EQUAL("2018-01-09T11:11:24Z+0100",
                       format_iso8601 (moment, false, true, true, true));