Skip to content

Commit

Permalink
fix timezone error (#34)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Jarrett Ye <[email protected]>
  • Loading branch information
3 people authored May 20, 2024
1 parent 6560253 commit 5d36ec3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
Expand Down
4 changes: 2 additions & 2 deletions src/fsrs/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions tests/test_fsrs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fsrs import *
from datetime import datetime, UTC
from datetime import datetime, timezone
import json
import pytest

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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):
Expand Down

0 comments on commit 5d36ec3

Please sign in to comment.