Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...