Add fromDateTime()
This commit is contained in:
@ -133,7 +133,6 @@ local_clock::time_point utcToLocal(utc_clock::time_point ts)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
|
||||||
DateTime toDateTime(std::chrono::microseconds ts)
|
DateTime toDateTime(std::chrono::microseconds ts)
|
||||||
{
|
{
|
||||||
auto _time = ts.count();
|
auto _time = ts.count();
|
||||||
@ -189,7 +188,6 @@ DateTime toDateTime(std::chrono::microseconds ts)
|
|||||||
dateTime.dayOfWeek = dayOfWeek;
|
dateTime.dayOfWeek = dayOfWeek;
|
||||||
return dateTime;
|
return dateTime;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DateTime toDateTime(utc_clock::time_point ts)
|
DateTime toDateTime(utc_clock::time_point ts)
|
||||||
{
|
{
|
||||||
@ -204,6 +202,19 @@ LocalDateTime toDateTime(local_clock::time_point ts)
|
|||||||
return dateTime;
|
return dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utc_clock::time_point fromDateTime(DateTime ts)
|
||||||
|
{
|
||||||
|
const sys_days date = ts.date;
|
||||||
|
return utc_clock::time_point {
|
||||||
|
date.time_since_epoch()
|
||||||
|
+ std::chrono::hours{ts.hour}
|
||||||
|
+ std::chrono::minutes{ts.minute}
|
||||||
|
+ std::chrono::seconds{ts.second}
|
||||||
|
+ std::chrono::milliseconds{ts.millisecond}
|
||||||
|
+ std::chrono::microseconds{ts.microsecond}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
std::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
std::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
||||||
{
|
{
|
||||||
// both valid:
|
// both valid:
|
||||||
|
@ -191,8 +191,10 @@ utc_clock::time_point localToUtc(local_clock::time_point local);
|
|||||||
local_clock::time_point utcToLocal(utc_clock::time_point ts);
|
local_clock::time_point utcToLocal(utc_clock::time_point ts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
DateTime toDateTime(std::chrono::microseconds ts);
|
||||||
DateTime toDateTime(utc_clock::time_point ts);
|
DateTime toDateTime(utc_clock::time_point ts);
|
||||||
LocalDateTime toDateTime(local_clock::time_point ts);
|
LocalDateTime toDateTime(local_clock::time_point ts);
|
||||||
|
utc_clock::time_point fromDateTime(DateTime ts);
|
||||||
|
|
||||||
std::expected<DateTime, std::string> parseDateTime(std::string_view str);
|
std::expected<DateTime, std::string> parseDateTime(std::string_view str);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user