これは私がやろうとしていることです:ユーザーは太平洋で時間を送信します。一度送信すると.replaceを使用して太平洋にタイムゾーンを設定します。putengine()を呼び出すときにdatetimeを自動変換しないのはなぜですか?
Pacific = time.USTimeZone(-8, "Pacific", "PST", "PDT")
addEvent.date = addEvent.date.replace(tzinfo=Pacific)
私がtzinfoを設定したら、putを実行しています。 GoogleのAppEngineののPythonドキュメントによると、それは言う:私はPUTを()を実行するとき
"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."
はしかし、私は次のエラーを取得する:
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.)
私はNDB
を使用していますのでご注意くださいこれを実行した後、NDBがUTCに自動的に変換しない可能性があると想定しました。
class UTC(tzinfo):
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return str("UTC")
def dst(self, dt):
return timedelta(0)
、今、私はまだ私はUTCに太平洋標準時を変換した後も同じエラーを取得し、「UTC」としてtzinfoの名を設定します。それでは、私は次のコードを使用してUTCに変換しようとしました。
本当にここで多額の助けを借りることができました... ありがとう!
ああそう簡単!ありがとう! – iceanfire
実際には一例が本当に役に立ちました。 – Houman
例を次に示します。プロパティをタイムスタンプに設定する前に、timestamp = timestamp.replace(tzinfo = None)を実行します。 – Luca