2020-03-06 14:18:14 +00:00
|
|
|
#include <catch2/catch.hpp>
|
2019-10-04 09:04:26 +00:00
|
|
|
|
2019-09-24 08:48:24 +00:00
|
|
|
#include "libslic3r/Time.hpp"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <locale>
|
|
|
|
|
2020-03-06 14:18:14 +00:00
|
|
|
using namespace Slic3r;
|
2019-09-24 08:48:24 +00:00
|
|
|
|
2020-03-06 14:18:14 +00:00
|
|
|
static void test_time_fmt(Slic3r::Utils::TimeFormat fmt) {
|
2019-09-24 08:48:24 +00:00
|
|
|
using namespace Slic3r::Utils;
|
|
|
|
time_t t = get_current_time_utc();
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-09-24 08:48:24 +00:00
|
|
|
std::string tstr = time2str(t, TimeZone::local, fmt);
|
|
|
|
time_t parsedtime = str2time(tstr, TimeZone::local, fmt);
|
2019-10-04 09:04:26 +00:00
|
|
|
REQUIRE(t == parsedtime);
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-09-24 08:48:24 +00:00
|
|
|
tstr = time2str(t, TimeZone::utc, fmt);
|
|
|
|
parsedtime = str2time(tstr, TimeZone::utc, fmt);
|
2019-10-04 09:04:26 +00:00
|
|
|
REQUIRE(t == parsedtime);
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-09-24 08:48:24 +00:00
|
|
|
parsedtime = str2time("not valid string", TimeZone::local, fmt);
|
2019-10-04 09:04:26 +00:00
|
|
|
REQUIRE(parsedtime == time_t(-1));
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-09-24 08:48:24 +00:00
|
|
|
parsedtime = str2time("not valid string", TimeZone::utc, fmt);
|
2019-10-04 09:04:26 +00:00
|
|
|
REQUIRE(parsedtime == time_t(-1));
|
2019-09-24 08:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 09:04:26 +00:00
|
|
|
TEST_CASE("ISO8601Z", "[Timeutils]") {
|
2019-09-24 08:48:24 +00:00
|
|
|
test_time_fmt(Slic3r::Utils::TimeFormat::iso8601Z);
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-10-07 06:56:54 +00:00
|
|
|
std::string mydate = "20190710T085000Z";
|
|
|
|
time_t t = Slic3r::Utils::parse_iso_utc_timestamp(mydate);
|
|
|
|
std::string date = Slic3r::Utils::iso_utc_timestamp(t);
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-10-07 06:56:54 +00:00
|
|
|
REQUIRE(date == mydate);
|
2019-09-24 08:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 09:04:26 +00:00
|
|
|
TEST_CASE("Slic3r_UTC_Time_Format", "[Timeutils]") {
|
2019-10-07 06:56:54 +00:00
|
|
|
using namespace Slic3r::Utils;
|
|
|
|
test_time_fmt(TimeFormat::gcode);
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-10-07 06:56:54 +00:00
|
|
|
std::string mydate = "2019-07-10 at 08:50:00 UTC";
|
|
|
|
time_t t = Slic3r::Utils::str2time(mydate, TimeZone::utc, TimeFormat::gcode);
|
|
|
|
std::string date = Slic3r::Utils::utc_timestamp(t);
|
2020-03-06 14:18:14 +00:00
|
|
|
|
2019-10-07 06:56:54 +00:00
|
|
|
REQUIRE(date == mydate);
|
2019-09-24 08:48:24 +00:00
|
|
|
}
|