diff --git a/include/date/tz.h b/include/date/tz.h index 8603c86..bab8b3c 100644 --- a/include/date/tz.h +++ b/include/date/tz.h @@ -2344,7 +2344,7 @@ struct clock_time_conversion sys_time operator()(const local_time& lt) const { - return sys_time{lt.time_sine_epoch()}; + return sys_time{lt.time_since_epoch()}; } }; diff --git a/test/tz_test/local_time_conversion.pass.cpp b/test/tz_test/local_time_conversion.pass.cpp new file mode 100644 index 0000000..d47c71f --- /dev/null +++ b/test/tz_test/local_time_conversion.pass.cpp @@ -0,0 +1,98 @@ +#include +#include "date/tz.h" + +int +main() +{ + using namespace date; + using namespace std::chrono_literals; + using namespace std::chrono; + + /// sys epoch + { + auto ls = local_days{1970_y/01/01_d}; + auto st = clock_cast(ls); + assert(clock_cast(st) == ls); + assert(st.time_since_epoch() == 0s); + } + + /// sys 2000 case + { + auto ls = local_days{2000_y/01/01_d}; + auto st = clock_cast(ls); + assert(clock_cast(st) == ls); + assert(st.time_since_epoch() == 946'684'800s); + } + + + /// utc epoch + { + auto lu = local_days{1970_y/01/01_d}; + auto ut = clock_cast(lu); + assert(clock_cast(ut) == lu); + assert(ut.time_since_epoch() == 0s); + } + + /// utc paper example + { + auto lu = local_days{2000_y/01/01_d}; + auto ut = clock_cast(lu); + assert(clock_cast(ut) == lu); + assert(ut.time_since_epoch() == 946'684'822s); + } + + /// tai epoch + { + auto lt = local_days{1958_y/01/01_d}; + auto tt = clock_cast(lt); + assert(clock_cast(tt) == lt); + assert(tt.time_since_epoch() == 0s); + + auto lu = local_days{1957_y/12/31_d} + 23h + 59min + 50s; + auto ut = clock_cast(lu); + assert(clock_cast(ut) == tt); + } + + // tai paper example + { + auto lt = local_days{2000_y/01/01_d} + 32s; + auto tt = clock_cast(lt); + assert(clock_cast(tt) == lt); + + auto lu = local_days{2000_y/01/01_d}; + auto ut = clock_cast(lu); + assert(clock_cast(ut) == tt); + } + + /// gps epoch + { + auto lg = local_days{1980_y/01/Sunday[1]}; + auto gt = clock_cast(lg); + assert(clock_cast(gt) == lg); + assert(gt.time_since_epoch() == 0s); + + auto lu = local_days{1980_y/01/Sunday[1]}; + auto ut = clock_cast(lu); + assert(clock_cast(ut) == gt); + + auto lt = local_days{1980_y/01/Sunday[1]} + 19s; + auto tt = clock_cast(lt); + assert(clock_cast(tt) == gt); + } + + // gps 2000 example + { + auto lg = local_days{2000_y/01/01_d}; + auto gt = clock_cast(lg); + assert(clock_cast(gt) == lg); + + auto lu = local_days{2000_y/01/01_d} - 13s; + auto ut = clock_cast(lu); + assert(clock_cast(ut) == gt); + + auto lt = local_days{2000_y/01/01_d} + 19s; + auto tt = clock_cast(lt); + assert(clock_cast(tt) == gt); + } + +}