Python django.utils.timesince.timeuntil() Examples

The following are 21 code examples of django.utils.timesince.timeuntil(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.utils.timesince , or try the search function .
Example #1
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #2
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #3
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #4
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #5
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #6
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #7
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #8
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #9
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #10
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #11
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #12
Source File: admin.py    From django-healthchecks with MIT License 5 votes vote down vote up
def remaining_time(self, object):
        return timeuntil(object.expires_at) 
Example #13
Source File: test_timesince.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #14
Source File: defaultfilters.py    From python2017 with MIT License 5 votes vote down vote up
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           #
################### 
Example #15
Source File: defaultfilters.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
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           #
################### 
Example #16
Source File: defaultfilters.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
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           #
################### 
Example #17
Source File: defaultfilters.py    From python with Apache License 2.0 5 votes vote down vote up
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           #
################### 
Example #18
Source File: defaultfilters.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
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           #
################### 
Example #19
Source File: defaultfilters.py    From bioforum with MIT License 5 votes vote down vote up
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           #
################### 
Example #20
Source File: __init__.py    From casepro with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def humanize_seconds(seconds):
    now = timezone.now()
    return timeuntil(now + timedelta(seconds=seconds), now) 
Example #21
Source File: defaultfilters.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
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           #
###################