From d92603f3038fa4cdc0f03d6496b16f375690bca0 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 3 Apr 2024 13:33:18 +0200 Subject: [PATCH 1/2] Use timezone aware objects for RepositoryData.last_fetched --- custom_components/hacs/repositories/base.py | 8 ++++---- custom_components/hacs/utils/data.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/custom_components/hacs/repositories/base.py b/custom_components/hacs/repositories/base.py index 4af6fb00c34..13231e8be54 100644 --- a/custom_components/hacs/repositories/base.py +++ b/custom_components/hacs/repositories/base.py @@ -2,7 +2,7 @@ from __future__ import annotations from asyncio import sleep -from datetime import datetime +from datetime import datetime, UTC import os import pathlib import shutil @@ -196,7 +196,7 @@ def update_data(self, data: dict, action: bool = False) -> None: continue if key == "last_fetched" and isinstance(value, float): - setattr(self, key, datetime.fromtimestamp(value)) + setattr(self, key, datetime.fromtimestamp(value, UTC)) elif key == "id": setattr(self, key, str(value)) elif key == "country": @@ -501,7 +501,7 @@ async def common_registration(self) -> None: if self.repository_object: self.data.last_updated = self.repository_object.attributes.get("pushed_at", 0) - self.data.last_fetched = datetime.utcnow() + self.data.last_fetched = datetime.now(UTC) # Set topics self.data.topics = self.data.topics @@ -555,7 +555,7 @@ async def common_update(self, ignore_issues=False, force=False, skip_releases=Fa self.additional_info = await self.async_get_info_file_contents() # Set last fetch attribute - self.data.last_fetched = datetime.utcnow() + self.data.last_fetched = datetime.now(UTC) return True diff --git a/custom_components/hacs/utils/data.py b/custom_components/hacs/utils/data.py index 12e9db73e49..93ac665bc31 100644 --- a/custom_components/hacs/utils/data.py +++ b/custom_components/hacs/utils/data.py @@ -2,7 +2,7 @@ from __future__ import annotations import asyncio -from datetime import datetime +from datetime import datetime, UTC from typing import Any from homeassistant.core import callback @@ -308,7 +308,7 @@ def async_restore_repository(self, entry: str, repository_data: dict[str, Any]): repository.data.manifest_name = repository_data.get("manifest_name") if last_fetched := repository_data.get("last_fetched"): - repository.data.last_fetched = datetime.fromtimestamp(last_fetched) + repository.data.last_fetched = datetime.fromtimestamp(last_fetched, UTC) repository.repository_manifest = HacsManifest.from_dict( repository_data.get("manifest") or repository_data.get("repository_manifest") or {} From a82fdbc58613f057218955f9b269e9700c6b7389 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 11 Apr 2024 12:49:15 +0200 Subject: [PATCH 2/2] Set non UTC system timezone in tests --- .github/workflows/pytest.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 2d70b1ac5ba..4142d733f04 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -35,6 +35,11 @@ jobs: scripts/install/core scripts/install/frontend + - name: ⏲️ Set time zone + uses: szenius/set-timezone@v2.0 + with: + timezoneLinux: 'Asia/Singapore' + - name: 🏃 Run tests env: PYTEST: true @@ -69,6 +74,11 @@ jobs: scripts/install/core_dev scripts/install/frontend + - name: ⏲️ Set time zone + uses: szenius/set-timezone@v2.0 + with: + timezoneLinux: 'Asia/Singapore' + - name: 🏃 Run tests env: PYTEST: true