[FIX] fields.date's date_to_datime function fixed
bzr revid: qdp-launchpad@openerp.com-20140416154450-ws9w6wzf9s5kmjjj
This commit is contained in:
parent
54907b2c48
commit
104451bd56
|
@ -344,27 +344,28 @@ class date(_column):
|
||||||
exc_info=True)
|
exc_info=True)
|
||||||
return (context_today or today).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
|
return (context_today or today).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||||
|
|
||||||
def date_to_datetime(self, cr, uid, userdate, context=None):
|
@staticmethod
|
||||||
|
def date_to_datetime(model, cr, uid, userdate, context=None):
|
||||||
""" Convert date values expressed in user's timezone to
|
""" Convert date values expressed in user's timezone to
|
||||||
server-side UTC timestamp, assuming a default arbitrary
|
server-side UTC timestamp, assuming a default arbitrary
|
||||||
time of 12:00 AM - because a time is needed.
|
time of 12:00 AM - because a time is needed.
|
||||||
|
|
||||||
:param str userdate: date string in in user time zone
|
:param str userdate: date string in in user time zone
|
||||||
:return: UTC datetime string for server-side use
|
:return: UTC datetime string for server-side use
|
||||||
"""
|
"""
|
||||||
user_date = datetime.strptime(userdate, DEFAULT_SERVER_DATE_FORMAT)
|
user_date = DT.datetime.strptime(userdate, tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||||
if context and context.get('tz'):
|
if context and context.get('tz'):
|
||||||
tz_name = context['tz']
|
tz_name = context['tz']
|
||||||
else:
|
else:
|
||||||
tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz']
|
tz_name = model.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz']
|
||||||
if tz_name:
|
if tz_name:
|
||||||
utc = pytz.timezone('UTC')
|
utc = pytz.timezone('UTC')
|
||||||
context_tz = pytz.timezone(tz_name)
|
context_tz = pytz.timezone(tz_name)
|
||||||
user_datetime = user_date + timedelta(hours=12.0)
|
user_datetime = user_date + DT.timedelta(hours=12.0)
|
||||||
local_timestamp = context_tz.localize(user_datetime, is_dst=False)
|
local_timestamp = context_tz.localize(user_datetime, is_dst=False)
|
||||||
user_datetime = local_timestamp.astimezone(utc)
|
user_datetime = local_timestamp.astimezone(utc)
|
||||||
return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
return user_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
return user_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
return user_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
class datetime(_column):
|
class datetime(_column):
|
||||||
|
|
Loading…
Reference in New Issue