-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnow_time.py
38 lines (32 loc) · 1.38 KB
/
now_time.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
"""
This module contains a class for getting the current time.
"""
from datetime import datetime, timezone
class NowTime:
"""
Class dedicated to represent the current date and time in different formats.
Attributes:
- utc: datetime object representing class instance time of instantiation
- time_list: list of hour,minutes,seconds of time of instantiation time
Functions:
- date_strings: Sets the string fields of the class to the respective string representations of the current time.
"""
def __init__(self):
"""
Constructor for NowTime.
"""
self.utc = datetime.now(timezone.utc)
self.time_list = (self.utc.strftime("%H:%M:%S")).split(":") # used to be: now_hour_min_secs
# now_hour_min_secs = now_hour_min_secs.split(":")
self.__date_strings()
self.last_minute_of_day = self.utc.replace(hour=23, minute=59, second=0, microsecond=0)
def __date_strings(self):
"""
This function converts instantiation time to different format class attributes.
iso: instantiation time in ISO 8601 format string
ym: instantiation time YearMonth (YYYYmm) format string
ymd: instantiation time YearMonthDay (YYYYmmdd) format string
"""
self.iso = self.utc.isoformat()
self.ym = self.utc.strftime("%Y%m")
self.ymd = self.utc.strftime("%Y%m%d")