Implemented custom time zone deduction test.

Implemented test for deduction from the custom time zone ptr.
Used OffsetZone extracted for that purpose.
This commit is contained in:
Tomasz Kamiński
2019-09-01 14:43:50 -04:00
committed by Howard Hinnant
parent 7c020642fb
commit 5345d135b7
3 changed files with 83 additions and 44 deletions
+1 -44
View File
@@ -23,50 +23,7 @@
// Test custom time zone support
#include "tz.h"
class OffsetZone
{
std::chrono::minutes offset_;
public:
explicit OffsetZone(std::chrono::minutes offset)
: offset_{offset}
{}
template <class Duration>
auto
to_local(date::sys_time<Duration> tp) const
{
using namespace date;
using namespace std::chrono;
using LT = local_time<std::common_type_t<Duration, minutes>>;
return LT{(tp + offset_).time_since_epoch()};
}
template <class Duration>
auto
to_sys(date::local_time<Duration> tp) const
{
using namespace date;
using namespace std::chrono;
using ST = sys_time<std::common_type_t<Duration, minutes>>;
return ST{(tp - offset_).time_since_epoch()};
}
template <class Duration>
date::sys_info
get_info(date::sys_time<Duration> st) const
{
using namespace date;
using namespace std::chrono;
return {sys_seconds::min(), sys_seconds::max(), offset_,
minutes{0}, offset_ >= minutes{0} ? "+" + date::format("%H%M", offset_)
: "-" + date::format("%H%M", -offset_)};
}
const OffsetZone* operator->() const {return this;}
};
#include "OffsetZone.h"
#include <cassert>
int