add utils functions

This commit is contained in:
Hirad 2025-07-23 11:54:03 +03:30
parent 8e59d18cda
commit 20cd56c00c

View 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)