Update public source
This commit is contained in:
+25
-5
@@ -10,7 +10,7 @@
|
|||||||
по всему проекту.
|
по всему проекту.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from functools import lru_cache
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@@ -55,10 +55,30 @@ RECENT_SESSIONS_LIMIT = REPORTS_CONFIG.get(
|
|||||||
10
|
10
|
||||||
)
|
)
|
||||||
|
|
||||||
TIMEZONE = CONFIG.get(
|
TIMEZONE = CONFIG.get("timezone", "Europe/Moscow")
|
||||||
"timezone",
|
|
||||||
"Europe/Moscow"
|
@lru_cache(maxsize=1)
|
||||||
)
|
def _load_timezone(mtime_ns, size):
|
||||||
|
with CONFIG_FILE.open("r", encoding="utf-8") as fp:
|
||||||
|
config = yaml.safe_load(fp) or {}
|
||||||
|
|
||||||
|
timezone_name = config.get("timezone", "Europe/Moscow")
|
||||||
|
if not isinstance(timezone_name, str) or not timezone_name:
|
||||||
|
return "Europe/Moscow"
|
||||||
|
|
||||||
|
return timezone_name
|
||||||
|
|
||||||
|
|
||||||
|
def get_timezone():
|
||||||
|
try:
|
||||||
|
stat = CONFIG_FILE.stat()
|
||||||
|
except OSError:
|
||||||
|
return "Europe/Moscow"
|
||||||
|
|
||||||
|
try:
|
||||||
|
return _load_timezone(stat.st_mtime_ns, stat.st_size)
|
||||||
|
except (OSError, yaml.YAMLError):
|
||||||
|
return TIMEZONE
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# Каталог отчёта
|
# Каталог отчёта
|
||||||
|
|||||||
+3
-3
@@ -26,7 +26,7 @@ from datetime import datetime, timezone
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from .config import TIMEZONE
|
from .config import get_timezone
|
||||||
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@@ -141,7 +141,7 @@ def format_datetime(
|
|||||||
if dt is None:
|
if dt is None:
|
||||||
return safe(text)
|
return safe(text)
|
||||||
|
|
||||||
display_timezone = ZoneInfo(TIMEZONE)
|
display_timezone = ZoneInfo(get_timezone())
|
||||||
|
|
||||||
return dt.astimezone(
|
return dt.astimezone(
|
||||||
display_timezone
|
display_timezone
|
||||||
@@ -403,7 +403,7 @@ def modified(path):
|
|||||||
if not path.exists():
|
if not path.exists():
|
||||||
return "-"
|
return "-"
|
||||||
|
|
||||||
display_timezone = ZoneInfo(TIMEZONE)
|
display_timezone = ZoneInfo(get_timezone())
|
||||||
|
|
||||||
return datetime.fromtimestamp(
|
return datetime.fromtimestamp(
|
||||||
path.stat().st_mtime,
|
path.stat().st_mtime,
|
||||||
|
|||||||
Reference in New Issue
Block a user