Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...