Implement more functions for working with local_time
This commit is contained in:
@@ -215,6 +215,20 @@ utc_clock::time_point fromDateTime(DateTime ts)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local_clock::time_point fromDateTime(LocalDateTime ts)
|
||||||
|
{
|
||||||
|
const sys_days date = ts.date;
|
||||||
|
return local_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}
|
||||||
|
, ts.timezone, ts.dst
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
std::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
std::expected<DateTime, std::string> parseDateTime(std::string_view str)
|
||||||
{
|
{
|
||||||
// both valid:
|
// both valid:
|
||||||
@@ -311,4 +325,9 @@ time_t toTimeT(utc_clock::time_point ts)
|
|||||||
{
|
{
|
||||||
return std::chrono::duration_cast<std::chrono::seconds>(ts.time_since_epoch()).count();
|
return std::chrono::duration_cast<std::chrono::seconds>(ts.time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t toTimeT(local_clock::time_point ts)
|
||||||
|
{
|
||||||
|
return std::chrono::duration_cast<std::chrono::seconds>(ts.time_since_epoch()).count();
|
||||||
|
}
|
||||||
} // namespace espchrono
|
} // namespace espchrono
|
||||||
|
@@ -195,6 +195,7 @@ 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);
|
utc_clock::time_point fromDateTime(DateTime ts);
|
||||||
|
local_clock::time_point fromDateTime(LocalDateTime ts);
|
||||||
|
|
||||||
std::expected<DateTime, std::string> parseDateTime(std::string_view str);
|
std::expected<DateTime, std::string> parseDateTime(std::string_view str);
|
||||||
|
|
||||||
@@ -214,4 +215,5 @@ std::string toString(minutes32 val);
|
|||||||
std::string toString(hours32 val);
|
std::string toString(hours32 val);
|
||||||
|
|
||||||
time_t toTimeT(utc_clock::time_point ts);
|
time_t toTimeT(utc_clock::time_point ts);
|
||||||
|
time_t toTimeT(local_clock::time_point ts);
|
||||||
} // namespace espchrono
|
} // namespace espchrono
|
||||||
|
Reference in New Issue
Block a user