How to use timeago - 10 common examples

To help you get started, we’ve selected a few timeago examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hustcc / timeago / test / testcase.py View on Github external
datetime_to_string(date), now, locale), '12 seconds ago')

        now = date + datetime.timedelta(seconds=60)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '1 minute ago')

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '3 minutes ago')

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '1 hour ago')

        now = date + datetime.timedelta(seconds=3600 * 2)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '2 hours ago')

        now = date + datetime.timedelta(seconds=86400)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '1 day ago')

        now = date + datetime.timedelta(seconds=86400 * 4.5)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '4 days ago')

        now = date + datetime.timedelta(seconds=2592000)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '4 weeks ago')

        now = date + datetime.timedelta(seconds=2592000 * 3.5)
        self.assertEqual(timeago.format(
github hustcc / timeago / test / testcase.py View on Github external
self.assertEqual(timeago.format(date, now, locale), "hai 1 minuto")

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(date, now, locale), "hai 3 minutos")

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(date, now, locale), "hai 1 hora")

        now = date + datetime.timedelta(seconds=3600 * 2)
        self.assertEqual(timeago.format(date, now, locale), "hai 2 horas")

        now = date + datetime.timedelta(seconds=86400)
        self.assertEqual(timeago.format(date, now, locale), "hai 1 día")

        now = date + datetime.timedelta(seconds=86400 * 4.5)
        self.assertEqual(timeago.format(date, now, locale), "hai 4 días")

        now = date + datetime.timedelta(seconds=86400 * 7)
        self.assertEqual(timeago.format(date, now, locale), "hai 1 semana")

        now = date + datetime.timedelta(seconds=2592000)
        self.assertEqual(timeago.format(date, now, locale), "hai 4 semanas")

        now = date + datetime.timedelta(seconds=86400 * 31)
        self.assertEqual(timeago.format(date, now, locale), "hai 1 mes")

        now = date + datetime.timedelta(seconds=2592000 * 3.5)
        self.assertEqual(timeago.format(date, now, locale), "hai 3 meses")

        now = date + datetime.timedelta(seconds=31536000)
        self.assertEqual(timeago.format(date, now, locale), "hai 1 ano")
github hustcc / timeago / test / testcase.py View on Github external
def test_timeago_ja_in(self):
        locale = 'ja'

        date = datetime.datetime.now()
        now = date + datetime.timedelta(seconds=2)
        self.assertEqual(timeago.format(now, date, locale), u'すぐに')

        now = date + datetime.timedelta(seconds=10)
        self.assertEqual(timeago.format(now, date, locale), u'10秒以内')

        now = date + datetime.timedelta(seconds=12)
        self.assertEqual(timeago.format(now, date, locale), u'12秒以内')

        now = date + datetime.timedelta(seconds=60)
        self.assertEqual(timeago.format(now, date, locale), u'1分以内')

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(now, date, locale), u'3分以内')

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(now, date, locale), u'1時間以内')
github hustcc / timeago / test / testcase.py View on Github external
def test_timeago_vi(self):
        locale = 'vi'

        date = datetime.datetime.now()
        now = date + datetime.timedelta(seconds=2)
        self.assertEqual(timeago.format(date, now, locale), "vừa xong")

        now = date + datetime.timedelta(seconds=10)
        self.assertEqual(timeago.format(date, now, locale), "10 giây trước")

        now = date + datetime.timedelta(seconds=60)
        self.assertEqual(timeago.format(date, now, locale), "1 phút trước")

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(date, now, locale), "3 phút trước")

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(date, now, locale), "1 giờ trước")

        now = date + datetime.timedelta(seconds=3600 * 2)
        self.assertEqual(timeago.format(date, now, locale), "2 giờ trước")

        now = date + datetime.timedelta(seconds=86400)
        self.assertEqual(timeago.format(date, now, locale), "1 ngày trước")

        now = date + datetime.timedelta(seconds=86400 * 4.5)
        self.assertEqual(timeago.format(date, now, locale), "4 ngày trước")

        now = date + datetime.timedelta(seconds=86400 * 7)
        self.assertEqual(timeago.format(date, now, locale), "1 tuần trước")
github hustcc / timeago / test / testcase.py View on Github external
def test_timeago_string_input(self):
        locale = None
        date = datetime.datetime.now()
        now = date + datetime.timedelta(seconds=2)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), 'just now')

        now = date + datetime.timedelta(seconds=10)
        self.assertEqual(timeago.format(datetime_to_string(
            date), datetime_to_string(now), locale), '10 seconds ago')

        now = date + datetime.timedelta(seconds=12)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '12 seconds ago')

        now = date + datetime.timedelta(seconds=60)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '1 minute ago')

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(
            datetime_to_string(date), now, locale), '3 minutes ago')

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(
github hustcc / timeago / test / testcase.py View on Github external
self.assertEqual(timeago.format(date, now, locale), "10 seconden geleden")

        now = date + datetime.timedelta(seconds=60)
        self.assertEqual(timeago.format(date, now, locale), "1 minuut geleden")

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(date, now, locale), "3 minuten geleden")

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(date, now, locale), "1 uur geleden")

        now = date + datetime.timedelta(seconds=3600 * 2)
        self.assertEqual(timeago.format(date, now, locale), "2 uren geleden")

        now = date + datetime.timedelta(seconds=86400)
        self.assertEqual(timeago.format(date, now, locale), "1 dag geleden")

        now = date + datetime.timedelta(seconds=86400 * 4.5)
        self.assertEqual(timeago.format(date, now, locale), "4 dagen geleden")

        now = date + datetime.timedelta(seconds=86400 * 7)
        self.assertEqual(timeago.format(date, now, locale), "1 week geleden")

        now = date + datetime.timedelta(seconds=2592000)
        self.assertEqual(timeago.format(date, now, locale), "4 weken geleden")

        now = date + datetime.timedelta(seconds=86400 * 31)
        self.assertEqual(timeago.format(date, now, locale), "1 maand geleden")

        now = date + datetime.timedelta(seconds=2592000 * 3.5)
        self.assertEqual(timeago.format(date, now, locale), "3 maanden geleden")
