Firebase Firestore Server timestamp vs Python Datetime?

Viewed 1228

I'm using the python admin sdk for my browser game... but I've run through some issues...

I use timestamps to track when something was created in my game, by using the default timestamp that comes with the library as shown here


from firebase_admin import firestore, credentials as _cred

# setup client here

firestore.SERVER_TIMESTAMP

but lets say I wanted to compare this to a normal datetime like so

>>> import datetime
>>> o = datetime.datetime.now()
>>> type(o)
<class 'datetime.datetime'>
>>> userDict = db.collection("users").document("test").get().to_dict()

>>> type(userDict['creation_time'])
<class 'google.api_core.datetime_helpers.DatetimeWithNanoseconds'>
>>> userDict['creation_time']-datetime.datetime.now()

TypeError: can't subtract offset-naive and offset-aware datetimes

is there any way I can subtract the two to get a normal datetime like so?

>>> o - datetime.datetime.now()
datetime.timedelta(days=-1, seconds=86381, microseconds=61146)

If so could you tell me please? That would make my day, Thanks for reading through my problem, I hope you can help!

0 Answers
Related