當前位置: 首頁>>代碼示例>>Python>>正文


Python timesince.timeuntil方法代碼示例

本文整理匯總了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) 
開發者ID:mvantellingen,項目名稱:django-healthchecks,代碼行數:4,代碼來源:admin.py

示例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           #
################### 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:defaultfilters.py

示例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) 
開發者ID:rapidpro,項目名稱:casepro,代碼行數:5,代碼來源:__init__.py

示例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           #
################### 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:defaultfilters.py

示例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           #
################### 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:14,代碼來源:defaultfilters.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:test_timesince.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_timesince.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:test_timesince.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:test_timesince.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_timesince.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:test_timesince.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:10,代碼來源:test_timesince.py


注:本文中的django.utils.timesince.timeuntil方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。