def render_distance_of_time_in_words(dt_from, dt_to=None): if not dt_from: return if dt_from.tzinfo is None: dt_from = convert_timezone(dt_from) if dt_to is None: return {'text': distance_of_time_in_words(dt_from, convert_timezone(datetime.now())) + ' ago', 'data_numeric': dt_from.strftime('%s')} else: if dt_to.tzinfo is None: dt_to = convert_timezone(dt_to) return {'text': distance_of_time_in_words(dt_from, dt_to), 'data_numeric': -timedelta_to_seconds(dt_to - dt_from)}
def render_distance_of_time_in_words(dt_from, dt_to=None): if not dt_from: return if dt_from.tzinfo is None: dt_from = convert_timezone(dt_from) if dt_to is None: return { "text": distance_of_time_in_words(dt_from, convert_timezone(datetime.now())) + " ago", "data_numeric": dt_from.strftime("%s"), } else: if dt_to.tzinfo is None: dt_to = convert_timezone(dt_to) return { "text": distance_of_time_in_words(dt_from, dt_to), "data_numeric": -timedelta_to_seconds(dt_to - dt_from), }
def test_timezone(self): self.assertEqual(convert_timezone(None), None) self.assertNotEqual(convert_timezone(datetime.datetime.now()).tzinfo, None)
def process_result_value(self, value, dialect=None): return convert_timezone(value)
def test_timezone(self): self.assertEqual(convert_timezone(None), None) self.assertNotEqual( convert_timezone(datetime.datetime.now()).tzinfo, None)