Ecco cosa sto cercando di fare: l'utente invia un tempo in pacifico, una volta inviato utilizzo .replace per impostare il fuso orario su Pacific.Perché la appengine non converte automaticamente datetime in UTC quando si chiama put()
Pacific = time.USTimeZone(-8, "Pacific", "PST", "PDT")
addEvent.date = addEvent.date.replace(tzinfo=Pacific)
Una volta impostato lo tzinfo, sto facendo un tentativo. Secondo la documentazione pitone di Google AppEngine che dice:
"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."
Tuttavia, quando faccio una put(), ottengo il seguente errore:
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.)
Si prega di notare che sto usando NDB
Ok, quindi, dopo averlo fatto, ho pensato che forse NDB non lo convertisse automaticamente in UTC. Allora ho provato a convertirlo in UTC utilizzando il seguente codice:
class UTC(tzinfo):
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return str("UTC")
def dst(self, dt):
return timedelta(0)
e ora ho ancora lo stesso errore anche dopo converto il tempo Pacifico per UTC e impostare il nome tzinfo come "UTC".
Potrebbe davvero usare un sacco di aiuto qui ... grazie!
ah così semplice! Grazie! – iceanfire
in realtà un esempio sarebbe stato davvero utile. – Houman
Ecco un esempio: do timestamp = timestamp.replace (tzinfo = None) prima di impostare la proprietà su timestamp. – Luca