在OpenERP中,我的时区感知日期时间仍被视为UTC - 为什么?

时间:2013-12-04 17:29:44

标签: datetime timezone openerp

我知道自6.1以来OpenERP决定专门使用UTC时区存储日期时间,但为什么它会忽略我的tz感知日期时间的时区?

1 个答案:

答案 0 :(得分:1)

自6.1以来,这是一个bug in OpenERPThis patch(针对7.0)修复了它。

对于好奇的人来说,修复的核心是.../openerp/osv/fields.py模块的几行:

UTC = pytz.timezone('UTC')
.
.
.
class datetime(_column):
    ...
    _symbol_c = '%s'
    def _symbol_f(symb):
        if symb is None or symb == False:
            return None
        elif isinstance(symb, unicode):
            symb = symb.encode('utf-8')
        if not isinstance(symb, str):
            # had better be something that quacks like a datetime
            if symb.tzinfo is not None:
                symb = symb.astimezone(UTC)
            symb = symb.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
        return symb
    _symbol_set = (_symbol_c, _symbol_f)

...

class function(_column):
    ...
    if type == 'datetime':
        self._symbol_c = datetime._symbol_c
        self._symbol_f = datetime._symbol_f
        self._symbol_set = datetime._symbol_set