~mgorven/ibid/smtp-fixes

« back to all changes in this revision

Viewing changes to ibid/utils/__init__.py

  • Committer: Michael Gorven
  • Date: 2010-01-02 16:01:58 UTC
  • mfrom: (817.1.22 timezone-335551)
  • Revision ID: michael@gorven.za.net-20100102160158-6mmt53pfqolc6m8a
Add timezone plugin.
https://code.launchpad.net/~mgorven/ibid/timezone-335551/+merge/16726

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
    except ImportError:
137
137
        pass
138
138
 
139
 
def format_date(timestamp, length='datetime'):
 
139
def format_date(timestamp, length='datetime', tolocaltime=True):
140
140
    "Format a UTC date for displaying in a response"
141
141
 
142
142
    defaults = {
148
148
    length += '_format'
149
149
    format = ibid.config.plugins.get(length, defaults[length])
150
150
 
151
 
    if timestamp.tzinfo is None:
152
 
        timestamp = timestamp.replace(tzinfo=tzutc())
153
 
 
154
 
    timestamp = timestamp.astimezone(tzlocal())
 
151
    if tolocaltime:
 
152
        if timestamp.tzinfo is None:
 
153
            timestamp = timestamp.replace(tzinfo=tzutc())
 
154
        timestamp = timestamp.astimezone(tzlocal())
155
155
 
156
156
    return unicode(timestamp.strftime(format.encode('utf8')), 'utf8')
157
157