-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathIdokonverzio.py
More file actions
36 lines (25 loc) · 872 Bytes
/
Idokonverzio.py
File metadata and controls
36 lines (25 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def formatExpr(val: int, unit: str):
ret = None
if val > 0: ret = '{} {}'.format(val, unit)
if val > 1: ret += 's'
return ret
def formatSeconds(seconds: int):
if seconds < 0: return "Seconds should be positive or zero."
if seconds == 0: return "now"
M = 60
H = 60 * M
D = 24 * H
Y = 356 * D
l = []
y, seconds = divmod(seconds, Y)
l.append(formatExpr(y, 'year'))
d, seconds = divmod(seconds, D)
l.append(formatExpr(d, 'day'))
h, seconds = divmod(seconds, H)
l.append(formatExpr(h, 'hour'))
m, seconds = divmod(seconds, M)
l.append(formatExpr(m, 'minute'))
l.append(formatExpr(seconds, 'second'))
return ', '.join([v for v in l if v != None])[::-1].replace(
" ,", " dan ", 1)[::-1]
formatSeconds(3600 + 15 * 3600 + 15 + 24 * 3600)