summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/south/utils/datetime_utils.py
blob: a4169359418d97708c00447dff9a4fcceb94de68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import *

import django
from django.conf import settings

if django.VERSION[:2] >= (1, 4) and getattr(settings, 'USE_TZ', False):
    from django.utils import timezone
    from datetime import datetime as _datetime

    class datetime(_datetime):
        """
        A custom datetime.datetime class which acts as a compatibility
        layer between South and Django 1.4's timezone aware datetime
        instances.

        It basically adds the default timezone (as configured in Django's
        settings) automatically if no tzinfo is given.
        """
        def __new__(cls, year, month, day,
                    hour=0, minute=0, second=0, microsecond=0, tzinfo=None):

            dt = _datetime(year, month, day,
                           hour, minute, second, microsecond,
                           tzinfo=tzinfo)
            if tzinfo is None:
                default_timezone = timezone.get_default_timezone()
                dt = timezone.make_aware(dt, default_timezone)
            return dt