-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastclock.py
More file actions
40 lines (31 loc) · 931 Bytes
/
fastclock.py
File metadata and controls
40 lines (31 loc) · 931 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
38
39
40
import datetime
import random
import threading
MAXOFFSET=600 #in seconds, should eventually read from .fastclockrc
#Internal functions
def changeOffset():
t = threading.Timer(30, changeOffset)
t.daemon = True
global offset
offset = random.randint(0, MAXOFFSET)
t.start()
def update():
t = threading.Timer(1.0, update)
t.daemon = True
current_time = datetime.datetime.now()
global displayed_time
displayed_time = current_time + datetime.timedelta(0, offset)
#print(displayed_time.time().strftime("%I:%M"))
t.start()
#External interfaces
def start(): #start FastClock
changeOffset()
update()
#Get current FastClock time object
def getTime():
global displayed_time
return displayed_time.time()
#Get current FastClock time in human-readable format
def getReadableTime():
global displayed_time
return displayed_time.time().strftime("%I:%M")