~credativ/openobject-server/trunk-csv-import-domain

« back to all changes in this revision

Viewing changes to openerp/osv/fields.py

  • Committer: Quentin (OpenERP)
  • Date: 2014-04-16 15:44:50 UTC
  • Revision ID: qdp-launchpad@openerp.com-20140416154450-ws9w6wzf9s5kmjjj
[FIX] fields.date's date_to_datime function fixed

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
                              exc_info=True)
345
345
        return (context_today or today).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
346
346
 
347
 
    def date_to_datetime(self, cr, uid, userdate, context=None):
 
347
    @staticmethod
 
348
    def date_to_datetime(model, cr, uid, userdate, context=None):
348
349
        """ Convert date values expressed in user's timezone to
349
350
        server-side UTC timestamp, assuming a default arbitrary
350
351
        time of 12:00 AM - because a time is needed.
351
 
    
 
352
 
352
353
        :param str userdate: date string in in user time zone
353
354
        :return: UTC datetime string for server-side use
354
355
        """
355
 
        user_date = datetime.strptime(userdate, DEFAULT_SERVER_DATE_FORMAT)
 
356
        user_date = DT.datetime.strptime(userdate, tools.DEFAULT_SERVER_DATE_FORMAT)
356
357
        if context and context.get('tz'):
357
358
            tz_name = context['tz']
358
359
        else:
359
 
            tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz']
 
360
            tz_name = model.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz']
360
361
        if tz_name:
361
362
            utc = pytz.timezone('UTC')
362
363
            context_tz = pytz.timezone(tz_name)
363
 
            user_datetime = user_date + timedelta(hours=12.0)
 
364
            user_datetime = user_date + DT.timedelta(hours=12.0)
364
365
            local_timestamp = context_tz.localize(user_datetime, is_dst=False)
365
366
            user_datetime = local_timestamp.astimezone(utc)
366
 
            return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
367
 
        return user_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
 
367
            return user_datetime.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
 
368
        return user_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
368
369
 
369
370
 
370
371
class datetime(_column):