Skip to content

Commit e2b276f

Browse files
Merge pull request #28 from RSS-Engineering/ttl-field-fixes
Ttl field fixes
2 parents 882c74b + 57d0eb6 commit e2b276f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pydanticrud/backends/dynamodb.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ def rule_to_boto_expression(rule: Rule, keys: Optional[Set[str]] = None):
7171
"bool": "BOOL",
7272
}
7373

74-
EPOCH = datetime(1970, 1, 1, 0, 0)
7574

76-
77-
def _to_epoch_decimal(dt: datetime) -> Decimal:
75+
def _to_epoch_decimal(dt: Union[datetime, float]) -> Decimal:
7876
"""TTL fields must be stored as a float but boto only supports decimals."""
79-
epock = EPOCH
80-
if dt.tzinfo:
81-
epock = epock.replace(tzinfo=timezone.utc)
82-
return Decimal((dt - epock).total_seconds())
77+
if type(dt) is datetime:
78+
val = dt.timestamp()
79+
else:
80+
val = dt
81+
return Decimal(val)
8382

8483

8584
SERIALIZE_MAP = {

0 commit comments

Comments
 (0)