(我是Python和Google App Engine的新手,请原谅我,如果我的问题看起来很基本)。
我有一段时间试图管理多个我的Google App Engine应用程序中的用户时区。
以下是我的限制:
我知道时间将在UTC内部存储为tzinfo对象,并且App Engine将以UTC时间存储模型。 / p>
我以前认为我通过要求用户在他们的偏好中指定他们的时区完成了这一切。然后,我只需加载它们的首选项,并将tzinfo添加到引用该用户的任何日期时间对象中。
然而,我们最近的夏令时打破了它。事实证明,我没有在我的tzinfo对象中正确实现dst()。据我了解,我必须确定DST是否正在运行,如果是,请返回正确的tzinfo偏移量。
问题是,我不知道如何以确定时区的夏时制是否为当前时间。我错过了一些明显的东西吗?
如果可以的话,我建议看一看 python-dateutil 包,其中包含为所有时区预先构建的tz对象,包括DST偏移量信息。我不认为如果没有支持数据,DST是否开启就没有办法知道......它是由大多数时区(或至少支持DST的时区)驱动的日期,并且日期根据本地习惯,政治和各种事情。http: //labix/python-dateutil
(I am new to Python and Google App Engine, please forgive me if my questions seem basic).
I'm having a helluva time trying to manage multiple user timezones in my Google App Engine application.
Here are my constraints:
I understand that time will be internally stored as UTC with a tzinfo object and that the App Engine will store the Models with UTC time.
I previously thought I had this all worked out by asking the user to specify their time zone in their preferences. Then, I would simply load their preferences and add that tzinfo to any datetime objects in reference to that user.
However, our recent daylight saving time broke it. It turns out that I had not correctly implemented the dst() in my tzinfo objects. As I understand it, I must determine if DST is currently on, and if so, return the correct offset for the tzinfo.
The problem is, I have no idea how to determine if the timezone's daylight time is current or not. Am I missing something obvious?
解决方案If you can, I'd recommend having a look at the python-dateutil package, which has tz objects pre-built for all timezones, including DST offset information. I don't think there's a way to "just know" if DST is on or not without supporting data... it's date driven for most timezones (or, at least, timezones that support DST), and the dates vary according to local custom, politics, and all manner of things.
labix/python-dateutil
更多推荐
Python tzinfo和夏令时
发布评论