-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
52 lines (38 loc) · 1.21 KB
/
__init__.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
__all__ = ["Total", "Timedelta"]
import datetime
"""
https://docs.python.org/3/library/datetime.html#timedelta-objects
"""
class Total:
__readme__ = ["__init__", "seconds", "minutes", "hours", "days"]
total_seconds = None
def __init__(self, total_seconds):
"""init from total seconds count"""
self.total_seconds = total_seconds
@property
def seconds(self):
"""return total seconds count"""
return int(self.total_seconds)
@property
def minutes(self):
"""return total minutes count"""
return int(self.seconds / 60)
@property
def hours(self):
"""return total hours count"""
return int(self.minutes / 60)
@property
def days(self):
"""return total days count"""
return int(self.hours / 24)
class Timedelta(datetime.timedelta):
"""datetime.timedelta replacement"""
def __new__(self, *args, **kwargs):
if args:
kwargs["seconds"] = args[0].total_seconds()
kwargs["microseconds"] = args[0].microseconds
return datetime.timedelta.__new__(self, **kwargs)
@property
def total(self):
"""return Total object"""
return Total(self.total_seconds())