@@ -66,33 +66,34 @@ TEST_CASE("clock, units")
66
66
67
67
TEST_CASE (" clock, time_t" )
68
68
{
69
+ const DateTime now_dt = clock::now ();
70
+ const time_t now_tt = time (nullptr );
71
+
69
72
// Round trip from DateTime to time_t and back.
70
73
// confirm that nothing happens other than truncating the fractional seconds
71
- const DateTime now_dt = clock::now ();
72
74
REQUIRE (clock::from_time_t (clock::to_time_t (now_dt)) == time_point_cast<seconds>(now_dt));
73
75
74
76
// Same thing in reverse
75
- const time_t now_tt = time (nullptr );
76
77
REQUIRE (clock::to_time_t (clock::from_time_t (now_tt)) == now_tt);
77
78
78
79
// Conversions are verified to be consistent. Now, verify that we're correctly converting epochs
79
- const auto diff = duration_cast<milliseconds>(abs (clock::now () - clock::from_time_t (time ( nullptr ) ))).count ();
80
+ const auto diff = duration_cast<milliseconds>(abs (now_dt - clock::from_time_t (now_tt ))).count ();
80
81
REQUIRE (diff < 1000 );
81
82
}
82
83
83
84
TEST_CASE (" clock, FILETIME" )
84
85
{
85
- // Round trip conversions
86
86
const DateTime now_dt = clock::now ();
87
- REQUIRE (clock::from_file_time (clock::to_file_time (now_dt)) == now_dt);
88
-
89
87
FILETIME now_ft;
90
88
::GetSystemTimePreciseAsFileTime (&now_ft);
89
+
90
+ // Round trip conversions
91
+ REQUIRE (clock::from_file_time (clock::to_file_time (now_dt)) == now_dt);
92
+
91
93
REQUIRE (clock::to_file_time (clock::from_file_time (now_ft)) == now_ft);
92
94
93
95
// Verify epoch
94
- ::GetSystemTimePreciseAsFileTime (&now_ft);
95
- const auto diff = abs (clock::now () - clock::from_file_time (now_ft));
96
+ const auto diff = abs (now_dt - clock::from_file_time (now_ft));
96
97
REQUIRE (diff < milliseconds{ 100 });
97
98
}
98
99
0 commit comments