示例#1
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\xa0weeks'
     )
     self.assertEqual(timesince(self.t, self.t + 4 * self.oneday + 5 * self.oneminute), '4\xa0days')
示例#2
0
    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')
示例#3
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\xa0minutes')
     past = datetime.datetime(1980, 1, 1, tzinfo=naive())
     self.assertEqual(timeuntil(past), '0\xa0minutes')
示例#4
0
 def test_other_units(self):
     """ Test other units. """
     self.assertEqual(timesince(self.t, self.t + self.oneminute), '1\xa0minute')
     self.assertEqual(timesince(self.t, self.t + self.onehour), '1\xa0hour')
     self.assertEqual(timesince(self.t, self.t + self.oneday), '1\xa0day')
     self.assertEqual(timesince(self.t, self.t + self.oneweek), '1\xa0week')
     self.assertEqual(timesince(self.t, self.t + self.onemonth), '1\xa0month')
     self.assertEqual(timesince(self.t, self.t + self.oneyear), '1\xa0year')
示例#5
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\xa0minutes')
     self.assertEqual(timeuntil(today - self.oneday), '0\xa0minutes')
示例#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\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.onesecond), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.oneminute), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.onehour), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.oneday), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.oneweek), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.onemonth), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - self.oneyear), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - 2 * self.oneday - 6 * self.onehour), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t - 2 * self.oneweek - 2 * self.oneday), '0\xa0minutes')
     self.assertEqual(
         timesince(self.t, self.t - 2 * self.oneweek - 3 * self.onehour - 4 * self.oneminute), '0\xa0minutes'
     )
     self.assertEqual(timesince(self.t, self.t - 4 * self.oneday - 5 * self.oneminute), '0\xa0minutes')
示例#7
0
 def test_multiple_units(self):
     """ Test multiple units. """
     self.assertEqual(timesince(self.t, self.t + 2 * self.oneday + 6 * self.onehour), '2\xa0days, 6\xa0hours')
     self.assertEqual(timesince(self.t, self.t + 2 * self.oneweek + 2 * self.oneday), '2\xa0weeks, 2\xa0days')
示例#8
0
 def test_ignore_microseconds_and_seconds(self):
     """ Microseconds and seconds are ignored. """
     self.assertEqual(timesince(self.t, self.t + self.onemicrosecond), '0\xa0minutes')
     self.assertEqual(timesince(self.t, self.t + self.onesecond), '0\xa0minutes')
示例#9
0
 def test_equal_datetimes(self):
     """ equal datetimes. """
     # NOTE: \xa0 avoids wrapping between value and unit
     self.assertEqual(timesince(self.t, self.t), '0\xa0minutes')
示例#10
0
 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')
示例#11
0
 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')
示例#12
0
 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')