Exemplo n.º 1
0
    def test_different_timezones(self):
        """ When using two different timezones. """
        now = datetime.datetime.now()
        now_tz = datetime.datetime.now(LocalTimezone(now))
        now_tz_i = datetime.datetime.now(FixedOffset((3 * 60) + 15))

        self.assertEqual(timesince(now), '0 minutes')
        self.assertEqual(timesince(now_tz), '0 minutes')
        self.assertEqual(timeuntil(now_tz, now_tz_i), '0 minutes')
Exemplo n.º 2
0
def timesince_filter(value, arg=None):
    """Formats a date as the time since that date (i.e. "4 days, 6 hours")."""
    if not value:
        return ''
    try:
        if arg:
            return timesince(value, arg)
        return timesince(value)
    except (ValueError, TypeError):
        return ''
Exemplo n.º 3
0
    def test_display_first_unit(self):
        """
        If the two differing units aren't adjacent, only the first unit is
        displayed.
        """
        self.assertEqual(timesince(self.t,
            self.t+2*self.oneweek+3*self.onehour+4*self.oneminute),
            '2 weeks')

        self.assertEqual(timesince(self.t,
            self.t+4*self.oneday+5*self.oneminute), '4 days')
Exemplo n.º 4
0
 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 minutes')
     past = datetime.datetime(1980, 1, 1, tzinfo=naive())
     self.assertEqual(timeuntil(past), '0 minutes')
Exemplo n.º 5
0
 def test_other_units(self):
     """ Test other units. """
     self.assertEqual(timesince(self.t, self.t+self.oneminute),
         '1 minute')
     self.assertEqual(timesince(self.t, self.t+self.onehour), '1 hour')
     self.assertEqual(timesince(self.t, self.t+self.oneday), '1 day')
     self.assertEqual(timesince(self.t, self.t+self.oneweek), '1 week')
     self.assertEqual(timesince(self.t, self.t+self.onemonth),
         '1 month')
     self.assertEqual(timesince(self.t, self.t+self.oneyear), '1 year')
Exemplo n.º 6
0
 def test_display_second_before_first(self):
     """
     When the second date occurs before the first, we should always
     get 0 minutes.
     """
     self.assertEqual(timesince(self.t, self.t-self.onemicrosecond),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.onesecond),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.oneminute),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.onehour),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.oneday),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.oneweek),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.onemonth),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t-self.oneyear),
         '0 minutes')
     self.assertEqual(timesince(self.t,
         self.t-2*self.oneday-6*self.onehour), '0 minutes')
     self.assertEqual(timesince(self.t,
         self.t-2*self.oneweek-2*self.oneday), '0 minutes')
     self.assertEqual(timesince(self.t,
         self.t-2*self.oneweek-3*self.onehour-4*self.oneminute),
         '0 minutes')
     self.assertEqual(timesince(self.t,
         self.t-4*self.oneday-5*self.oneminute), '0 minutes')
Exemplo n.º 7
0
 def test_multiple_units(self):
     """ Test multiple units. """
     self.assertEqual(timesince(self.t,
         self.t+2*self.oneday+6*self.onehour), '2 days, 6 hours')
     self.assertEqual(timesince(self.t,
         self.t+2*self.oneweek+2*self.oneday), '2 weeks, 2 days')
Exemplo n.º 8
0
 def test_ignore_microseconds_and_seconds(self):
     """ Microseconds and seconds are ignored. """
     self.assertEqual(timesince(self.t, self.t+self.onemicrosecond),
         '0 minutes')
     self.assertEqual(timesince(self.t, self.t+self.onesecond),
         '0 minutes')
Exemplo n.º 9
0
 def test_equal_datetimes(self):
     """ equal datetimes. """
     self.assertEqual(timesince(self.t, self.t), '0 minutes')
Exemplo n.º 10
0
 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 minutes')
     self.assertEqual(timeuntil(today - self.oneday), '0 minutes')