From cc6e5af40dd06aae9941accebb9332667367a759 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Mon, 4 Nov 2024 10:49:16 -0800 Subject: [PATCH] [date_time_scanner] handle ambiguous time exception --- src/base/date_time_scanner.cc | 23 +++++++++++++------ test/Makefile.am | 1 + test/expected/expected.am | 2 ++ ...6472800fd625a8ffe16a1f392053590246c1a2.err | 0 ...6472800fd625a8ffe16a1f392053590246c1a2.out | 10 ++++++++ test/logfile_dst.0 | 10 ++++++++ test/test_logfile.sh | 6 +++++ 7 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.err create mode 100644 test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.out create mode 100644 test/logfile_dst.0 diff --git a/src/base/date_time_scanner.cc b/src/base/date_time_scanner.cc index 31b7bef8..fd12d172 100644 --- a/src/base/date_time_scanner.cc +++ b/src/base/date_time_scanner.cc @@ -177,13 +177,22 @@ date_time_scanner::scan(const char* time_dest, && !(tm_out->et_flags & ETF_EPOCH_TIME) && this->dts_default_zone != nullptr) { - date::local_seconds stime; - stime += std::chrono::seconds{gmt}; - auto ztime - = date::make_zoned(this->dts_default_zone, stime); - gmt = std::chrono::duration_cast( - ztime.get_sys_time().time_since_epoch()) - .count(); + try { + date::local_seconds stime; + stime += std::chrono::seconds{gmt}; + auto ztime + = date::make_zoned(this->dts_default_zone, + stime, + date::choose::earliest); + gmt = std::chrono::duration_cast< + std::chrono::seconds>( + ztime.get_sys_time().time_since_epoch()) + .count(); + } catch (const std::exception& e) { + log_error("failed to convert time %d -- %s", + gmt, + e.what()); + } } this->to_localtime(gmt, *tm_out); } diff --git a/test/Makefile.am b/test/Makefile.am index 356aa45b..c5c70b6c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -336,6 +336,7 @@ dist_noinst_DATA = \ logfile_docker_compose.0 \ logfile_docker_compose_with_noise.0 \ logfile_docker_compose_with_ts.0 \ + logfile_dst.0 \ logfile_empty.0 \ logfile_epoch.0 \ logfile_epoch.1 \ diff --git a/test/expected/expected.am b/test/expected/expected.am index ad998e0d..61760cc8 100644 --- a/test/expected/expected.am +++ b/test/expected/expected.am @@ -384,6 +384,8 @@ EXPECTED_FILES = \ $(srcdir)/%reldir%/test_logfile.sh_3fc6bfd8a6160817211f3e14fde957af75b9dbe7.out \ $(srcdir)/%reldir%/test_logfile.sh_4a2a907fcb069b8d6e65961a7b2e796d6c3a87b1.err \ $(srcdir)/%reldir%/test_logfile.sh_4a2a907fcb069b8d6e65961a7b2e796d6c3a87b1.out \ + $(srcdir)/%reldir%/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.err \ + $(srcdir)/%reldir%/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.out \ $(srcdir)/%reldir%/test_logfile.sh_6602faf7817c494c33e32da7ee95f13aa9210d01.err \ $(srcdir)/%reldir%/test_logfile.sh_6602faf7817c494c33e32da7ee95f13aa9210d01.out \ $(srcdir)/%reldir%/test_logfile.sh_7c2e11488bccc59458b5775db4b90de964858259.err \ diff --git a/test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.err b/test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.err new file mode 100644 index 00000000..e69de29b diff --git a/test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.out b/test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.out new file mode 100644 index 00000000..f512cfa7 --- /dev/null +++ b/test/expected/test_logfile.sh_4f6472800fd625a8ffe16a1f392053590246c1a2.out @@ -0,0 +1,10 @@ +Nov 03 01:01:03 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:13:04 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:23:29 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:41:30 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:59:14 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:59:14 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:59:14 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 01:59:14 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 02:08:19 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 03 02:25:02 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics diff --git a/test/logfile_dst.0 b/test/logfile_dst.0 new file mode 100644 index 00000000..873b7fb7 --- /dev/null +++ b/test/logfile_dst.0 @@ -0,0 +1,10 @@ +Nov 3 01:01:03 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:13:04 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:23:29 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:41:30 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:59:14 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:24:56 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:38:13 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 01:50:16 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 02:08:19 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics +Nov 3 02:25:02 Tims-MacBook-Air syslogd[634]: ASL Sender Statistics diff --git a/test/test_logfile.sh b/test/test_logfile.sh index e71ac2eb..e6151bda 100644 --- a/test/test_logfile.sh +++ b/test/test_logfile.sh @@ -742,3 +742,9 @@ run_cap_test ${lnav_test} -n \ run_cap_test ${lnav_test} -n \ -c ';SELECT log_time FROM all_logs' \ ${test_dir}/logfile_yday.0 + +touch -t 202411030000 ${test_dir}/logfile_dst.0 + +run_cap_test env TZ=America/Los_Angeles ${lnav_test} -n \ + -c ':set-file-timezone America/Los_Angeles' \ + ${test_dir}/logfile_dst.0