Template
mirror of
https://github.com/djimboy/djimbo_template_aio3.git
synced 2026-08-17 02:47:44 +00:00
Update
This commit is contained in:
@@ -113,7 +113,9 @@ def get_unix(full: bool = False) -> int:
|
||||
|
||||
|
||||
# Конвертация unix в дату и даты в unix
|
||||
def convert_date(from_time, full: bool = True, second: bool = True) -> Union[str, int]:
|
||||
def convert_date(from_time, full=True, second=True) -> Union[str, int]:
|
||||
from tgbot.data.config import BOT_TIMEZONE
|
||||
|
||||
if "-" in str(from_time):
|
||||
from_time = from_time.replace("-", ".")
|
||||
|
||||
@@ -125,6 +127,34 @@ def convert_date(from_time, full: bool = True, second: bool = True) -> Union[str
|
||||
else:
|
||||
to_time = datetime.fromtimestamp(from_time, pytz.timezone(BOT_TIMEZONE)).strftime("%d.%m.%Y")
|
||||
else:
|
||||
if " " in str(from_time):
|
||||
cache_time = from_time.split(" ")
|
||||
|
||||
if ":" in cache_time[0]:
|
||||
cache_date = cache_time[1].split(".")
|
||||
cache_time = cache_time[0].split(":")
|
||||
else:
|
||||
cache_date = cache_time[0].split(".")
|
||||
cache_time = cache_time[1].split(":")
|
||||
|
||||
if len(cache_date[0]) == 4:
|
||||
x_year, x_month, x_day = cache_date[0], cache_date[1], cache_date[2]
|
||||
else:
|
||||
x_year, x_month, x_day = cache_date[2], cache_date[1], cache_date[0]
|
||||
|
||||
x_hour, x_minute, x_second = cache_time[0], cache_time[2], cache_time[2]
|
||||
|
||||
from_time = f"{x_day}.{x_month}.{x_year} {x_hour}:{x_minute}:{x_second}"
|
||||
else:
|
||||
cache_date = from_time.split(".")
|
||||
|
||||
if len(cache_date[0]) == 4:
|
||||
x_year, x_month, x_day = cache_date[0], cache_date[1], cache_date[2]
|
||||
else:
|
||||
x_year, x_month, x_day = cache_date[2], cache_date[1], cache_date[0]
|
||||
|
||||
from_time = f"{x_day}.{x_month}.{x_year}"
|
||||
|
||||
if " " in str(from_time):
|
||||
to_time = int(datetime.strptime(from_time, "%d.%m.%Y %H:%M:%S").timestamp())
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user