<s> import time <EOL> import calendar <EOL> from pytz import utc <EOL> from datetime import datetime <EOL> from django . conf import settings <EOL> use_tz = getattr ( settings , '<STR_LIT>' , False ) <EOL> try : <EOL> from django . utils . timezone import now , localtime , get_current_timezone , make_aware <EOL> except ImportError : <EOL> from datetime import datetime <EOL> now = datetime . now <EOL> use_tz = False <EOL> def utc_localize ( dtime ) : <EOL> if use_tz : <EOL> if dtime . tzinfo : <EOL> return utc . normalize ( dtime ) <EOL> else : <EOL> return utc . localize ( dtime ) <EOL> return dtime <EOL> def localize ( dtime ) : <EOL> if use_tz : <EOL> if dtime . tzinfo : <EOL> return localtime ( dtime ) <EOL> else : <EOL> return make_aware ( dtime , get_current_timezone ( ) ) <EOL> return dtime <EOL> def to_timestamp ( dtime ) : <EOL> if use_tz : <EOL> return calendar . timegm ( dtime . utctimetuple ( ) ) + float ( dtime . microsecond ) / <NUM_LIT> <EOL> return time . mktime ( dtime . timetuple ( ) ) + float ( dtime . microsecond ) / <NUM_LIT> <EOL> def from_timestamp ( tstamp ) : <EOL> if use_tz : <EOL> return datetime . fromtimestamp ( float ( tstamp ) , tz = utc ) <EOL> return datetime . fromtimestamp ( float ( tstamp ) ) </s>
