Example #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)}
Example #2
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)}
Example #3
0
File: meta.py Project: 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),
            }
Example #4
0
 def test_timezone(self):
     self.assertEqual(convert_timezone(None), None)
     self.assertNotEqual(convert_timezone(datetime.datetime.now()).tzinfo, None)
Example #5
0
 def process_result_value(self, value, dialect=None):
     return convert_timezone(value)
Example #6
0
 def test_timezone(self):
     self.assertEqual(convert_timezone(None), None)
     self.assertNotEqual(
         convert_timezone(datetime.datetime.now()).tzinfo, None)
Example #7
0
 def process_result_value(self, value, dialect=None):
     return convert_timezone(value)