From 75c136924b8bd6e02b15c72272e06c0d768bfef0 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 10 Dec 2018 22:06:06 +0900 Subject: [PATCH] add datetimes to chrono --- toml/get.hpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/toml/get.hpp b/toml/get.hpp index 2c84de1..430c4cc 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -80,9 +80,48 @@ inline std::string get(value&& v) return std::move(v.cast().str); } +// ============================================================================ +// std::chrono::duration from toml::local_time. + +template::value, std::nullptr_t>::type = nullptr> +inline T get(value& v) +{ + return std::chrono::duration_cast( + std::chrono::microseconds(v.cast())); +} // ============================================================================ -// forward declaration. ignore this. +// std::chrono::system_clock::time_point from toml::datetime variants + +template::value, + std::nullptr_t>::type = nullptr> +inline T get(value& v) +{ + switch(v.type()) + { + case value_t::LocalDate: + { + return std::chrono::system_clock::time_point( + v.cast()); + } + case value_t::LocalDatetime: + { + return std::chrono::system_clock::time_point( + v.cast()); + } + default: + { + return std::chrono::system_clock::time_point( + v.cast()); + } + } +} + +// ============================================================================ +// forward declaration to use this recursively. ignore this and go ahead. + template, // T is container detail::has_resize_method, // T::resize(N) works