本文整理匯總了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')