From 5d36ec32bcac350b489b78dd6c20b26a38582d09 Mon Sep 17 00:00:00 2001 From: T2XX <61300026+T2XX@users.noreply.github.com> Date: Mon, 20 May 2024 22:35:53 +0800 Subject: [PATCH] fix timezone error (#34) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix timezone error 通过更换时区表达模块修复错误 can not import UTC Fix error can not import UTC by using timezone.utc * fix format * bump version --------- Co-authored-by: T2XX Co-authored-by: Jarrett Ye --- pyproject.toml | 2 +- src/fsrs/models.py | 4 ++-- tests/test_fsrs.py | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8ab5d64..1d513b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "fsrs" -version = "2.1.0" +version = "2.1.1" description = "Free Spaced Repetition Scheduler" readme = "README.md" authors = [{ name = "Jarrett Ye", email = "jarrett.ye@outlook.com" }] diff --git a/src/fsrs/models.py b/src/fsrs/models.py index 39fc902..3fde91e 100644 --- a/src/fsrs/models.py +++ b/src/fsrs/models.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta, UTC +from datetime import datetime, timedelta, timezone import copy from typing import Tuple, Optional from enum import IntEnum @@ -65,7 +65,7 @@ def __init__( ) -> None: if due is None: - self.due = datetime.now(UTC) + self.due = datetime.now(timezone.utc) else: self.due = due diff --git a/tests/test_fsrs.py b/tests/test_fsrs.py index df2b1d1..07d3491 100644 --- a/tests/test_fsrs.py +++ b/tests/test_fsrs.py @@ -1,5 +1,5 @@ from fsrs import * -from datetime import datetime, UTC +from datetime import datetime, timezone import json import pytest @@ -40,7 +40,7 @@ def test_repeat(self): 2.0902, ) card = Card() - now = datetime(2022, 11, 29, 12, 30, 0, 0, tzinfo=UTC) + now = datetime(2022, 11, 29, 12, 30, 0, 0, timezone.utc) scheduling_cards = f.repeat(card, now) print_scheduling_cards(scheduling_cards) @@ -78,7 +78,7 @@ def test_datetime(self): card = Card() # new cards should be due immediately after creation - assert datetime.now(UTC) >= card.due + assert datetime.now(timezone.utc) >= card.due # comparing timezone aware cards with deprecated datetime.utcnow() should raise a TypeError with pytest.raises(TypeError): @@ -89,12 +89,12 @@ def test_datetime(self): f.repeat(card, datetime(2022, 11, 29, 12, 30, 0, 0)) # repeat a card with rating good before next tests - scheduling_cards = f.repeat(card, datetime.now(UTC)) + scheduling_cards = f.repeat(card, datetime.now(timezone.utc)) card = scheduling_cards[Rating.Good].card # card object's due and last_review attributes must be timezone aware and UTC - assert card.due.tzinfo == UTC - assert card.last_review.tzinfo == UTC + assert card.due.tzinfo == timezone.utc + assert card.last_review.tzinfo == timezone.utc # card object's due datetime should be later than its last review assert card.due >= card.last_review @@ -120,7 +120,7 @@ def test_serialize(self): assert card.to_dict() == copied_card.to_dict() # (x2) perform the above tests once more with a repeated card - scheduling_cards = f.repeat(card, datetime.now(UTC)) + scheduling_cards = f.repeat(card, datetime.now(timezone.utc)) repeated_card = scheduling_cards[Rating.Good].card with pytest.raises(TypeError):