mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-24 09:36:31 +00:00
Add timezone to snapshot timestamp (#360)
* Add timezone to snapshot timestamp ``` old: 2018-02-14T15:13:46.391829 new: 2018-02-14T15:13:46.391829+00:00 ``` * Update __init__.py * Move code to dt util * Lint * Lint 2 * Update dt.py * Update __init__.py
This commit is contained in:
parent
ac60de0360
commit
9c40c32e95
@ -1,6 +1,5 @@
|
||||
"""Snapshot system control."""
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
@ -9,6 +8,7 @@ from .utils import create_slug
|
||||
from ..const import (
|
||||
FOLDER_HOMEASSISTANT, SNAPSHOT_FULL, SNAPSHOT_PARTIAL)
|
||||
from ..coresys import CoreSysAttributes
|
||||
from ..utils.dt import utcnow
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -33,7 +33,7 @@ class SnapshotManager(CoreSysAttributes):
|
||||
|
||||
def _create_snapshot(self, name, sys_type, password):
|
||||
"""Initialize a new snapshot object from name."""
|
||||
date_str = datetime.utcnow().isoformat()
|
||||
date_str = utcnow().isoformat()
|
||||
slug = create_slug(name, date_str)
|
||||
tar_file = Path(self._config.path_backup, f"{slug}.tar")
|
||||
|
||||
|
@ -8,6 +8,8 @@ import aiohttp
|
||||
import async_timeout
|
||||
import pytz
|
||||
|
||||
UTC = pytz.utc
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
FREEGEOIP_URL = "https://freegeoip.io/json/"
|
||||
@ -61,7 +63,7 @@ def parse_datetime(dt_str):
|
||||
|
||||
tzinfo = None # type: Optional[dt.tzinfo]
|
||||
if tzinfo_str == 'Z':
|
||||
tzinfo = pytz.utc
|
||||
tzinfo = UTC
|
||||
elif tzinfo_str is not None:
|
||||
offset_mins = int(tzinfo_str[-2:]) if len(tzinfo_str) > 3 else 0
|
||||
offset_hours = int(tzinfo_str[1:3])
|
||||
@ -74,3 +76,8 @@ def parse_datetime(dt_str):
|
||||
kws = {k: int(v) for k, v in kws.items() if v is not None}
|
||||
kws['tzinfo'] = tzinfo
|
||||
return datetime(**kws)
|
||||
|
||||
|
||||
def utcnow():
|
||||
"""Returns current timestamp including timezone."""
|
||||
return datetime.now(UTC)
|
||||
|
Loading…
x
Reference in New Issue
Block a user