from __future__ import unicode_literals

from calendar import timegm
from datetime import datetime

from django.conf import settings
from django.utils import six
from django.utils.functional import lazy
from django.utils.timezone import is_aware, make_aware, utc


def make_utc(dt):
    if settings.USE_TZ and not is_aware(dt):
        return make_aware(dt, timezone=utc)

    return dt


def aware_utcnow():
    return make_utc(datetime.utcnow())


def datetime_to_epoch(dt):
    return timegm(dt.utctimetuple())


def datetime_from_epoch(ts):
    return make_utc(datetime.utcfromtimestamp(ts))


def format_lazy(s, *args, **kwargs):
    return s.format(*args, **kwargs)

format_lazy = lazy(format_lazy, six.text_type)

from __future__ import unicode_literals

from calendar import timegm
from datetime import datetime

from django.conf import settings
from django.utils import six
from django.utils.functional import lazy
from django.utils.timezone import is_naive, make_aware, utc


def make_utc(dt):
    if settings.USE_TZ and is_naive(dt):
        return make_aware(dt, timezone=utc)

    return dt


def aware_utcnow():
    return make_utc(datetime.utcnow())


def datetime_to_epoch(dt):
    return timegm(dt.utctimetuple())


def datetime_from_epoch(ts):
    return make_utc(datetime.utcfromtimestamp(ts))


def format_lazy(s, *args, **kwargs):
    return s.format(*args, **kwargs)

format_lazy = lazy(format_lazy, six.text_type)

Use is_naive here for clarity
Use is_naive here for clarity
