File tree Expand file tree Collapse file tree 3 files changed +9
-31
lines changed
scaffolding_tests/chronological Expand file tree Collapse file tree 3 files changed +9
-31
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,6 @@ target_include_directories(uniffi_${TEST_NAME} PRIVATE scaffolding_tests/${TEST_
47
47
add_executable (${TEST_NAME} -scaffolding-test tests/${TEST_NAME}/main.cpp ${BINDINGS_SRC_DIR} /${TEST_NAME}.cpp )
48
48
target_include_directories (${TEST_NAME} -scaffolding-test PRIVATE ${BINDINGS_SRC_DIR} include )
49
49
target_link_libraries (${TEST_NAME} -scaffolding-test uniffi_${TEST_NAME} Threads::Threads )
50
- target_compile_definitions (${TEST_NAME} -scaffolding-test PRIVATE SCAFFOLDING_TEST=1 )
51
50
52
51
add_test (NAME ${TEST_NAME} -scaffolding-test COMMAND ${TEST_NAME} -scaffolding-test )
53
52
memcheck_test (${TEST_NAME} -scaffolding-test )
Original file line number Diff line number Diff line change @@ -14,9 +14,18 @@ chronological::duration chronological::return_duration(chronological::duration a
14
14
15
15
std::string chronological::to_string_timestamp (chronological::timestamp a) {
16
16
std::time_t time = std::chrono::system_clock::to_time_t (a);
17
+ auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(a.time_since_epoch ()).count () % 1000000000 ;
18
+ if (ns < 0 ) {
19
+ ns += 1000000000 ;
20
+ time -= 1 ;
21
+ }
22
+
17
23
std::tm tm = *std::gmtime (&time);
18
24
std::stringstream ss;
19
25
ss << std::put_time (&tm, " %Y-%m-%dT%H:%M:%S" );
26
+ ss<< " ." << std::setfill (' 0' ) << std::setw (9 ) << ns;
27
+ ss << " Z" ;
28
+
20
29
return ss.str ();
21
30
}
22
31
Original file line number Diff line number Diff line change @@ -53,32 +53,6 @@ void test_string_timestamps() {
53
53
}
54
54
}
55
55
56
- void test_scaffolding_string_timestamps () {
57
- {
58
- auto time_str = " 1970-01-01T00:00:00" ;
59
- auto time = time_from_string (time_str);
60
-
61
- ASSERT_EQ (time_str, chronological::to_string_timestamp (time));
62
- }
63
-
64
- {
65
- auto time_str = " 1970-12-31T23:59:58" ;
66
- auto time = time_from_string (time_str);
67
-
68
- ASSERT_EQ (time_str, chronological::to_string_timestamp (time));
69
- }
70
-
71
- {
72
- auto time = time_from_string (" 1979-11-05T00:06:01" ) + 283000200ns;
73
- auto time2 = time_from_string (" 1979-11-05T00:06:00" ) + 283000100ns;
74
-
75
- ASSERT_EQ (
76
- time,
77
- chronological::add (time2, time_span_seconds (1 , 100 ))
78
- );
79
- }
80
- }
81
-
82
56
int main () {
83
57
ASSERT_EQ (
84
58
epoch_second (101 , 110 ),
@@ -110,11 +84,7 @@ int main() {
110
84
chronological::return_duration (std::chrono::nanoseconds::max ())
111
85
);
112
86
113
- #ifdef SCAFFOLDING_TEST
114
- test_scaffolding_string_timestamps ();
115
- #else
116
87
test_string_timestamps ();
117
- #endif
118
88
119
89
auto before = std::chrono::system_clock::now ();
120
90
std::this_thread::sleep_for (1s);
You can’t perform that action at this time.
0 commit comments