Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jan 15, 2025
1 parent 85891e4 commit 91434df
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_iso8601.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
from datetime import datetime, timezone

import pytest

from aggrec.helpers import parse_iso8601_interval


def test_parse_iso8601_interval():
# timestamp/duration
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

# timestamp/timestamp
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

# Invalid format
with pytest.raises(ValueError):
parse_iso8601_interval("invalid")

# Different timezone formats
start, duration = parse_iso8601_interval("2025-01-15T08:56:58-05:00/PT1M")
assert start == datetime(year=2025, month=1, day=15, hour=13, minute=56, second=58, tzinfo=timezone.utc)

# Microsecond precision
start, duration = parse_iso8601_interval("2025-01-15T08:56:58.123456+00:00/PT1M")
assert start == datetime(
year=2025, month=1, day=15, hour=8, minute=56, second=58, microsecond=123456, tzinfo=timezone.utc
)
assert duration.total_seconds() == 60

0 comments on commit 91434df

Please sign in to comment.