Coverage for src/lexigram/graphql/scalars/timestamp.py: 75%
16 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
1from __future__ import annotations
3from datetime import datetime
6class Timestamp:
7 """Custom scalar for timestamp (Unix epoch) values."""
9 @staticmethod
10 def serialize(dt: datetime | None) -> int | None:
11 if dt is None:
12 return None
13 if isinstance(dt, datetime):
14 return int(dt.timestamp())
15 raise ValueError(f"Cannot serialize {type(dt)} as Timestamp")
17 @staticmethod
18 def parse_value(value: int | None) -> datetime | None:
19 if value is None:
20 return None
21 return datetime.fromtimestamp(value)
24__all__ = [
25 "Timestamp",
26]