jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/878222 )

Change subject: [Bugfix] Remove timezone information when normalizing
......................................................................

[Bugfix] Remove timezone information when normalizing

Bug: T326693
Change-Id: Ia589f74da678c7c680bf352b0f8dd315291eed5f
---
M pywikibot/__init__.py
M tests/wikibase_tests.py
2 files changed, 31 insertions(+), 1 deletion(-)

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




diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 8aea5a8..d78b579 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -606,6 +606,9 @@
         This function returns a new normalized object and does not do
         any modification in place.

+        Normalization will delete timezone information if the precision
+        is less than or equal to DAY.
+
         Note: Normalized WbTime objects can only be compared to other
         normalized WbTime objects of the same precision. Normalization
         might make a WbTime object that was less than another WbTime object
@@ -649,7 +652,6 @@
             'precision': self.precision,
             'before': self.before,
             'after': self.after,
-            'timezone': self.timezone,
             'calendarmodel': self.calendarmodel,
             'year': year
         }
@@ -658,6 +660,8 @@
         if self.precision >= self.PRECISION['day']:
             kwargs['day'] = self.day
         if self.precision >= self.PRECISION['hour']:
+            # See T326693
+            kwargs['timezone'] = self.timezone
             kwargs['hour'] = self.hour
         if self.precision >= self.PRECISION['minute']:
             kwargs['minute'] = self.minute
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 3bb61e5..0e96dad 100755
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -391,6 +391,15 @@
         t10 = pywikibot.WbTime(site=repo, year=2010, month=1, day=1, hour=12,
                                minute=43, second=12,
                                precision=millenia)
+        t11 = pywikibot.WbTime(site=repo, year=2010, month=1, day=1, hour=12,
+                               minute=43, second=12, timezone=-300,
+                               precision=pywikibot.WbTime.PRECISION['day'])
+        t12 = pywikibot.WbTime(site=repo, year=2010, month=1, day=1, hour=12,
+                               minute=43, second=12, timezone=300,
+                               precision=pywikibot.WbTime.PRECISION['day'])
+        t13 = pywikibot.WbTime(site=repo, year=2010, month=1, day=1, hour=12,
+                               minute=43, second=12, timezone=-300,
+                               precision=pywikibot.WbTime.PRECISION['hour'])
         self.assertEqual(t.normalize(), t)
         self.assertEqual(t2.normalize(), t.normalize())
         self.assertEqual(t3.normalize(),
@@ -422,6 +431,13 @@
         self.assertEqual(t10.normalize(),
                          pywikibot.WbTime(site=repo, year=2010,
                                           precision=millenia).normalize())
+        t11_normalized = t11.normalize()
+        t12_normalized = t12.normalize()
+        self.assertEqual(t11_normalized.timezone, 0)
+        self.assertEqual(t12_normalized.timezone, 0)
+        self.assertNotEqual(t11, t12)
+        self.assertEqual(t11_normalized, t12_normalized)
+        self.assertEqual(t13.normalize().timezone, -300)

     def test_WbTime_normalization_very_low_precision(self):
         """Test WbTime normalization with very low precision."""

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia589f74da678c7c680bf352b0f8dd315291eed5f
Gerrit-Change-Number: 878222
Gerrit-PatchSet: 1
Gerrit-Owner: RPI2026F1 <sarkaraoyan+rpi202...@gmail.com>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org
To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org

Reply via email to