diff options
Diffstat (limited to 'app/utils.py')
| -rw-r--r-- | app/utils.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/app/utils.py b/app/utils.py index 77ea775..626ee24 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,4 +1,4 @@ -import time +from datetime import datetime from typing import TypeAlias, Union from app.Item import Item from dataclasses import asdict @@ -17,9 +17,11 @@ def get_param(key: str, params: Params) -> str: def item_to_dict(item: Item) -> ItemDict: - return asdict(item) + d = asdict(item) + d["pub_date"] = datetime.isoformat(d["pub_date"]) if d["pub_date"] else None + return d def dict_to_item(d: ItemDict) -> Item: pub_date, rest = (lambda pub_date, **rest: (pub_date, rest))(**d) # type: ignore - return Item(pub_date=time.struct_time(pub_date), **rest) # type: ignore + return Item(pub_date=datetime.fromisoformat(pub_date), **rest) # type: ignore |
