-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_manager.py
38 lines (27 loc) · 979 Bytes
/
time_manager.py
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
import database
# I am saving this one variable in the database as a song, cause why not. I am too lazy, and noone will ever see this :)
time = 0
if(database.check_if_exists("time_spent")):
time = database.get_song_plays("time_spent")
else:
database.new_song("time_spent", time)
def get_current_raw_time_spent():
return database.get_song_plays("time_spent")
def add_seconds(sec):
global time
database.update_song("time_spent", time + sec)
time += sec
def add_millis(millis):
add_seconds(millis // 1000)
def add_minutes(minutes):
add_seconds(60 * minutes)
def get_current_time_spent():
return format_time(get_current_raw_time_spent())
def format_time(seconds):
days = seconds // (24 * 3600)
seconds -= days * 24 * 3600
hours = seconds // 3600
seconds -= hours * 3600
minutes = seconds // 60
seconds -= minutes * 60
return str(days) + ":" + f"{hours:02d}" + ":" + f"{minutes:02d}" + ":" + f"{seconds:02d}"