Subject: [PATCH] vc-hg-annotate-time extracts incorrect dates

From: Kjetil Ørbekk <[email-masked]>
Date: Fri, 29 Dec 2023 09:21:52 -0500

Hi,

I noticed that vc-hg-annotate-time constructs a timestamp based on
incorrect strings. E.g., the date "2014-11-28" is interpreted as year
2014, day -1, month 1.

Please see the attached patch for a fix.

-- 
Kjetil

>From 47274868e458f92073eb75bb48f6e34564f020e5 Mon Sep 17 00:00:00 2001
From: Kjetil Orbekk <[email-masked]>
Date: Fri, 29 Dec 2023 08:59:23 -0500
Subject: [PATCH] Fix vg-hg-annotate-time bug

* lisp/vc/vc-hg.el (vc-hg-annotate-time): Fix extraction of timestamp
from string.
* test/lisp/vc/vc-hg-tests.el (vc-hg-annotate-time): Test that the
correct timestamp is found.

Copyright-paperwork-exempt: yes
---
 lisp/vc/vc-hg.el            | 4 ++--
 test/lisp/vc/vc-hg-tests.el | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index d6dadb7..10be29c 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -584,8 +584,8 @@ vc-hg-annotate-time
     (vc-annotate-convert-time
      (let ((str (match-string-no-properties 2)))
        (encode-time 0 0 0
-                    (string-to-number (substring str 6 8))
-                    (string-to-number (substring str 4 6))
+                    (string-to-number (substring str 8 10))
+                    (string-to-number (substring str 5 7))
                     (string-to-number (substring str 0 4)))))))
 
 (defun vc-hg-annotate-extract-revision-at-line ()
diff --git a/test/lisp/vc/vc-hg-tests.el b/test/lisp/vc/vc-hg-tests.el
index 89d518b..43bb922 100644
--- a/test/lisp/vc/vc-hg-tests.el
+++ b/test/lisp/vc/vc-hg-tests.el
@@ -53,6 +53,8 @@ vc-hg-annotate-extract-revision-at-line-with-both
 (ert-deftest vc-hg-annotate-time ()
   (with-temp-buffer
     (save-excursion (insert "philringnalda 218075 2014-11-28 CLOBBER:"))
-    (should (floatp (vc-hg-annotate-time)))))
+    (should (equal (vc-hg-annotate-time)
+                   (vc-annotate-convert-time
+                    (encode-time 0 0 0 28 11 2014))))))
 
 ;;; vc-hg-tests.el ends here
-- 
2.42.0