util.datestr: use divmod()
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 14 Nov 2015 17:30:10 -0800
changeset 27066 6f1f8e88f036
parent 27065 93bcc73df8d5
child 27067 19b52cde2b84
util.datestr: use divmod() We were computing the quotient and remainder of a division operation separately. The built-in divmod() function allows us to do this with a single function call. Do that.
mercurial/util.py
--- a/mercurial/util.py	Sat Nov 14 17:44:01 2015 -0800
+++ b/mercurial/util.py	Sat Nov 14 17:30:10 2015 -0800
@@ -1367,9 +1367,10 @@
     if "%1" in format or "%2" in format or "%z" in format:
         sign = (tz > 0) and "-" or "+"
         minutes = abs(tz) // 60
+        q, r = divmod(minutes, 60)
         format = format.replace("%z", "%1%2")
-        format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
-        format = format.replace("%2", "%02d" % (minutes % 60))
+        format = format.replace("%1", "%c%02d" % (sign, q))
+        format = format.replace("%2", "%02d" % r)
     try:
         t = time.gmtime(float(t) - tz)
     except ValueError: