comparison babel/dates.py @ 217:4de6f4604830

Implement milliseconds in day (#48).
author cmlenz
date Mon, 16 Jul 2007 06:30:01 +0000
parents 1f3c3924b1b5
children 898b9450f274
comparison
equal deleted inserted replaced
216:1f3c3924b1b5 217:4de6f4604830
467 elif char == 'm': 467 elif char == 'm':
468 return self.format(self.value.minute, num) 468 return self.format(self.value.minute, num)
469 elif char == 's': 469 elif char == 's':
470 return self.format(self.value.second, num) 470 return self.format(self.value.second, num)
471 elif char == 'S': 471 elif char == 'S':
472 return self.format_frac_seconds(self.value.microsecond, num) 472 return self.format_frac_seconds(num)
473 elif char == 'A':
474 return self.format_milliseconds_in_day(num)
473 elif char in ('z', 'Z', 'v'): 475 elif char in ('z', 'Z', 'v'):
474 return self.format_timezone(char, num) 476 return self.format_timezone(char, num)
475 else: 477 else:
476 raise KeyError('Unsupported date/time field %r' % char) 478 raise KeyError('Unsupported date/time field %r' % char)
477 479
518 520
519 def format_period(self, char): 521 def format_period(self, char):
520 period = {0: 'am', 1: 'pm'}[int(self.value.hour > 12)] 522 period = {0: 'am', 1: 'pm'}[int(self.value.hour > 12)]
521 return get_period_names(locale=self.locale)[period] 523 return get_period_names(locale=self.locale)[period]
522 524
523 def format_frac_seconds(self, char, num): 525 def format_frac_seconds(self, num):
524 value = str(self.value.microsecond) 526 value = str(self.value.microsecond)
525 return self.format(round(float('.%s' % value), num) * 10**num, num) 527 return self.format(round(float('.%s' % value), num) * 10**num, num)
528
529 def format_milliseconds_in_day(self, num):
530 msecs = self.value.microsecond // 1000 + self.value.second * 1000 + \
531 self.value.minute * 60000 + self.value.hour * 3600000
532 return self.format(msecs, num)
526 533
527 def format_timezone(self, char, num): 534 def format_timezone(self, char, num):
528 if char in ('z', 'v'): 535 if char in ('z', 'v'):
529 if hasattr(self.value.tzinfo, 'zone'): 536 if hasattr(self.value.tzinfo, 'zone'):
530 zone = self.value.tzinfo.zone 537 zone = self.value.tzinfo.zone
Copyright (C) 2012-2017 Edgewall Software