Refactor timezone functions

Split them into hours and minutes, and use divmod() to make them more
readable.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
This commit is contained in:
Felipe Contreras
2019-06-04 19:51:22 -05:00
parent e17e147fb1
commit fad59f53eb

View File

@@ -72,14 +72,16 @@ def gitmode(flags):
return 'l' in flags and '120000' or 'x' in flags and '100755' or '100644'
def gittz(tz):
sign = 1 if tz < 0 else -1
return '%+03d%02d' % (sign * (abs(tz) / 3600), abs(tz) % 3600 / 60)
sign = 1 if tz >= 0 else -1
hours, minutes = divmod(abs(tz), 60 * 60)
return '%+03d%02d' % (-sign * hours, minutes / 60)
def hgtz(tz):
tz = int(tz)
sign = 1 if tz < 0 else -1
tz = ((abs(tz) / 100) * 3600) + ((abs(tz) % 100) * 60)
return sign * tz
sign = 1 if tz >= 0 else -1
hours, minutes = divmod(abs(tz), 100)
tz = hours * 60 * 60 + minutes * 60
return -sign * tz
def hgmode(mode):
m = { '100755': 'x', '120000': 'l' }