mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-19 09:08:57 +08:00
Fix incorrect time format spec in iso_utc_timestamp.
Also add test for such errors in the future.
This commit is contained in:
parent
f1388fffba
commit
f0d75eea0d
@ -46,7 +46,7 @@ time_t str2time(const std::string &str, TimeZone zone, TimeFormat fmt);
|
|||||||
|
|
||||||
inline std::string iso_utc_timestamp(time_t t)
|
inline std::string iso_utc_timestamp(time_t t)
|
||||||
{
|
{
|
||||||
return time2str(t, TimeZone::utc, TimeFormat::gcode);
|
return time2str(t, TimeZone::utc, TimeFormat::iso8601Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string iso_utc_timestamp()
|
inline std::string iso_utc_timestamp()
|
||||||
|
@ -12,18 +12,18 @@ namespace {
|
|||||||
void test_time_fmt(Slic3r::Utils::TimeFormat fmt) {
|
void test_time_fmt(Slic3r::Utils::TimeFormat fmt) {
|
||||||
using namespace Slic3r::Utils;
|
using namespace Slic3r::Utils;
|
||||||
time_t t = get_current_time_utc();
|
time_t t = get_current_time_utc();
|
||||||
|
|
||||||
std::string tstr = time2str(t, TimeZone::local, fmt);
|
std::string tstr = time2str(t, TimeZone::local, fmt);
|
||||||
time_t parsedtime = str2time(tstr, TimeZone::local, fmt);
|
time_t parsedtime = str2time(tstr, TimeZone::local, fmt);
|
||||||
REQUIRE(t == parsedtime);
|
REQUIRE(t == parsedtime);
|
||||||
|
|
||||||
tstr = time2str(t, TimeZone::utc, fmt);
|
tstr = time2str(t, TimeZone::utc, fmt);
|
||||||
parsedtime = str2time(tstr, TimeZone::utc, fmt);
|
parsedtime = str2time(tstr, TimeZone::utc, fmt);
|
||||||
REQUIRE(t == parsedtime);
|
REQUIRE(t == parsedtime);
|
||||||
|
|
||||||
parsedtime = str2time("not valid string", TimeZone::local, fmt);
|
parsedtime = str2time("not valid string", TimeZone::local, fmt);
|
||||||
REQUIRE(parsedtime == time_t(-1));
|
REQUIRE(parsedtime == time_t(-1));
|
||||||
|
|
||||||
parsedtime = str2time("not valid string", TimeZone::utc, fmt);
|
parsedtime = str2time("not valid string", TimeZone::utc, fmt);
|
||||||
REQUIRE(parsedtime == time_t(-1));
|
REQUIRE(parsedtime == time_t(-1));
|
||||||
}
|
}
|
||||||
@ -31,8 +31,21 @@ void test_time_fmt(Slic3r::Utils::TimeFormat fmt) {
|
|||||||
|
|
||||||
TEST_CASE("ISO8601Z", "[Timeutils]") {
|
TEST_CASE("ISO8601Z", "[Timeutils]") {
|
||||||
test_time_fmt(Slic3r::Utils::TimeFormat::iso8601Z);
|
test_time_fmt(Slic3r::Utils::TimeFormat::iso8601Z);
|
||||||
|
|
||||||
|
std::string mydate = "20190710T085000Z";
|
||||||
|
time_t t = Slic3r::Utils::parse_iso_utc_timestamp(mydate);
|
||||||
|
std::string date = Slic3r::Utils::iso_utc_timestamp(t);
|
||||||
|
|
||||||
|
REQUIRE(date == mydate);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Slic3r_UTC_Time_Format", "[Timeutils]") {
|
TEST_CASE("Slic3r_UTC_Time_Format", "[Timeutils]") {
|
||||||
test_time_fmt(Slic3r::Utils::TimeFormat::gcode);
|
using namespace Slic3r::Utils;
|
||||||
|
test_time_fmt(TimeFormat::gcode);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
REQUIRE(date == mydate);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user