add precautions for old glibc
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 26 Apr 2019 08:44:02 +0000 (10:44 +0200)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 26 Apr 2019 14:29:43 +0000 (16:29 +0200)
The glibc 2.17 currently being used on the Intranator lacks two
commits from 2015 which implement correct handling of ISO8601
timezone specifications. This causes timestamp parsing to fail
where the `Z' suffix is used to indicate UTC, so comment out
the respective tests.

test/test_timefunc.cpp

index 5fc58e5..6192b78 100644 (file)
@@ -23,6 +23,16 @@ on this file might be covered by the GNU General Public License.
  * @copyright Copyright &copy; 2001-2008 by Intra2net AG
  *
  */
+#include <features.h>
+#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 23)
+/*
+ * Ancient glibc (pre 2015) has a defective implementation of strptime(3)
+ * that doesn’t handle the ‘Z’ modifier of ISO8601 to indicate UTC. It also
+ * parses fractional timezones only partially so e. g. “+11:11” is treated
+ * as “+1100”.
+ */
+#   define GLIBC_STRPTIME_LACKS_Z
+#endif
 
 #define BOOST_TEST_DYN_LINK
 #include <boost/test/unit_test.hpp>
@@ -1189,6 +1199,7 @@ BOOST_AUTO_TEST_SUITE(Clock)
 # endif
     }
 
+# ifndef GLIBC_STRPTIME_LACKS_Z
     BOOST_AUTO_TEST_CASE(FromString_iso8601_Z)
     {
         const std::string in1 ("2019-04-25T13:41:47+0000");
@@ -1205,6 +1216,7 @@ BOOST_AUTO_TEST_SUITE(Clock)
         BOOST_CHECK_EQUAL(*t1->format_iso8601 (), *t2->format_iso8601 ());
         BOOST_CHECK_EQUAL(*t2->format_iso8601 (), in1);
     }
+# endif
 
     BOOST_AUTO_TEST_CASE(FromString_iso8601_partial)
     {
@@ -1240,14 +1252,22 @@ BOOST_AUTO_TEST_SUITE(Clock)
         boost::optional<I2n::clock::Time> t2 = I2n::clock::time_of_iso8601 (in2, true, true, true);
         boost::optional<I2n::clock::Time> t3 = I2n::clock::time_of_iso8601 (in3, true, true, true);
 
+# ifdef GLIBC_STRPTIME_LACKS_Z
+        BOOST_CHECK(!t1);
+# else
         BOOST_CHECK(t1);
+# endif
         BOOST_CHECK(t2);
         BOOST_CHECK(t3);
 
+# ifndef GLIBC_STRPTIME_LACKS_Z
         BOOST_CHECK_EQUAL(*t1->format_iso8601 (), "2019-04-25T13:41:47+0000");
         BOOST_CHECK_EQUAL(t1->get_sec (), 1556199707);
+# endif
         BOOST_CHECK_EQUAL(*t2->format_iso8601 (), "2019-04-25T15:41:47+0000");
+# ifndef GLIBC_STRPTIME_LACKS_Z
         BOOST_CHECK_EQUAL(t2->get_sec (), t1->get_sec () + 2 * 60 * 60);
+# endif
         BOOST_CHECK_EQUAL(*t2, *t3);
         BOOST_CHECK_EQUAL(*t3->format_iso8601 (), "2019-04-25T15:41:47+0000");
     }