mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
Time conversion functions with tests.
Fixes issue with incorrect characters in time strings on UI. Fix platform dependency Fix return value with incorrect strings. Just use strptime and strftime on all platforms. Emulate strptime on msvc... because they don't have it and their get_time is buggy.
This commit is contained in:
parent
f29e18dad2
commit
d5dcba00b1
10 changed files with 296 additions and 99 deletions
41
tests/timeutils/timeutils_tests_main.cpp
Normal file
41
tests/timeutils/timeutils_tests_main.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "libslic3r/Time.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
|
||||
namespace {
|
||||
|
||||
void test_time_fmt(Slic3r::Utils::TimeFormat fmt) {
|
||||
using namespace Slic3r::Utils;
|
||||
time_t t = get_current_time_utc();
|
||||
|
||||
std::string tstr = time2str(t, TimeZone::local, fmt);
|
||||
time_t parsedtime = str2time(tstr, TimeZone::local, fmt);
|
||||
ASSERT_EQ(t, parsedtime);
|
||||
|
||||
tstr = time2str(t, TimeZone::utc, fmt);
|
||||
parsedtime = str2time(tstr, TimeZone::utc, fmt);
|
||||
ASSERT_EQ(t, parsedtime);
|
||||
|
||||
parsedtime = str2time("not valid string", TimeZone::local, fmt);
|
||||
ASSERT_EQ(parsedtime, time_t(-1));
|
||||
|
||||
parsedtime = str2time("not valid string", TimeZone::utc, fmt);
|
||||
ASSERT_EQ(parsedtime, time_t(-1));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Timeutils, ISO8601Z) {
|
||||
test_time_fmt(Slic3r::Utils::TimeFormat::iso8601Z);
|
||||
}
|
||||
|
||||
TEST(Timeutils, Slic3r_UTC_Time_Format) {
|
||||
test_time_fmt(Slic3r::Utils::TimeFormat::gcode);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue