Skip to content

Commit

Permalink
Choosing the "correct" floor method even with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
rbock committed Apr 17, 2016
1 parent 91defe2 commit c63aac4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion include/sqlpp11/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef SQLPP_CHRONO_H
#define SQLPP_CHRONO_H

#include <chrono>
#include <date.h>

namespace sqlpp
{
Expand All @@ -37,6 +37,13 @@ namespace sqlpp

using day_point = std::chrono::time_point<std::chrono::system_clock, days>;
using microsecond_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>;

#if _MSC_FULL_VER >= 190023918
// MSVC Update 2 provides floor, ceil, round, abs in chrono (which is C++17 only...)
using ::std::chrono::floor;
#else
using ::date::floor;
#endif
}
}

Expand Down
3 changes: 1 addition & 2 deletions include/sqlpp11/data_types/time_point/operand.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#ifndef SQLPP_TIME_POINT_OPERAND_H
#define SQLPP_TIME_POINT_OPERAND_H

#include <date.h>
#include <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
Expand Down Expand Up @@ -76,7 +75,7 @@ namespace sqlpp

static Context& _(const Operand& t, Context& context)
{
const auto dp = ::date::floor<::date::days>(t._t);
const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t);
const auto time = ::date::make_time(t._t - dp);
const auto ymd = ::date::year_month_day{dp};
context << "TIMESTAMP '" << ymd << ' ' << time << "'";
Expand Down
3 changes: 2 additions & 1 deletion include/sqlpp11/data_types/time_point/result_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef SQLPP_TIME_POINT_RESULT_FIELD_H
#define SQLPP_TIME_POINT_RESULT_FIELD_H

#include <sqlpp11/chrono.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
Expand Down Expand Up @@ -63,7 +64,7 @@ namespace sqlpp
}
else
{
const auto dp = ::date::floor<::date::days>(e.value());
const auto dp = ::sqlpp::chrono::floor<::date::days>(e.value());
const auto time = ::date::make_time(e.value() - dp);
const auto ymd = ::date::year_month_day{dp};
os << ymd << 'T' << time;
Expand Down

0 comments on commit c63aac4

Please sign in to comment.