Skip to content

Commit

Permalink
Replace pendulum with aniso8601 for ISO8601 interval parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jan 15, 2025
1 parent 3bfc748 commit a827347
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
python-version:
- "3.12"
- "3.13"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
20 changes: 3 additions & 17 deletions aggrec/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
from datetime import datetime, timedelta, timezone

import aniso8601
import http_sf
import pendulum
from fastapi import HTTPException, Request, status
from http_message_signatures import (
HTTPMessageVerifier,
Expand Down Expand Up @@ -115,19 +115,5 @@ def rfc_3339_datetime_now() -> str:


def parse_iso8601_interval(interval: str) -> tuple[datetime, timedelta]:
period = pendulum.parse(interval)
duration = period.start.diff(period.end).in_seconds()
return pendulum_as_datetime(period.start), timedelta(seconds=duration)


def pendulum_as_datetime(dt: pendulum.DateTime) -> datetime:
return datetime(
year=dt.year,
month=dt.month,
day=dt.day,
hour=dt.hour,
minute=dt.minute,
second=dt.second,
microsecond=dt.microsecond,
tzinfo=dt.tzinfo,
)
t1, t2 = aniso8601.parse_interval(interval)
return t1, timedelta(seconds=(t2 - t1).total_seconds())
129 changes: 16 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 @@ -21,11 +21,11 @@ pydantic-settings = "^2.7.0"
werkzeug = "^3.0.4"
boto3 = "^1.26.133"
aiomqtt = "^2.2.0"
pendulum = "^3"
pyyaml = "^6.0.1"
http-sf = "^1.0.2"
redis = "^5.1.1"
aiobotocore = ">=2.15.2"
aniso8601 = "^10.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.0"
Expand Down
4 changes: 4 additions & 0 deletions tests/test_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ def test_parse_iso8601_interval():
start, duration = parse_iso8601_interval("2025-01-15T08:56:58+00:00/PT1M")
assert start == datetime(year=2025, month=1, day=15, hour=8, minute=56, second=58, tzinfo=timezone.utc)
assert duration.total_seconds() == 60

start, duration = parse_iso8601_interval("19840101T000000Z/19840115T000000Z")
assert start == datetime(year=1984, month=1, day=1, hour=0, minute=0, second=0, tzinfo=timezone.utc)
assert duration.total_seconds() == 14 * 24 * 60 * 60

0 comments on commit a827347

Please sign in to comment.