diff --git a/tests/mysql/usage/DateTimeTest.cpp b/tests/mysql/usage/DateTimeTest.cpp index 34523913..1cfc848a 100644 --- a/tests/mysql/usage/DateTimeTest.cpp +++ b/tests/mysql/usage/DateTimeTest.cpp @@ -48,6 +48,21 @@ namespace serialize(::sqlpp::wrap_operand_t{l}, std::cerr); std::cerr << " != "; serialize(::sqlpp::wrap_operand_t{r}, std::cerr); + std::cerr << "\n" ; + throw std::runtime_error("Unexpected result"); + } + } + + template + auto require_close(int line, const L& l, const R& r) -> void + { + if (std::chrono::abs(l - r) > std::chrono::seconds{1}) + { + std::cerr << line << ": abs("; + serialize(::sqlpp::wrap_operand_t{l}, std::cerr); + std::cerr << " - "; + serialize(::sqlpp::wrap_operand_t{r}, std::cerr); + std::cerr << ") > 1s\n" ; throw std::runtime_error("Unexpected result"); } } @@ -78,9 +93,8 @@ int main() try { - using days_type = std::chrono::duration>; - mysql::connection db(config); + db.execute(R"(SET time_zone = '+00:00')"); // To force MySQL's CURRENT_TIMESTAMP into the right timezone db.execute(R"(DROP TABLE IF EXISTS tab_date_time)"); db.execute(R"(CREATE TABLE tab_date_time ( col_day_point date, @@ -96,14 +110,14 @@ int main() require_equal(__LINE__, row.colDayPoint.value(), ::sqlpp::chrono::day_point{}); require_equal(__LINE__, row.colTimePoint.is_null(), true); require_equal(__LINE__, row.colTimePoint.value(), ::sqlpp::chrono::microsecond_point{}); - require_equal(__LINE__, std::chrono::time_point_cast(row.colDateTimePoint.value()), std::chrono::time_point_cast(std::chrono::system_clock::now())); + require_close(__LINE__, row.colDateTimePoint.value(), std::chrono::system_clock::now()); } auto statement = db.prepare(select(tab.colDateTimePoint).from(tab).unconditionally()); for (const auto& row : db(statement)) { require_equal(__LINE__, row.colDateTimePoint.is_null(), false); - require_equal(__LINE__, std::chrono::time_point_cast(row.colDateTimePoint.value()), std::chrono::time_point_cast(std::chrono::system_clock::now())); + require_close(__LINE__, row.colDateTimePoint.value(), std::chrono::system_clock::now()); } db(update(tab).set(tab.colDayPoint = today, tab.colTimePoint = now).unconditionally());