Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 27066:6f1f8e88f036
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 14 Nov 2015 17:30:10 -0800 |
parents | 448cbdab5883 |
children | 39c14e89b881 |
comparison
equal
deleted
inserted
replaced
27065:93bcc73df8d5 | 27066:6f1f8e88f036 |
---|---|
1365 t = 0 # time.gmtime(lt) fails on Windows for lt < -43200 | 1365 t = 0 # time.gmtime(lt) fails on Windows for lt < -43200 |
1366 tz = 0 | 1366 tz = 0 |
1367 if "%1" in format or "%2" in format or "%z" in format: | 1367 if "%1" in format or "%2" in format or "%z" in format: |
1368 sign = (tz > 0) and "-" or "+" | 1368 sign = (tz > 0) and "-" or "+" |
1369 minutes = abs(tz) // 60 | 1369 minutes = abs(tz) // 60 |
1370 q, r = divmod(minutes, 60) | |
1370 format = format.replace("%z", "%1%2") | 1371 format = format.replace("%z", "%1%2") |
1371 format = format.replace("%1", "%c%02d" % (sign, minutes // 60)) | 1372 format = format.replace("%1", "%c%02d" % (sign, q)) |
1372 format = format.replace("%2", "%02d" % (minutes % 60)) | 1373 format = format.replace("%2", "%02d" % r) |
1373 try: | 1374 try: |
1374 t = time.gmtime(float(t) - tz) | 1375 t = time.gmtime(float(t) - tz) |
1375 except ValueError: | 1376 except ValueError: |
1376 # time was out of range | 1377 # time was out of range |
1377 t = time.gmtime(sys.maxint) | 1378 t = time.gmtime(sys.maxint) |