Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't appengine auto-convert datetime to UTC when calling put()

Here's what I'm trying to do: the user submits a time in pacific, once submitted I use .replace to set the timezone to Pacific.

Pacific = time.USTimeZone(-8, "Pacific",  "PST", "PDT")
addEvent.date = addEvent.date.replace(tzinfo=Pacific)

Once i've set the tzinfo, I'm doing a put. According to the python documentation of google appengine it says:

"If the datetime value has a tzinfo attribute, it will be converted to the UTC time zone for storage. Values come back from the datastore as UTC, with a tzinfo of None. An application that needs date and time values to be in a particular time zone must set tzinfo correctly when updating the value, and convert values to the timezone when accessing the value."

However, when I do a put(), i get the following error:

WARNING 2012-10-06 21:10:14,579 tasklets.py:399] initial generator _put_tasklet(context.py:264) raised NotImplementedError(DatetimeProperty date can only support UTC. Please derive a new Property to support alternative timezones.) WARNING 2012-10-06 21:10:14,579 tasklets.py:399] suspended generator put(context.py:703) raised NotImplementedError(DatetimeProperty date can only support UTC. Please derive a new Property to support alternative timezones.)

Please note I am using NDB

Ok, so after doing that I assumed that maybe NDB doesn't automatically convert it into UTC. So then I tried to convert it to UTC using the following code:

class UTC(tzinfo):
  def utcoffset(self, dt):
    return timedelta(0)
  def tzname(self, dt):
    return str("UTC")
  def dst(self, dt):
    return timedelta(0)

and now I still get the same error even after I convert the pacific time to UTC and set the tzinfo name as "UTC".

Could really use a ton of help here... thanks!

like image 702
iceanfire Avatar asked Oct 06 '12 21:10

iceanfire


1 Answers

The solution is to remove the tzinfo completely from the time after converting to UTC.

timestamp = timestamp.replace(tzinfo=None)
like image 145
Guido van Rossum Avatar answered Nov 13 '22 15:11

Guido van Rossum