From 2b6930323f111165f149e1aa93bd774b7c581442 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Thu, 19 Sep 2024 23:41:30 +0200 Subject: [PATCH] latex3: fix one more time-ms overflow --- impls/latex3/core.sty | 19 ++++++++++++++++--- impls/latex3/types.sty | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/impls/latex3/core.sty b/impls/latex3/core.sty index 57ba2b4506..ff9c6df6c4 100644 --- a/impls/latex3/core.sty +++ b/impls/latex3/core.sty @@ -403,18 +403,31 @@ \tl_set:Nx \l_tmpa_tl { s \l_tmpa_str } } +% Seconds since the UNIX epoch * on first call to time-ms *. +\int_gzero_new:N \g_mal_first_epoch_int + \mal_def_builtin:nnn { time-ms } { time_ms } { % Seconds are not accurate enough for MAL tests, so use %s%N. % The raw nanosecond count overflows LaTeX integers. - % Extract the seconds, subtract the date of publication, - % then add the three millisecond digits. + % Even the millisecond count since 2024 overflows. \iow_term:n {MAL_LATEX3_STRIP_ON} \sys_get_shell:xnN { date ~ + \c_percent_str s \c_percent_str N} {} \l_tmpa_str \iow_term:n {MAL_LATEX3_STRIP_OFF} + % Extract the digits representing seconds. \int_set:Nx \l_tmpa_int { \tl_range:Vnn \l_tmpa_str 1 { -10 } } - \int_set:Nn \l_tmpa_int { \l_tmpa_int - 1723068439 } + % If this is the first time this function is called, + \int_if_zero:VTF \g_mal_first_epoch_int { + % then store the seconds since the epoch for later use + \int_gset_eq:NN \g_mal_first_epoch_int \l_tmpa_int + % and return 0 seconds + \int_zero:N \l_tmpa_int + } { + % else return the duration in seconds since first call + \int_set:Nn \l_tmpa_int { \l_tmpa_int - \g_mal_first_epoch_int } + } + % ... in both cases, append the three digits for millisecond. \tl_set:Nx \l_tmpa_tl { i \int_to_arabic:V \l_tmpa_int \tl_range:Vnn \l_tmpa_str { -9 } { -7 } } } diff --git a/impls/latex3/types.sty b/impls/latex3/types.sty index b524930c68..c5e2fb6545 100644 --- a/impls/latex3/types.sty +++ b/impls/latex3/types.sty @@ -5,6 +5,7 @@ \cs_generate_variant:Nn \int_compare:nNnTF { oNoTF } \cs_generate_variant:Nn \int_const:Nn { NV } +\cs_generate_variant:Nn \int_if_zero:nTF { VTF } \cs_generate_variant:Nn \int_set:Nn { Nx } \cs_generate_variant:Nn \int_to_alph:n { V } \cs_generate_variant:Nn \int_to_arabic:n { o, V }