In OpenERP my timezone aware datetimes are still being treated as UTC — why?

安稳与你 提交于 2019-12-25 01:56:42

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/20381970/in-openerp-my-timezone-aware-datetimes-are-still-being-treated-as-utc-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!