Ticket #17937: timezone.diff

File timezone.diff, 1.3 KB (added by dmitry.guyvoronsky@…, 13 years ago)

Objects of date class should be always naive according to python docs

  • django/utils/timezone.py

     
    33This module uses pytz when it's available and fallbacks when it isn't.
    44"""
    55
    6 from datetime import datetime, timedelta, tzinfo
     6from datetime import date, datetime, timedelta, tzinfo
    77from threading import local
    88import time as _time
    99
     
    248248
    249249    The logic is described in Python's docs:
    250250    http://docs.python.org/library/datetime.html#datetime.tzinfo
     251
     252    Objects of the date type are always naive.
    251253    """
    252     return value.tzinfo is not None and value.tzinfo.utcoffset(value) is not None
     254    if isinstance(value, date):
     255        return False
     256    else:
     257        return value.tzinfo is not None and value.tzinfo.utcoffset(value) is not None
    253258
    254259def is_naive(value):
    255260    """
     
    257262
    258263    The logic is described in Python's docs:
    259264    http://docs.python.org/library/datetime.html#datetime.tzinfo
     265
     266    Objects of the date type are always naive.
    260267    """
    261     return value.tzinfo is None or value.tzinfo.utcoffset(value) is None
     268    if isinstance(value, date):
     269        return True
     270    else:
     271        return value.tzinfo is None or value.tzinfo.utcoffset(value) is None
    262272
    263273def make_aware(value, timezone):
    264274    """
Back to Top