#include <unistd.h>
#include <set>
+#include <iostream>
using namespace std;
using namespace I2n;
protected:
typedef std::list< std::string > StringList;
std::set<std::string> used_check_files;
+ std::string tz; /* save and restore TZ from envp */
std::string get_check_file_path(std::string tag)
{
used_check_files.clear();
} // eo remove_check_files
+ void set_utc (void)
+ {
+ errno = 0;
+ if (setenv ("TZ", "UTC", 1) == -1)
+ {
+ std::cerr
+ << "error setting environment 'TZ': [" << this->tz << "]"
+ << std::endl
+ ;
+ return;
+ }
+
+ tzset ();
+ }
+
public:
TestTimeFuncFixture()
+ : tz (secure_getenv ("TZ") ?: "")
{
}
~TestTimeFuncFixture()
{
remove_check_files();
+
+ errno = 0;
+ if (setenv ("TZ", this->tz.c_str (), 1) == -1)
+ {
+ std::cerr
+ << "error cleaning up environment 'TZ': [" << this->tz << "]"
+ << std::endl
+ ;
+ }
+ else
+ {
+ tzset();
+ }
}
};
* brr, the old formatters use localtime without a way to opt out of
* it!
*/
- setenv ("TZ", "UTC", 1);
- tzset();
+ this->set_utc ();
boost::optional<std::string> s = t.format_full_time ();
BOOST_CHECK_EQUAL("11.11.2018 11:11", *s);
const std::string in1 ("0001-01-01T00:00:00Z+0000");
const std::string in2 ("2018-11-11T11:11:11Z+0000");
+ this->set_utc ();
+
boost::optional<I2n::clock::Time> t1 = I2n::clock::time_of_iso8601 (in1);
boost::optional<I2n::clock::Time> t2 = I2n::clock::time_of_iso8601 (in2);
const std::string in1 ("-0001-01-01T00:00:00Z+0000");
const std::string in2 ("-2018-11-11T11:11:11Z+0000");
+ this->set_utc ();
+
boost::optional<I2n::clock::Time> t1 = I2n::clock::time_of_iso8601 (in1);
boost::optional<I2n::clock::Time> t2 = I2n::clock::time_of_iso8601 (in2);
const std::string in1 ("2018-11-11T11:11:11");
const std::string in2 ("2018-11-11");
- setenv ("TZ", "UTC", 1);
- tzset();
+ this->set_utc ();
boost::optional<I2n::clock::Time> t1 =
I2n::clock::time_of_iso8601 (in1, true, true, false);
const std::string timeless ("11:11:11");
boost::optional<I2n::clock::Time> untimely = boost::none;
+ this->set_utc ();
+
untimely = I2n::clock::time_of_iso8601 (timeless, false, true, false);
# if LONG_BIT == 32