22 #include <string_view>
24 #if __cpp_lib_chrono >= 201907L
25 #define CPP20_CHRONO_SUPPORT
30 #ifdef CPP20_CHRONO_SUPPORT
39 using days = std::chrono::duration<int, std::ratio<86400>>;
40 using weeks = std::chrono::duration<int, std::ratio<604800>>;
41 using months = std::chrono::duration<int, std::ratio<2629746>>;
42 using years = std::chrono::duration<int, std::ratio<31556952>>;
48 return std::chrono::system_clock::from_time_t(val);
53 return std::chrono::system_clock::from_time_t(val.
to_long_long());
58 return std::chrono::system_clock::to_time_t(time);
63 std::ostringstream ss;
64 auto as_time_t = std::chrono::system_clock::to_time_t(time);
65 ss << std::put_time(std::localtime(&as_time_t),
format.data());
69 template<
typename Duration>
75 template<
typename... Ts,
typename Rep,
typename Period>
76 constexpr
auto deconstruct_duration(
const std::tuple<Ts...>&,
const std::chrono::duration<Rep, Period>& span)
78 auto time_remaining = std::chrono::duration_cast<std::common_type_t<Ts...>>(span);
79 return std::tuple{[&time_remaining]() {
80 auto duration = std::chrono::duration_cast<Ts>(time_remaining);
81 time_remaining -= duration;
Variant for storing WML attributes.
long long to_long_long(long long def=0) const
Definitions for the interface to Wesnoth Markup Language (WML).
std::chrono::duration< int, std::ratio< 2629746 > > months
auto serialize_timestamp(const std::chrono::system_clock::time_point &time)
auto parse_timestamp(long long val)
auto parse_duration(const config_attribute_value &val, const Duration &def=Duration{0})
auto format_local_timestamp(const std::chrono::system_clock::time_point &time, std::string_view format="%F %T")
std::chrono::duration< int, std::ratio< 31556952 > > years
std::chrono::duration< int, std::ratio< 604800 > > weeks
constexpr auto deconstruct_duration(const std::tuple< Ts... > &, const std::chrono::duration< Rep, Period > &span)
std::chrono::duration< int, std::ratio< 86400 > > days