def format_time(self, time): """return a string for a time according to instance's configuration """ if time is not None: return ustrftime(time, self.property_value('ui.time-format')) return u''
def default(self, obj): if hasattr(obj, '__json_encode__'): return obj.__json_encode__() if isinstance(obj, datetime.datetime): return ustrftime(obj, '%Y/%m/%d %H:%M:%S') elif isinstance(obj, datetime.date): return ustrftime(obj, '%Y/%m/%d') elif isinstance(obj, datetime.time): return obj.strftime('%H:%M:%S') elif isinstance(obj, datetime.timedelta): return (obj.days * 24 * 60 * 60) + obj.seconds elif isinstance(obj, decimal.Decimal): return float(obj) elif isinstance(obj, Binary): return base64.b64encode(obj.getvalue()).decode('ascii') try: return json.JSONEncoder.default(self, obj) except TypeError: # we never ever want to fail because of an unknown type, # just return None in those cases. return None
def format_date(self, date, date_format=None, time=False): """return a string for a date time according to instance's configuration """ if date is not None: if date_format is None: if time: date_format = self.property_value('ui.datetime-format') else: date_format = self.property_value('ui.date-format') return ustrftime(date, date_format) return u''
def test_ticks2datetime_before_1900(self): ticks = -2209075200000 date = ticks2datetime(ticks) self.assertEqual(ustrftime(date, '%Y-%m-%d'), u'1899-12-31')
def test_ustrftime_before_1900(self): date = self.datetimecls(1328, 3, 12, 6, 30) self.assertEqual(ustrftime(date, '%Y-%m-%d %H:%M:%S'), u'1328-03-12 06:30:00')
def format_single_value(self, req, value): if value: return ustrftime(value, req.property_value(self.format_prop)) return u''
def test_ticks2datetime_before_1900(self): ticks = -2209075200000 date = ticks2datetime(ticks) self.assertEqual(ustrftime(date, "%Y-%m-%d"), u"1899-12-31")
def test_ustrftime_before_1900(self): date = self.datetimecls(1328, 3, 12, 6, 30) self.assertEqual(ustrftime(date, "%Y-%m-%d %H:%M:%S"), u"1328-03-12 06:30:00")
def print_tzdatetime(value, req, props, displaytime=True): if displaytime: return ustrftime(value, req.property_value('ui.datetime-format')) + u' UTC' return ustrftime(value, req.property_value('ui.date-format'))
def print_time(value, req, props, displaytime=True): return ustrftime(value, req.property_value('ui.time-format'))