<div dir="ltr">Hello,<div><br></div><div>May I ask if there are any updates?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 17, 2024 at 3:08 PM HONG Yifan <<a href="mailto:elsk@google.com">elsk@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The code below with "If format didn't already specify seconds, grab<br>
seconds" detects whether the format contains seconds by relying on the<br>
index of the format (with an i>2 predicate). However, the format<br>
"%a %b %e %H:%M:%S %Z %Y" does not end with seconds, so we shouldn't<br>
parse fraction of seconds here. On the other hand, the format<br>
"%H:%M:%S" ends with seconds, so we should parse fraction of seconds<br>
there.<br>
<br>
Add a test for it; the test uses a >60 number for fraction of seconds<br>
to trigger the bug before the fix. Without the fix, "12:34:56.777" are<br>
recognized as "12:34:77", which is an invalid time.<br>
<br>
Fixes: d1a446687a9c<br>
    ("xparsedate: support default date(1) output format.")<br>
---<br>
 lib/xwrap.c     | 3 ++-<br>
 tests/date.test | 3 +++<br>
 2 files changed, 5 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/lib/xwrap.c b/lib/xwrap.c<br>
index d07f355a..e5b35bb7 100644<br>
--- a/lib/xwrap.c<br>
+++ b/lib/xwrap.c<br>
@@ -1025,8 +1025,9 @@ void xparsedate(char *str, time_t *t, unsigned *nano, int endian)<br>
   // Formats with seconds come first. Posix can't agree on whether 12 digits<br>
   // has year before (touch -t) or year after (date), so support both.<br>
   char *s = str, *p, *oldtz = 0, *formats[] = {"%Y-%m-%d %T", "%Y-%m-%dT%T",<br>
+    "%H:%M:%S",<br>
     "%a %b %e %H:%M:%S %Z %Y", // date(1) output format in POSIX/C locale.<br>
-    "%H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d", "%H:%M", "%m%d%H%M",<br>
+    "%Y-%m-%d %H:%M", "%Y-%m-%d", "%H:%M", "%m%d%H%M",<br>
     endian ? "%m%d%H%M%y" : "%y%m%d%H%M",<br>
     endian ? "%m%d%H%M%C%y" : "%C%y%m%d%H%M"};<br>
<br>
diff --git a/tests/date.test b/tests/date.test<br>
index 9777edb3..3ec2659e 100644<br>
--- a/tests/date.test<br>
+++ b/tests/date.test<br>
@@ -42,6 +42,9 @@ testing "Unix time missing @" "TZ=$tz date 1438053157 2>/dev/null || echo no" \<br>
 testing "-d 12:34" 'TZ=UTC date -d 12:34 | grep -q " 12:34:00 UTC $this_year" && echo OK' "OK\n" "" ""<br>
 testing "-d 12:34:56" 'TZ=UTC date -d 12:34:56 | grep -q " 12:34:56 UTC $this_year" && echo OK' "OK\n" "" ""<br>
<br>
+# Test fraction<br>
+testing "-d 12:34:56.777" 'date -d 12:34:56.777 +%H:%M:%S.%3N | grep -q "12:34:56.777" && echo OK' "OK\n" "" ""<br>
+<br>
 # Test the %N extension to srtftime(3) format strings.<br>
 testing "%N" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%M%S.%N" "20120123-123456.123456789\n" "" ""<br>
 testing "%1N" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%M%S.%1N" "20120123-123456.1\n" "" ""<br>
-- <br>
2.46.0.662.g92d0881bb0-goog<br>
<br>
</blockquote></div>