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 Rep,
typename Period>
78 auto days = std::chrono::duration_cast<chrono::days>(span);
79 auto hours = std::chrono::duration_cast<std::chrono::hours>(span -
days);
80 auto minutes = std::chrono::duration_cast<std::chrono::minutes>(span -
days - hours);
81 auto seconds = std::chrono::duration_cast<std::chrono::seconds>(span -
days - hours - minutes);
83 return std::tuple{
days, hours, minutes, seconds };
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
std::chrono::duration< int, std::ratio< 86400 > > days
constexpr auto deconstruct_duration(const std::chrono::duration< Rep, Period > &span)