Skip to content

Commit

Permalink
Migrate from pendulum to arrow for dates (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
pronovic authored Jan 8, 2025
1 parent 1decbe1 commit bcaccee
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 144 deletions.
3 changes: 2 additions & 1 deletion Changelog
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Version 0.1.57 unreleased
Version 0.2.0 unreleased

* Migrate to Poetry v2 and project-managed Poetry plugins.
* Move configuration into pyproject.toml for pytest, mypy & coverage.
* Upgrade to gha-shared-workflows@v8 for Poetry v2 support.
* Migrate from pendulum to arrow for dates (interface change).
* Update all dependencies and outdated constraints.

Version 0.1.56 02 Jan 2025
Expand Down
146 changes: 33 additions & 113 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dynamic = [ "classifiers", "version" ]
dependencies = [
"attrs (>=24.2.0,<25.0.0)",
"cattrs (>=24.1.2,<25.0.0)",
"pendulum (>=3.0.0,<4.0.0)",
"arrow (>=1.3.0,<2.0.0)",
]

[project.urls]
Expand Down
16 changes: 8 additions & 8 deletions src/apologies/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
from enum import Enum
from typing import Dict, List, Optional

import pendulum
from arrow import Arrow
from arrow import utcnow as arrow_utcnow
from attrs import define, field, frozen
from pendulum.datetime import DateTime

from .util import CattrConverter
from .util import ISO_TIME_FORMAT, CattrConverter

# Cattr converter that serializes/deserializes DateTime to an ISO 8601 timestamp
_CONVERTER = CattrConverter()
Expand Down Expand Up @@ -425,21 +425,21 @@ class History:
action(str): String describing the action
color(Optional[PlayerColor]): Color of the player associated with the action
card(Optional[CardType]): Card associated with the action
timestamp(DateTime): Timestamp tied to the action (defaults to current time)
timestamp(Arrow): Timestamp tied to the action (defaults to current time)
"""

action: str
color: Optional[PlayerColor] = None
card: Optional[CardType] = None
timestamp: DateTime = field()
timestamp: Arrow = field()

# noinspection PyUnresolvedReferences
@timestamp.default
def _default_timestamp(self) -> DateTime:
return pendulum.now(pendulum.UTC) # type: ignore[attr-defined,unused-ignore]
def _default_timestamp(self) -> Arrow:
return arrow_utcnow()

def __str__(self) -> str:
time = self.timestamp.to_time_string() # type: ignore[no-untyped-call,unused-ignore]
time = self.timestamp.format(ISO_TIME_FORMAT)
color = "General" if not self.color else self.color.value
action = self.action
return "[%s] %s - %s" % (time, color, action)
Expand Down
Loading

0 comments on commit bcaccee

Please sign in to comment.