Пример #1
0
    def test_week(self):
        # >>> datetime.date(2012, 1, 1).isocalendar()
        # (2011, 52, 7)
        # >>> datetime.date(2012, 12, 31).isocalendar()
        # (2013, 1, 1)

        di = DI().parse('2011-W52')
        self.assertEqual(di.dates(), [
            datetime.date(2011, 12, 26) + datetime.timedelta(i)
            for i in range(7)
        ])
        self.assertEqual(di.next().dates(), [
            datetime.date(2012, 1, 2) + datetime.timedelta(i) for i in range(7)
        ])
        self.assertEqual(str(di), '2011-W52')

        di = DI().parse('2013-W01')
        self.assertEqual(di.dates(), [
            datetime.date(2012, 12, 31) + datetime.timedelta(i)
            for i in range(7)
        ])
        self.assertEqual(di.prev().dates(), [
            datetime.date(2012, 12, 24) + datetime.timedelta(i)
            for i in range(7)
        ])
        self.assertEqual(str(di), '2013-W01')
Пример #2
0
 def test_month(self):
     di = DI().parse('2012-01')
     self.assertEqual(di.dates(), [
         datetime.date(2012, 1, 1) + datetime.timedelta(i)
         for i in range(31)
     ])
     self.assertEqual(di.next().dates(), [
         datetime.date(2012, 2, 1) + datetime.timedelta(i)
         for i in range(29)
     ])
     self.assertEqual(di.prev().dates(), [
         datetime.date(2011, 12, 1) + datetime.timedelta(i)
         for i in range(31)
     ])
     self.assertEqual(str(di), '2012-01')
Пример #3
0
 def test_year(self):
     di = DI().parse('2012')
     self.assertEqual(di.dates(), [
         datetime.date(2012, 1, 1) + datetime.timedelta(i)
         for i in range(366)
     ])
     self.assertEqual(di.next().dates(), [
         datetime.date(2013, 1, 1) + datetime.timedelta(i)
         for i in range(365)
     ])
     self.assertEqual(di.prev().dates(), [
         datetime.date(2011, 1, 1) + datetime.timedelta(i)
         for i in range(365)
     ])
     self.assertEqual(str(di), '2012')
Пример #4
0
    def test_week(self):
        # >>> datetime.date(2012, 1, 1).isocalendar()
        # (2011, 52, 7)
        # >>> datetime.date(2012, 12, 31).isocalendar()
        # (2013, 1, 1)

        di = DI().parse('2011-W52')
        self.assertEqual(di.dates(), [datetime.date(2011, 12, 26) + datetime.timedelta(i) for i in range(7)])
        self.assertEqual(di.next().dates(), [datetime.date(2012, 1, 2) + datetime.timedelta(i) for i in range(7)])
        self.assertEqual(str(di), '2011-W52')

        di = DI().parse('2013-W01')
        self.assertEqual(di.dates(), [datetime.date(2012, 12, 31) + datetime.timedelta(i) for i in range(7)])
        self.assertEqual(di.prev().dates(), [datetime.date(2012, 12, 24) + datetime.timedelta(i) for i in range(7)])
        self.assertEqual(str(di), '2013-W01')
Пример #5
0
 def test_date(self):
     di = DI().parse('2012-01-01')
     self.assertEqual(di.dates(), [datetime.date(2012, 1, 1)])
     self.assertEqual(di.next().dates(), [datetime.date(2012, 1, 2)])
     self.assertEqual(di.prev().dates(), [datetime.date(2011, 12, 31)])
     self.assertEqual(str(di), '2012-01-01')
Пример #6
0
 def test_year(self):
     di = DI().parse('2012')
     self.assertEqual(di.dates(), [datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(366)])
     self.assertEqual(di.next().dates(), [datetime.date(2013, 1, 1) + datetime.timedelta(i) for i in range(365)])
     self.assertEqual(di.prev().dates(), [datetime.date(2011, 1, 1) + datetime.timedelta(i) for i in range(365)])
     self.assertEqual(str(di), '2012')
Пример #7
0
 def test_month(self):
     di = DI().parse('2012-01')
     self.assertEqual(di.dates(), [datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(31)])
     self.assertEqual(di.next().dates(), [datetime.date(2012, 2, 1) + datetime.timedelta(i) for i in range(29)])
     self.assertEqual(di.prev().dates(), [datetime.date(2011, 12, 1) + datetime.timedelta(i) for i in range(31)])
     self.assertEqual(str(di), '2012-01')
Пример #8
0
 def test_date(self):
     di = DI().parse('2012-01-01')
     self.assertEqual(di.dates(), [datetime.date(2012, 1, 1)])
     self.assertEqual(di.next().dates(), [datetime.date(2012, 1, 2)])
     self.assertEqual(di.prev().dates(), [datetime.date(2011, 12, 31)])
     self.assertEqual(str(di), '2012-01-01')