microblog.pub/app/utils/pagination.py

13 lines
305 B
Python
Raw Normal View History

2022-06-28 18:10:25 +00:00
import base64
from datetime import datetime
from dateutil.parser import isoparse
def encode_cursor(val: datetime) -> str:
return base64.urlsafe_b64encode(val.isoformat().encode()).decode()
def decode_cursor(cursor: str) -> datetime:
return isoparse(base64.urlsafe_b64decode(cursor).decode())