comparison babel/messages/catalog.py @ 429:08e2d18163d9

Fix Catalog._set_mime_headers' handing of negative offsets. Submitted by: Asheesh Laroia (Creative Commons) Closes: #165
author jruigrok
date Mon, 16 Mar 2009 17:49:48 +0000
parents 52492583006a
children 86c4fe7de244
comparison
equal deleted inserted replaced
428:072300df53fc 429:08e2d18163d9
347 self._num_plurals = int(params.get('nplurals', 2)) 347 self._num_plurals = int(params.get('nplurals', 2))
348 self._plural_expr = params.get('plural', '(n != 1)') 348 self._plural_expr = params.get('plural', '(n != 1)')
349 elif name == 'pot-creation-date': 349 elif name == 'pot-creation-date':
350 # FIXME: this should use dates.parse_datetime as soon as that 350 # FIXME: this should use dates.parse_datetime as soon as that
351 # is ready 351 # is ready
352 value, tzoffset, _ = re.split('[+-](\d{4})$', value, 1) 352 value, tzoffset, _ = re.split('([+-]\d{4})$', value, 1)
353
353 tt = time.strptime(value, '%Y-%m-%d %H:%M') 354 tt = time.strptime(value, '%Y-%m-%d %H:%M')
354 ts = time.mktime(tt) 355 ts = time.mktime(tt)
355 tzoffset = FixedOffsetTimezone(int(tzoffset[:2]) * 60 + 356
356 int(tzoffset[2:])) 357 # Seprate the offset into a sign component, hours, and minutes
358 plus_minus_s, rest = tzoffset[0], tzoffset[1:]
359 hours_offset_s, mins_offset_s = rest[:2], rest[2:]
360
361 # Make them all integers
362 plus_minus = int(plus_minus_s + '1')
363 hours_offset = int(hours_offset_s)
364 mins_offset = int(mins_offset_s)
365
366 # Calculate net offset
367 net_mins_offset = hours_offset * 60
368 net_mins_offset += mins_offset
369 net_mins_offset *= plus_minus
370
371 # Create an offset object
372 tzoffset = FixedOffsetTimezone(net_mins_offset)
373
374 # Store the offset in a datetime object
357 dt = datetime.fromtimestamp(ts) 375 dt = datetime.fromtimestamp(ts)
358 self.creation_date = dt.replace(tzinfo=tzoffset) 376 self.creation_date = dt.replace(tzinfo=tzoffset)
359 elif name == 'po-revision-date': 377 elif name == 'po-revision-date':
360 # Keep the value if it's not the default one 378 # Keep the value if it's not the default one
361 if 'YEAR' not in value: 379 if 'YEAR' not in value:
362 # FIXME: this should use dates.parse_datetime as soon as 380 # FIXME: this should use dates.parse_datetime as soon as
363 # that is ready 381 # that is ready
364 value, tzoffset, _ = re.split('[+-](\d{4})$', value, 1) 382 value, tzoffset, _ = re.split('([+-]\d{4})$', value, 1)
365 tt = time.strptime(value, '%Y-%m-%d %H:%M') 383 tt = time.strptime(value, '%Y-%m-%d %H:%M')
366 ts = time.mktime(tt) 384 ts = time.mktime(tt)
367 tzoffset = FixedOffsetTimezone(int(tzoffset[:2]) * 60 + 385
368 int(tzoffset[2:])) 386 # Seprate the offset into a sign component, hours, and
387 # minutes
388 plus_minus_s, rest = tzoffset[0], tzoffset[1:]
389 hours_offset_s, mins_offset_s = rest[:2], rest[2:]
390
391 # Make them all integers
392 plus_minus = int(plus_minus_s + '1')
393 hours_offset = int(hours_offset_s)
394 mins_offset = int(mins_offset_s)
395
396 # Calculate net offset
397 net_mins_offset = hours_offset * 60
398 net_mins_offset += mins_offset
399 net_mins_offset *= plus_minus
400
401 # Create an offset object
402 tzoffset = FixedOffsetTimezone(net_mins_offset)
403
404 # Store the offset in a datetime object
369 dt = datetime.fromtimestamp(ts) 405 dt = datetime.fromtimestamp(ts)
370 self.revision_date = dt.replace(tzinfo=tzoffset) 406 self.revision_date = dt.replace(tzinfo=tzoffset)
371 407
372 mime_headers = property(_get_mime_headers, _set_mime_headers, doc="""\ 408 mime_headers = property(_get_mime_headers, _set_mime_headers, doc="""\
373 The MIME headers of the catalog, used for the special ``msgid ""`` entry. 409 The MIME headers of the catalog, used for the special ``msgid ""`` entry.
Copyright (C) 2012-2017 Edgewall Software