Esempio n. 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')
Esempio n. 2
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')
Esempio n. 3
0
 def test_interval(self):
     di = DI().parse('2012-01-01-2012-02-01')
     self.assertEqual(di.dates(), [
         datetime.date(2012, 1, 1) + datetime.timedelta(i)
         for i in xrange(31)
     ])
     self.assertRaises(NotImplementedError, di.next)
     self.assertRaises(NotImplementedError, di.prev)
Esempio n. 4
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')
Esempio n. 5
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')
Esempio n. 6
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')
Esempio n. 7
0
 def test_interval(self):
     di = DI().parse('2012-01-01-2012-02-01')
     self.assertEqual(di.dates(), [datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(31)])
     self.assertRaises(NotImplementedError, di.next)
     self.assertRaises(NotImplementedError, di.prev)
     self.assertEquals(di.to_string(), '2012-01-01-2012-02-01')
Esempio n. 8
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')
Esempio n. 9
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')
Esempio n. 10
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')