summaryrefslogtreecommitdiffstats
path: root/pykolab/xml/utils.py
blob: 0959c800b89f78dca889098c9926ce7d9810d62f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import datetime
import pytz

def to_dt(dt):
    """
        Convert a naive date or datetime to a tz-aware datetime.
    """

    if type(dt) == 'datetime.date' or not hasattr(dt, 'hour'):
        dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0)

    else:
        if dt.tzinfo == None:
            return dt.replace(tzinfo=pytz.utc)
        else:

            return dt