-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path16.4.py
More file actions
37 lines (29 loc) · 759 Bytes
/
16.4.py
File metadata and controls
37 lines (29 loc) · 759 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
37
#coding:utf-8
class Time(object):
""""""
def time_to_int(t):
"""
Returns a time in seconds
"""
minutes = t.hours * 60 + t.minutes
seconds = minutes * 60 + t.seconds
return seconds
def int_to_time(t):
"""
Takes a time in seconds and returns it in format hh:mm:ss
"""
time = Time()
minutes, time.seconds = divmod(t, 60)
time.hours, time.minutes = divmod(minutes, 60)
return time
def print_time(time):
print '%.2d:%.2d:%.2d' % (time.hours, time.minutes, time.seconds)
def increment(t, seconds):
return int_to_time(time_to_int(t) + seconds)
t1 = Time()
t1.hours = 10
t1.minutes = 7
t1.seconds = 5
print_time(t1)
t2 = increment(t1, 4000)
print_time(t2)