本文整理汇总了Python中django.utils.timesince.timeuntil方法的典型用法代码示例。如果您正苦于以下问题:Python timesince.timeuntil方法的具体用法?Python timesince.timeuntil怎么用?Python timesince.timeuntil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.timesince
的用法示例。
在下文中一共展示了timesince.timeuntil方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remaining_time
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def remaining_time(self, object):
return timeuntil(object.expires_at)
示例2: timeuntil_filter
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def timeuntil_filter(value, arg=None):
"""Formats a date as the time until that date (i.e. "4 days, 6 hours")."""
if not value:
return ''
try:
return timeuntil(value, arg)
except (ValueError, TypeError):
return ''
###################
# LOGIC #
###################
示例3: humanize_seconds
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def humanize_seconds(seconds):
now = timezone.now()
return timeuntil(now + timedelta(seconds=seconds), now)
示例4: timeuntil_filter
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def timeuntil_filter(value, arg=None):
"""Format a date as the time until that date (i.e. "4 days, 6 hours")."""
if not value:
return ''
try:
return timeuntil(value, arg)
except (ValueError, TypeError):
return ''
###################
# LOGIC #
###################
示例5: timeuntil_filter
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def timeuntil_filter(value, arg=None):
"""Formats a date as the time until that date (i.e. "4 days, 6 hours")."""
if not value:
return ''
try:
return timeuntil(value, arg)
except (ValueError, TypeError):
return ''
###################
# LOGIC #
###################
示例6: test_different_timezones
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_different_timezones(self):
""" When using two different timezones. """
now = datetime.datetime.now()
now_tz = timezone.make_aware(now, timezone.get_default_timezone())
now_tz_i = timezone.localtime(now_tz, timezone.get_fixed_timezone(195))
self.assertEqual(timesince(now), '0\xa0minutes')
self.assertEqual(timesince(now_tz), '0\xa0minutes')
self.assertEqual(timesince(now_tz_i), '0\xa0minutes')
self.assertEqual(timesince(now_tz, now_tz_i), '0\xa0minutes')
self.assertEqual(timeuntil(now), '0\xa0minutes')
self.assertEqual(timeuntil(now_tz), '0\xa0minutes')
self.assertEqual(timeuntil(now_tz_i), '0\xa0minutes')
self.assertEqual(timeuntil(now_tz, now_tz_i), '0\xa0minutes')
示例7: test_date_objects
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_date_objects(self):
""" Both timesince and timeuntil should work on date objects (#17937). """
today = datetime.date.today()
self.assertEqual(timesince(today + self.oneday), '0\xa0minutes')
self.assertEqual(timeuntil(today - self.oneday), '0\xa0minutes')
示例8: test_both_date_objects
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_both_date_objects(self):
""" Timesince should work with both date objects (#9672) """
today = datetime.date.today()
self.assertEqual(timeuntil(today + self.oneday, today), '1\xa0day')
self.assertEqual(timeuntil(today - self.oneday, today), '0\xa0minutes')
self.assertEqual(timeuntil(today + self.oneweek, today), '1\xa0week')
示例9: test_leap_year
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_leap_year(self):
start_date = datetime.date(2016, 12, 25)
self.assertEqual(timeuntil(start_date + self.oneweek, start_date), '1\xa0week')
self.assertEqual(timesince(start_date, start_date + self.oneweek), '1\xa0week')
示例10: test_leap_year_new_years_eve
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_leap_year_new_years_eve(self):
t = datetime.date(2016, 12, 31)
now = datetime.datetime(2016, 12, 31, 18, 0, 0)
self.assertEqual(timesince(t + self.oneday, now), '0\xa0minutes')
self.assertEqual(timeuntil(t - self.oneday, now), '0\xa0minutes')
示例11: test_thousand_years_ago
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_thousand_years_ago(self):
t = datetime.datetime(1007, 8, 14, 13, 46, 0)
self.assertEqual(timesince(t, self.t), '1000\xa0years')
self.assertEqual(timeuntil(self.t, t), '1000\xa0years')
示例12: test_naive_datetime_with_tzinfo_attribute
# 需要导入模块: from django.utils import timesince [as 别名]
# 或者: from django.utils.timesince import timeuntil [as 别名]
def test_naive_datetime_with_tzinfo_attribute(self):
class naive(datetime.tzinfo):
def utcoffset(self, dt):
return None
future = datetime.datetime(2080, 1, 1, tzinfo=naive())
self.assertEqual(timesince(future), '0\xa0minutes')
past = datetime.datetime(1980, 1, 1, tzinfo=naive())
self.assertEqual(timeuntil(past), '0\xa0minutes')