diff --git a/src/espchrono.cpp b/src/espchrono.cpp index 5f772e7..8354fab 100644 --- a/src/espchrono.cpp +++ b/src/espchrono.cpp @@ -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 parseDateTime(std::string_view str) { // both valid: @@ -311,4 +325,9 @@ time_t toTimeT(utc_clock::time_point ts) { return std::chrono::duration_cast(ts.time_since_epoch()).count(); } + +time_t toTimeT(local_clock::time_point ts) +{ + return std::chrono::duration_cast(ts.time_since_epoch()).count(); +} } // namespace espchrono diff --git a/src/espchrono.h b/src/espchrono.h index 3123ce5..5f0e32d 100644 --- a/src/espchrono.h +++ b/src/espchrono.h @@ -195,6 +195,7 @@ DateTime toDateTime(std::chrono::microseconds ts); DateTime toDateTime(utc_clock::time_point ts); LocalDateTime toDateTime(local_clock::time_point ts); utc_clock::time_point fromDateTime(DateTime ts); +local_clock::time_point fromDateTime(LocalDateTime ts); std::expected parseDateTime(std::string_view str); @@ -214,4 +215,5 @@ std::string toString(minutes32 val); std::string toString(hours32 val); time_t toTimeT(utc_clock::time_point ts); +time_t toTimeT(local_clock::time_point ts); } // namespace espchrono