mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-23 05:34:28 +00:00
13 lines
305 B
Python
13 lines
305 B
Python
|
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())
|