Ejemplo n.º 1
0
    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)}
Ejemplo n.º 2
0
Archivo: meta.py Proyecto: asyd/almir
    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),
            }
Ejemplo n.º 3
0
 def test_timezone(self):
     self.assertEqual(convert_timezone(None), None)
     self.assertNotEqual(convert_timezone(datetime.datetime.now()).tzinfo, None)
Ejemplo n.º 4
0
 def process_result_value(self, value, dialect=None):
     return convert_timezone(value)