55 lines
816 B
Python
55 lines
816 B
Python
|
|
class Duration:
|
|
def __init__(self):
|
|
self.hour=0
|
|
self.min=0
|
|
self.sec=0
|
|
|
|
# Set the duration
|
|
# Takes nano-seconds
|
|
def setTime(self,ns):
|
|
# Convert to seconds
|
|
time = ns/1000000000
|
|
# Hours
|
|
if time >= 3600:
|
|
self.hour = time/3600
|
|
time = time-(self.hour*3600)
|
|
|
|
# Minutes
|
|
if time >= 60:
|
|
self.min = time/60
|
|
time = time-(self.min*60)
|
|
|
|
# Seconds
|
|
self.sec = time
|
|
|
|
|
|
# Write time to screen
|
|
def toStr(self):
|
|
time = ""
|
|
if self.hour > 0:
|
|
time+=str(self.hour)+":"
|
|
|
|
if self.min > 0:
|
|
min = str(self.min)
|
|
if self.min < 10:
|
|
min = "0"+min
|
|
time+=min
|
|
else:
|
|
time+="00"
|
|
time+=":"
|
|
|
|
if self.sec > 0:
|
|
sec = str(self.sec)
|
|
if self.sec < 10:
|
|
sec = "0"+sec
|
|
time += sec
|
|
else:
|
|
time+="00"
|
|
return time
|
|
|
|
|
|
def disp(self,prnt):
|
|
time = self.toStr()
|
|
prnt([time])
|