3

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!

Artrix
  • 149
  • 10
  • is not clear for me on you code if you are converting the `firestore.SERVER_TIMESTAMP` to a datetime before trying to subtract it, are you doing that? If so, you might wan't to try removing the timezone awareness from your datetimes, like in this [community answer](https://stackoverflow.com/questions/796008/cant-subtract-offset-naive-and-offset-aware-datetimes), note that you might have do add some time or subtract it depending on the timezone but this could work. – Ralemos Jul 02 '20 at 13:45

0 Answers0