jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1336850?usp=email )

Change subject: time: Simplify ISO 8601 timezone parsing with strptime
......................................................................

time: Simplify ISO 8601 timezone parsing with strptime

Python 3.7 added support for Z and colon-separated offsets to
strptime's %z directive, so all supported Python versions can parse
them directly. Use %z for both forms and retain padding for abbreviated
offsets and conversion to naive UTC.

Change-Id: Ib3b1c2826187c21342a594be562256bef4885b18
---
M pywikibot/time.py
1 file changed, 6 insertions(+), 8 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/time.py b/pywikibot/time.py
index 0603390..3f970f8 100644
--- a/pywikibot/time.py
+++ b/pywikibot/time.py
@@ -160,14 +160,12 @@
             strpfmt += '.%f'
             strpstr += m['u'].replace(',', '.')  # .ljust(7, '0')

-        if m['tz']:
-            if m['tz'] == 'Z':
-                strpfmt += 'Z'
-                strpstr += 'Z'
-            else:
-                strpfmt += '%z'
-                # strptime wants HHMM, without ':'
-                strpstr += (m['tz'].replace(':', '')).ljust(5, '0')
+        if tz := m['tz']:
+            strpfmt += '%z'
+            if tz != 'Z':
+                # Complete abbreviated offsets, preserving any colon.
+                tz = tz.ljust(6 if ':' in tz else 5, '0')
+            strpstr += tz

         ts = cls.strptime(strpstr, strpfmt)
         if ts.tzinfo is not None:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1336850?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib3b1c2826187c21342a594be562256bef4885b18
Gerrit-Change-Number: 1336850
Gerrit-PatchSet: 3
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to