[date_time_scanner] handle ambiguous time exception

This commit is contained in:
Tim Stack 2024-11-04 10:49:16 -08:00
parent 94fbf33a93
commit cc6e5af40d
7 changed files with 45 additions and 7 deletions

View File

@ -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<std::chrono::seconds>(
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);
}

View File

@ -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 \

View File

@ -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 \

View File

@ -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

10
test/logfile_dst.0 Normal file
View File

@ -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

View File

@ -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