add utils functions
This commit is contained in:
parent
8e59d18cda
commit
20cd56c00c
1 changed files with 23 additions and 0 deletions
23
src/synclean/utils/utils.py
Normal file
23
src/synclean/utils/utils.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from datetime import datetime
|
||||
from dateutil import parser
|
||||
|
||||
|
||||
def convert_bytes_to_megabytes(bytes_size: int) -> float:
|
||||
"""Convert bytes to megabytes"""
|
||||
return bytes_size / (1024 * 1024)
|
||||
|
||||
|
||||
def convert_megabytes_to_bytes(megabytes: float) -> int:
|
||||
"""Convert megabytes to bytes"""
|
||||
return int(megabytes * (1024 * 1024))
|
||||
|
||||
|
||||
def convert_ts_to_datetime(ts: int) -> str:
|
||||
"""Convert timestamp to date"""
|
||||
return datetime.fromtimestamp(ts / 1000).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
def convert_datetime_to_ts(dt: str) -> int:
|
||||
"""Convert date to timestamp"""
|
||||
dt = parser.parse(dt)
|
||||
timestamp = dt.timestamp()
|
||||
return int(timestamp * 1000)
|
Loading…
Add table
Add a link
Reference in a new issue