~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-09 04:08:15 UTC
  • Revision ID: mbp@sourcefrog.net-20050309040815-13242001617e4a06
import from baz patch-364

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
 
168
168
 
169
169
 
170
 
def local_time_offset():
171
 
    if time.daylight:
172
 
        return -time.altzone
173
 
    else:
174
 
        return -time.timezone
175
 
 
176
 
    
177
 
def format_date(t, offset=0, timezone='original'):
 
170
def format_date(t, inutc=False):
178
171
    ## TODO: Perhaps a global option to use either universal or local time?
179
172
    ## Or perhaps just let people set $TZ?
180
173
    import time
181
174
    
182
175
    assert isinstance(t, float)
183
176
    
184
 
    if timezone == 'utc':
 
177
    if inutc:
185
178
        tt = time.gmtime(t)
 
179
        zonename = 'UTC'
186
180
        offset = 0
187
 
    elif timezone == 'original':
188
 
        tt = time.gmtime(t - offset)
189
 
    elif timezone == 'local':
 
181
    else:
190
182
        tt = time.localtime(t)
191
 
        offset = local_time_offset()
192
 
    else:
193
 
        bailout("unsupported timezone format %r",
194
 
                ['options are "utc", "original", "local"'])
195
 
 
 
183
        if time.daylight:
 
184
            zonename = time.tzname[1]
 
185
            offset = - time.altzone
 
186
        else:
 
187
            zonename = time.tzname[0]
 
188
            offset = - time.timezone
 
189
            
196
190
    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
197
 
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
 
191
            + ' ' + zonename + ' '
 
192
            + '%+03d%02d' % (offset / 3600, (offset / 60) % 60))
198
193
 
199
194
 
200
195
def compact_date(when):