Control: tags -1 patch

Hi Guido,

On 23/12/23 16:57, Guido Günther wrote:
the gbp-import-dsc script crashes while parsing changelogs that include leap
seconds.

dateutil.parser._parser.ParserError: second must be in 0..59: Sun,  1 Jan
2006 00:59:60 +0100

This looks like a bug in dateutil, can you reassign there?

Not really:

As of 2023-12 there is an open issue asking for support for leap seconds in
dateutils [3].

That issue has been open for almost three years. The dateutils developers say that Python's datetime does not handle leap seconds, so they are not going to mess around with it.

In order to deal with Debian policy's request to support :60, application-level workarounds are needed.

Please find attached a small patch that fix this issue.

Regards,

--
Gioele Barabucci
From 5dd36d1a7ed44f7cd10eb7afeb58e6c747558e91 Mon Sep 17 00:00:00 2001
From: Gioele Barabucci <gio...@svario.it>
Date: Sat, 23 Dec 2023 17:03:39 +0100
Subject: [PATCH] git: rfc822_date_to_git: Handle leap seconds

Closes: #1059363
---
 gbp/git/__init__.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gbp/git/__init__.py b/gbp/git/__init__.py
index 3d0bb0b9..773ba822 100644
--- a/gbp/git/__init__.py
+++ b/gbp/git/__init__.py
@@ -17,6 +17,7 @@
 """Accessing Git from python"""
 
 import calendar
+import datetime
 import dateutil.parser
 
 from gbp.git.modifier import GitModifier   # noqa: F401
@@ -41,7 +42,11 @@ def rfc822_date_to_git(rfc822_date, fuzzy=False):
     >>> rfc822_date_to_git('So, 26 Feb 1998 8:50:00 +0100', fuzzy=True)
     '888479400 +0100'
     """
+    rfc822_date_orig = rfc822_date
+    rfc822_date = rfc822_date.replace(":60 ", ":59 ")
     d = dateutil.parser.parse(rfc822_date, fuzzy=fuzzy)
+    if rfc822_date != rfc822_date_orig: # Handle leap seconds.
+        d += datetime.timedelta(seconds=1)
     seconds = calendar.timegm(d.utctimetuple())
     tz = d.strftime("%z")
     return '%d %s' % (seconds, tz)
-- 
2.43.0

Reply via email to