本文介绍了在OpenERP中,我的时区感知数据时间仍被视为UTC - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白OpenERP自6.1以来决定专门使用UTC时区来存储数据时间,但为什么它忽略了我的tz感知数据时间的时区?

解决方案

自6.1以来,这是。 (对7.0)进行修复。



对于好奇,修复的核心是 ... / openerp / osv / fields.py module:

  UTC = pytz.timezone('UTC')



class datetime(_column):
...
_symbol_c ='%s'
def _symbol_f(symb):
如果symb为无或symb == False :
return无
elif isinstance(symb,unicode):
symb = symb.encode('utf-8')
如果不是isinstance(symb,str):
#最好是像datetime
那样的东西,如果symb.tzinfo不是None:
symb = symb.astimezone(UTC)
symb = symb.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
return symb
_symbol_set =(_symbol_c,_symbol_f)

...

类函数(_column):
...
如果type =='datetime':
self._symbol_c = datetime._symbol_c
self._symbol_f = datetime._symbol_f
self._symbol_set = datetime._symbol_set


I understand that OpenERP since 6.1 decided to exclusively use the UTC timezone for storage of datetimes, but why does it ignore the timezone of my tz-aware datetimes?

解决方案

This is a bug in OpenERP probably since 6.1. This patch (against 7.0) fixes it.

For the curious, the heart of the fix is a few lines to the .../openerp/osv/fields.py module:

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

这篇关于在OpenERP中,我的时区感知数据时间仍被视为UTC - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:19