Merge branch 'main' of github.com:rconybea/indentlog

This commit is contained in:
Roland Conybeare 2023-10-17 14:37:27 -04:00
commit 5fb7586fea
5 changed files with 39 additions and 23 deletions

View file

@ -1,5 +1,9 @@
# indentlog build details
## mac osx
Note: ~ expansion doesn't work in a pure build environment.
## Test Coverage
### enable coverage build

View file

@ -38,8 +38,9 @@ xo_add_headeronly_library(indentlog)
# ----------------------------------------------------------------
# standard install + provide find_package() support
#xo_install_library2(indentlog)
#xo_install_include_tree()
xo_install_library3(indentlog ${PROJECT_NAME}Targets)
xo_install_include_tree()
xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets)
# ----------------------------------------------------------------

View file

@ -232,7 +232,7 @@ namespace xo {
} /*nesting_level*/
template <typename CharT, typename Traits>
basic_scope<CharT, Traits>::state_impl_type *
typename basic_scope<CharT, Traits>::state_impl_type *
basic_scope<CharT, Traits>::require_indent_thread_local_state()
{
state_impl_type * local_state = require_thread_local_state();
@ -244,7 +244,7 @@ namespace xo {
} /*require_thread_local_stream*/
template <typename CharT, typename Traits>
basic_scope<CharT, Traits>::state_impl_type *
typename basic_scope<CharT, Traits>::state_impl_type *
basic_scope<CharT, Traits>::require_thread_local_state()
{
if(!s_threadlocal_state) {

View file

@ -13,10 +13,6 @@
namespace xo {
namespace time {
using utc_nanos = std::chrono::time_point<std::chrono::system_clock,
std::chrono::nanoseconds>;
using nanos = std::chrono::nanoseconds;
using microseconds = std::chrono::microseconds;
using milliseconds = std::chrono::milliseconds;
@ -24,6 +20,12 @@ namespace xo {
using hours = std::chrono::hours;
using days = std::chrono::days;
using utc_nanos = std::chrono::time_point<std::chrono::system_clock,
std::chrono::nanoseconds>;
using utc_micros = std::chrono::time_point<std::chrono::system_clock,
std::chrono::microseconds>;
struct timeutil {
static utc_nanos now() {
return utc_nanos(std::chrono::system_clock::now());
@ -168,7 +170,9 @@ namespace xo {
/* use yyyymmdd.hh:mm:ss.nnnnnn */
time_t t0_time_t = (std::chrono::system_clock::to_time_t(t0));
time_t t0_time_t
= (std::chrono::system_clock::to_time_t
(std::chrono::time_point_cast<microseconds>(t0)));
//time_t t0_time_t = (std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<xo::time::microseconds>(t0)));
/* convert to std::tm, in UTC coords,

View file

@ -10,75 +10,82 @@ using namespace xo::time;
using namespace std::chrono;
namespace ut {
template <typename FromTime>
inline utc_micros to_micros(FromTime tm) {
return std::chrono::time_point_cast<xo::time::microseconds>(tm);
} /*to_micros*/
TEST_CASE("epoch", "[timeutil]") {
//tag_config::tag_color = color_spec_type::none();
using xo::time::microseconds;
utc_nanos t0 = timeutil::epoch();
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(0));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(0));
} /*TEST_CASE(epoch)*/
TEST_CASE("ymd_hms", "[timeutil]") {
{
utc_nanos t0 = timeutil::ymd_hms(19700101 /*ymd*/, 0 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(0));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(0));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700101 /*ymd*/, 1 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(1));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(1));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700101 /*ymd*/, 100 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(60));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(60));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700101 /*ymd*/, 10000 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(3600));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(3600));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700101 /*ymd*/, 235959 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(86399));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(86399));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700102 /*ymd*/, 235959 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(86400 + 86399));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(86400 + 86399));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700131 /*ymd*/, 235959 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(30 * 86400 + 86399));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(30 * 86400 + 86399));
}
{
utc_nanos t0 = timeutil::ymd_hms(19700201 /*ymd*/, 235959 /*hms*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(31 * 86400 + 86399));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(31 * 86400 + 86399));
}
} /*TEST_CASE(ymd_hms)*/
TEST_CASE("ymd_midnight", "[timeutil]") {
{
utc_nanos t0 = timeutil::ymd_midnight(19700101 /*ymd*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(0));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(0));
}
{
utc_nanos t0 = timeutil::ymd_midnight(19700102 /*ymd*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(86400));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(86400));
}
{
utc_nanos t0 = timeutil::ymd_midnight(19700131 /*ymd*/);
REQUIRE(std::chrono::system_clock::to_time_t(t0) == std::time_t(30 * 86400));
REQUIRE(std::chrono::system_clock::to_time_t(to_micros(t0)) == std::time_t(30 * 86400));
}
{
utc_nanos t0 = timeutil::ymd_midnight(19700201 /*ymd*/);
REQUIRE(system_clock::to_time_t(t0) == std::time_t(31 * 86400));
REQUIRE(system_clock::to_time_t(to_micros(t0)) == std::time_t(31 * 86400));
}
} /*TEST_CASE(ymd_midnight)*/
@ -144,10 +151,10 @@ namespace ut {
INFO(xtag("tc.utc_ymd_hms_usec_str", tc.utc_ymd_hms_usec_str_));
utc_nanos const t0 = timeutil::ymd_hms_usec(tc.ymd_, tc.hms_, tc.usec_);
REQUIRE(system_clock::to_time_t(t0) == std::time_t(tc.epoch_sec_));
REQUIRE(system_clock::to_time_t(to_micros(t0)) == std::time_t(tc.epoch_sec_));
auto x = timeutil::utc_split_vs_midnight(t0);
REQUIRE(system_clock::to_time_t(x.first) == tc.midnight_sec_);
REQUIRE(system_clock::to_time_t(to_micros(x.first)) == tc.midnight_sec_);
REQUIRE(x.second == seconds(tc.fractional_sec_) + microseconds(tc.fractional_usec_));
{