github hustcc / timeago / test / testcase.py View on Github external
self.assertEqual(timeago.format(now, date, locale), 'a while')

        now = date + datetime.timedelta(seconds=10)
        self.assertEqual(timeago.format(now, date, locale), 'in 10 seconds')

        now = date + datetime.timedelta(seconds=12)
        self.assertEqual(timeago.format(now, date, locale), 'in 12 seconds')

        now = date + datetime.timedelta(seconds=60)
        self.assertEqual(timeago.format(now, date, locale), 'in 1 minute')

        now = date + datetime.timedelta(seconds=60 * 3.4)
        self.assertEqual(timeago.format(now, date, locale), 'in 3 minutes')

        now = date + datetime.timedelta(seconds=3600)
        self.assertEqual(timeago.format(now, date, locale), 'in 1 hour')

        now = date + datetime.timedelta(seconds=3600 * 2)
        self.assertEqual(timeago.format(now, date, locale), 'in 2 hours')

        now = date + datetime.timedelta(seconds=86400)
        self.assertEqual(timeago.format(now, date, locale), 'in 1 day')

        now = date + datetime.timedelta(seconds=86400 * 4.5)
        self.assertEqual(timeago.format(now, date, locale), 'in 4 days')

        now = date + datetime.timedelta(seconds=2592000)
        self.assertEqual(timeago.format(now, date, locale), 'in 4 weeks')

        now = date + datetime.timedelta(seconds=2592000 * 3.5)
        self.assertEqual(timeago.format(now, date, locale), 'in 3 months')
github hustcc / timeago / test / testcase.py View on Github external
input = '2016-5-27 21:22:2'
        self.assertEqual(parser.parse(input), date)

        input = '2016/05/27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        input = '2016/5/27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        date = datetime.datetime(2016, 5, 27, 0, 0, 0)
        input = '2016/05/27'
        self.assertEqual(parser.parse(input), date)

        input = '2016-5-27'
        self.assertEqual(parser.parse(input), date)

        input = '2016-05-27'
        self.assertEqual(parser.parse(input), date)

        today = dateimport.today()
        date = datetime.datetime(
            today.year, today.month, today.day, 12, 12, 12)
        input = '12:12:12'
        self.assertEqual(parser.parse(input), date)

        # date
        input = dateimport(2016, 5, 27)
        date = datetime.datetime(2016, 5, 27, 0, 0, 0)
        self.assertEqual(parser.parse(input), date)

        # time
github hustcc / timeago / test / testcase.py View on Github external
input = '2016/05/27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        input = '2016/5/27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        date = datetime.datetime(2016, 5, 27, 0, 0, 0)
        input = '2016/05/27'
        self.assertEqual(parser.parse(input), date)

        input = '2016-5-27'
        self.assertEqual(parser.parse(input), date)

        input = '2016-05-27'
        self.assertEqual(parser.parse(input), date)

        today = dateimport.today()
        date = datetime.datetime(
            today.year, today.month, today.day, 12, 12, 12)
        input = '12:12:12'
        self.assertEqual(parser.parse(input), date)

        # date
        input = dateimport(2016, 5, 27)
        date = datetime.datetime(2016, 5, 27, 0, 0, 0)
        self.assertEqual(parser.parse(input), date)

        # time
        today = dateimport.today()
        input = time(21, 45, 27)
        date = datetime.datetime(
github hustcc / timeago / test / testcase.py View on Github external
# datetime string
        input = '2016-05-27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        input = '2016-5-27 21:22:2'
        self.assertEqual(parser.parse(input), date)

        input = '2016/05/27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        input = '2016/5/27 21:22:02'
        self.assertEqual(parser.parse(input), date)

        date = datetime.datetime(2016, 5, 27, 0, 0, 0)
        input = '2016/05/27'
        self.assertEqual(parser.parse(input), date)

        input = '2016-5-27'
        self.assertEqual(parser.parse(input), date)

        input = '2016-05-27'
        self.assertEqual(parser.parse(input), date)

        today = dateimport.today()
        date = datetime.datetime(
            today.year, today.month, today.day, 12, 12, 12)
        input = '12:12:12'
        self.assertEqual(parser.parse(input), date)

        # date
        input = dateimport(2016, 5, 27)
        date = datetime.datetime(2016, 5, 27, 0, 0, 0)

timeago

A very simple python library, used to format datetime with `*** time ago` statement. eg: "3 hours ago".

MIT
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis

Similar packages