-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeautifulTime.py
More file actions
27 lines (20 loc) · 844 Bytes
/
BeautifulTime.py
File metadata and controls
27 lines (20 loc) · 844 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
import time
from datetime import datetime
from zoneinfo import ZoneInfo
from jdatetime import datetime as jdatetime
class BeautifulTime:
@staticmethod
def create_readable_time(unix_time: int) -> str:
date_time = datetime.fromtimestamp(unix_time, ZoneInfo('UTC'))
jalali_date_time = jdatetime.fromtimestamp(unix_time, ZoneInfo('Asia/Tehran'))
return f'{date_time:%Y-%m-%d %H:%M:%S}\n{jalali_date_time:%Y-%m-%d %H:%M:%S}'
@staticmethod
def is_now_command(command: str) -> bool:
return command.lower() == 'now'
@staticmethod
def is_unix_time(text: str) -> bool:
return text.isnumeric() and len(text) == 10
@staticmethod
def get_readable_now() -> str:
unix_time = int(time.time())
return f'{unix_time}\n' + BeautifulTime.create_readable_time(unix_time)