def test_age_in_future(self, age_args, expected): from rhodecode.lib.utils2 import age from dateutil import relativedelta n = datetime.datetime(year=2012, month=5, day=17) delt = lambda *args, **kwargs: relativedelta.relativedelta( *args, **kwargs) self.assertEqual(age(n + delt(**age_args), now=n), expected)
def test_age_in_future(self): import calendar from rhodecode.lib.utils2 import age n = datetime.datetime.now() delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs) self.assertEqual(age(n), u'just now') self.assertEqual(age(n + delt(seconds=1)), u'in 1 second') self.assertEqual(age(n + delt(seconds=60 * 2)), u'in 2 minutes') self.assertEqual(age(n + delt(hours=1)), u'in 1 hour') self.assertEqual(age(n + delt(hours=24)), u'in 1 day') self.assertEqual(age(n + delt(hours=24 * 5)), u'in 5 days') self.assertEqual(age(n + delt(hours=24 * (calendar.mdays[n.month]))), u'in 1 month') self.assertEqual(age(n + delt(hours=24 * (calendar.mdays[n.month] + 1))), u'in 1 month and 1 day') self.assertEqual(age(n + delt(hours=24 * 400)), u'in 1 year and 1 month')
def test_age(self): import calendar from rhodecode.lib.utils2 import age n = datetime.datetime.now() delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs) self.assertEqual(age(n), u'just now') self.assertEqual(age(n - delt(seconds=1)), u'1 second ago') self.assertEqual(age(n - delt(seconds=60 * 2)), u'2 minutes ago') self.assertEqual(age(n - delt(hours=1)), u'1 hour ago') self.assertEqual(age(n - delt(hours=24)), u'1 day ago') self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago') self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month - 1]))), u'1 month ago') self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month - 1] + 2))), u'1 month and 2 days ago') self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago')
def test_age_in_future(self, age_args, expected): from rhodecode.lib.utils2 import age from dateutil import relativedelta n = datetime.datetime(year=2012, month=5, day=17) delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) self.assertEqual(age(n + delt(**age_args), now=n), expected)