示例#1
0
 def test_time(self):
     self.assertEqual(time("12:45:54"), time(12, 45, 54))
     self.assertEqual(time("2:30 PM"), time(14, 30))
     self.assertEqual(relativedelta(time("3:40"), time(2, 30)),
                      relativedelta(hours=1, minutes=10))
     self.assertEqual(relativedelta("3:40", time(2, 30)),
                      relativedelta(hours=1, minutes=10))
     self.assertEqual(relativedelta(time(2, 30), time(3, 40)),
                      relativedelta(hours=-1, minutes=-10))
示例#2
0
文件: tests.py 项目: ryanss/bdateutil
 def test_time(self):
     self.assertEqual(time("12:45:54"), time(12, 45, 54))
     self.assertEqual(time("2:30 PM"), time(14, 30))
     self.assertEqual(relativedelta(time("3:40"), time(2, 30)),
                      relativedelta(hours=1, minutes=10))
     self.assertEqual(relativedelta("3:40", time(2, 30)),
                      relativedelta(hours=1, minutes=10))
     self.assertEqual(relativedelta(time(2, 30), time(3, 40)),
                      relativedelta(hours=-1, minutes=-10))
示例#3
0
 def test_radd_time(self):
     self.assertEqual(datetime("2015-01-02 16:45") +
                      relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 9, 15))
     self.assertEqual(date(2015, 1, 2) + relativedelta(bminutes=+30),
                      datetime(2015, 1, 2, 9, 30))
     self.assertEqual(date(2014, 1, 3) + relativedelta(bdays=1, bhours=4),
                      datetime(2014, 1, 6, 13, 0))
     bdateutil.BTSTART = time(7, 30)
     self.assertEqual(datetime("2015-01-02 16:45") +
                      relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 7, 45))
     self.assertEqual(datetime("2015-01-02 16:45") +
                      relativedelta(bhours=+0.5),
                      datetime(2015, 1, 5, 7, 45))
     bdateutil.BTSTART = time(9, 0)
示例#4
0
文件: tests.py 项目: ryanss/bdateutil
 def test_radd_time(self):
     self.assertEqual(datetime("2015-01-02 16:45") +
                      relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 9, 15))
     self.assertEqual(date(2015, 1, 2) + relativedelta(bminutes=+30),
                      datetime(2015, 1, 2, 9, 30))
     self.assertEqual(date(2014, 1, 3) + relativedelta(bdays=1, bhours=4),
                      datetime(2014, 1, 6, 13, 0))
     bdateutil.BTSTART = time(7, 30)
     self.assertEqual(datetime("2015-01-02 16:45") +
                      relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 7, 45))
     self.assertEqual(datetime("2015-01-02 16:45") +
                      relativedelta(bhours=+0.5),
                      datetime(2015, 1, 5, 7, 45))
     bdateutil.BTSTART = time(9, 0)
示例#5
0
 def test_add_sub(self):
     self.assertEqual(datetime("2014-11-15 1:23").add(bdays=1),
                      datetime(2014, 11, 18, 1, 23))
     self.assertEqual(datetime("2014-11-15 1:23").sub(bdays=-1),
                      datetime(2014, 11, 18, 1, 23))
     self.assertEqual(date(2016, 1, 1).add(hours=2, minutes=4),
                      datetime(2016, 1, 1, 2, 4))
     self.assertEqual(datetime(2016, 1, 1, 0).sub(days=1),
                      datetime(2015, 12, 31, 0))
     ush = holidays.US()
     self.assertEqual(date(2016, 12, 30).add(bdays=1, holidays=ush),
                      date(2017, 1, 3))
     self.assertEqual(date(2016, 12, 31).add(bdays=0, holidays=ush),
                      date(2017, 1, 3))
     self.assertEqual(date(2016, 12, 31).add(bdays=1, holidays=ush),
                      date(2017, 1, 4))
     self.assertEqual(time(3, 40).add(hours=5, minutes=25), time(9, 5))
示例#6
0
文件: tests.py 项目: ryanss/bdateutil
 def test_add_sub(self):
     self.assertEqual(datetime("2014-11-15 1:23").add(bdays=1),
                      datetime(2014, 11, 18, 1, 23))
     self.assertEqual(datetime("2014-11-15 1:23").sub(bdays=-1),
                      datetime(2014, 11, 18, 1, 23))
     self.assertEqual(date(2016, 1, 1).add(hours=2, minutes=4),
                      datetime(2016, 1, 1, 2, 4))
     self.assertEqual(datetime(2016, 1, 1, 0).sub(days=1),
                      datetime(2015, 12, 31, 0))
     ush = holidays.US()
     self.assertEqual(date(2016, 12, 30).add(bdays=1, holidays=ush),
                      date(2017, 1, 3))
     self.assertEqual(date(2016, 12, 31).add(bdays=0, holidays=ush),
                      date(2017, 1, 3))
     self.assertEqual(date(2016, 12, 31).add(bdays=1, holidays=ush),
                      date(2017, 1, 4))
     self.assertEqual(time(3, 40).add(hours=5, minutes=25), time(9, 5))
示例#7
0
 def test_datetime(self):
     self.assertEqual(datetime("2015-03-25 12:34"),
                      dt.datetime(2015, 3, 25, 12, 34))
     self.assertEqual(datetime(2015, 3, 15, 23, 45).month_end(),
                      datetime(2015, 3, 31, 23, 59, 59, 999999))
     self.assertEqual(datetime.now().date(), dt.datetime.now().date())
     self.assertEqual(datetime.now(bdays=-45).date(),
                      (dt.datetime.now() - relativedelta(bdays=45)).date())
     self.assertEqual(datetime(time("3:40")),
                      dt.datetime.combine(dt.datetime.today(),
                                          dt.time(3, 40, 0)))
示例#8
0
文件: tests.py 项目: ryanss/bdateutil
 def test_datetime(self):
     self.assertEqual(datetime("2015-03-25 12:34"),
                      dt.datetime(2015, 3, 25, 12, 34))
     self.assertEqual(datetime(2015, 3, 15, 23, 45).month_end(),
                      datetime(2015, 3, 31, 23, 59, 59, 999999))
     self.assertEqual(datetime.now().date(), dt.datetime.now().date())
     self.assertEqual(datetime.now(bdays=-45).date(),
                      (dt.datetime.now() - relativedelta(bdays=45)).date())
     self.assertEqual(datetime(time("3:40")),
                      dt.datetime.combine(dt.datetime.today(),
                                          dt.time(3, 40, 0)))
示例#9
0
 def test_init_time(self):
     self.assertEqual(relativedelta(datetime(2015, 1, 5, 9, 15),
                                    datetime(2015, 1, 2, 16, 45)),
                      relativedelta(days=2, hours=16, minutes=30,
                                    bminutes=30))
     self.assertEqual(relativedelta(datetime(2015, 1, 20, 21, 22),
                                    datetime(2015, 1, 9, 3, 0)),
                      relativedelta(days=11, hours=18, minutes=22,
                                    bdays=7, bhours=8, bminutes=0))
     self.assertEqual(relativedelta(datetime(2015, 1, 20, 21, 22),
                                    datetime(2015, 1, 9, 3, 0),
                                    holidays=holidays.US()),
                      relativedelta(days=11, hours=18, minutes=22,
                                    bdays=6, bhours=8, bminutes=0))
     bdateutil.HOLIDAYS = holidays.CA()
     self.assertEqual(relativedelta(datetime(2015, 1, 20, 21, 22),
                                    datetime(2015, 1, 9, 3, 0)),
                      relativedelta(days=11, hours=18, minutes=22,
                                    bdays=7, bhours=8, bminutes=0))
     bdateutil.HOLIDAYS = []
     self.assertEqual(relativedelta(time(3, 40), time(2, 37)),
                      relativedelta(hours=1, minutes=3))
示例#10
0
文件: tests.py 项目: ryanss/bdateutil
 def test_init_time(self):
     self.assertEqual(relativedelta(datetime(2015, 1, 5, 9, 15),
                                    datetime(2015, 1, 2, 16, 45)),
                      relativedelta(days=2, hours=16, minutes=30,
                                    bminutes=30))
     self.assertEqual(relativedelta(datetime(2015, 1, 20, 21, 22),
                                    datetime(2015, 1, 9, 3, 0)),
                      relativedelta(days=11, hours=18, minutes=22,
                                    bdays=7, bhours=8, bminutes=0))
     self.assertEqual(relativedelta(datetime(2015, 1, 20, 21, 22),
                                    datetime(2015, 1, 9, 3, 0),
                                    holidays=holidays.US()),
                      relativedelta(days=11, hours=18, minutes=22,
                                    bdays=6, bhours=8, bminutes=0))
     bdateutil.HOLIDAYS = holidays.CA()
     self.assertEqual(relativedelta(datetime(2015, 1, 20, 21, 22),
                                    datetime(2015, 1, 9, 3, 0)),
                      relativedelta(days=11, hours=18, minutes=22,
                                    bdays=7, bhours=8, bminutes=0))
     bdateutil.HOLIDAYS = []
     self.assertEqual(relativedelta(time(3, 40), time(2, 37)),
                      relativedelta(hours=1, minutes=3))
示例#11
0
 def test_radd_time(self):
     self.assertEqual("2015-01-02 16:45" + relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 9, 15))
     self.assertEqual(date(2015, 1, 2) + relativedelta(bminutes=+30),
                      datetime(2015, 1, 2, 9, 30))
     self.assertEqual(date(2014, 1, 3) + relativedelta(bdays=1, bhours=4),
                      datetime(2014, 1, 6, 13, 0))
     relativedelta.btstart = time(7, 30)
     self.assertEqual("2015-01-02 16:45" + relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 7, 45))
     self.assertEqual("2015-01-02 16:45" + relativedelta(bhours=+0.5),
                      datetime(2015, 1, 5, 7, 45))
     del relativedelta.btstart
示例#12
0
 def test_radd_time(self):
     self.assertEqual("2015-01-02 16:45" + relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 9, 15))
     self.assertEqual(
         date(2015, 1, 2) + relativedelta(bminutes=+30),
         datetime(2015, 1, 2, 9, 30))
     self.assertEqual(
         date(2014, 1, 3) + relativedelta(bdays=1, bhours=4),
         datetime(2014, 1, 6, 13, 0))
     relativedelta.btstart = time(7, 30)
     self.assertEqual("2015-01-02 16:45" + relativedelta(bminutes=+30),
                      datetime(2015, 1, 5, 7, 45))
     self.assertEqual("2015-01-02 16:45" + relativedelta(bhours=+0.5),
                      datetime(2015, 1, 5, 7, 45))
     del relativedelta.btstart
示例#13
0
 def test_date(self):
     self.assertEqual(date("2015-03-25"), dt.date(2015, 3, 25))
     self.assertEqual(date("1/2/2014"), dt.date(2014, 1, 2))
     self.assertEqual(date(1388577600), dt.date(2014, 1, 1))
     self.assertRaises(ValueError, lambda: date("abc"))
     self.assertRaises(TypeError, lambda: date(['a', 'b', 'c']))
     self.assertRaises(TypeError, lambda: date(time(3, 40)))
     self.assertEqual(date(2015, 2, 15).month_end(), date(2015, 2, 28))
     self.assertEqual(date.today(), dt.date.today())
     self.assertEqual(date.today(days=+1),
                      dt.date.today() + relativedelta(days=+1))
     self.assertEqual(date.today(bdays=+200, holidays=holidays.US()),
                      dt.date.today() +
                      relativedelta(bdays=+200, holidays=holidays.US()))
     relativedelta.holidays = holidays.US()
     self.assertEqual(date.today(bdays=+200),
                      dt.date.today() + relativedelta(bdays=+200))
     del relativedelta.holidays
示例#14
0
文件: tests.py 项目: ryanss/bdateutil
 def test_date(self):
     self.assertEqual(date("2015-03-25"), dt.date(2015, 3, 25))
     self.assertEqual(date("1/2/2014"), dt.date(2014, 1, 2))
     self.assertEqual(date(1388577600), dt.date(2014, 1, 1))
     self.assertRaises(ValueError, lambda: date("abc"))
     self.assertRaises(TypeError, lambda: date(['a', 'b', 'c']))
     self.assertRaises(TypeError, lambda: date(time(3, 40)))
     self.assertEqual(date(2015, 2, 15).month_end(), date(2015, 2, 28))
     self.assertEqual(date.today(), dt.date.today())
     self.assertEqual(date.today(days=+1),
                      dt.date.today() + relativedelta(days=+1))
     self.assertEqual(date.today(bdays=+200, holidays=holidays.US()),
                      dt.date.today() +
                      relativedelta(bdays=+200, holidays=holidays.US()))
     relativedelta.holidays = holidays.US()
     self.assertEqual(date.today(bdays=+200),
                      dt.date.today() + relativedelta(bdays=+200))
     del relativedelta.holidays
示例#15
0
 def test_BTSTART_BTEND(self):
     self.assertEqual(time(16, 30) + relativedelta(bminutes=60),
                      time(9, 30))
     bdateutil.BTSTART = time(10, 30)
     bdateutil.BTEND = time(16, 45)
     self.assertEqual(time(16, 30) + relativedelta(bminutes=60),
                      time(11, 15))
     self.assertEqual(time(16, 30) + relativedelta(bminutes=60,
                                                   btstart=time(11, 30)),
                      time(12, 15))
     bdateutil.BTEND = time(8, 0)
     self.assertRaises(ValueError,
                       lambda: time(16, 30) + relativedelta(bminutes=60))
     bdateutil.BTEND = None
     self.assertRaises(TypeError,
                       lambda: time(16, 30) + relativedelta(bminutes=60))
     bdateutil.BTSTART = time(9, 0)
     bdateutil.BTEND = time(17, 0)
示例#16
0
文件: tests.py 项目: ryanss/bdateutil
 def test_BTSTART_BTEND(self):
     self.assertEqual(time(16, 30) + relativedelta(bminutes=60),
                      time(9, 30))
     bdateutil.BTSTART = time(10, 30)
     bdateutil.BTEND = time(16, 45)
     self.assertEqual(time(16, 30) + relativedelta(bminutes=60),
                      time(11, 15))
     self.assertEqual(time(16, 30) + relativedelta(bminutes=60,
                                                   btstart=time(11, 30)),
                      time(12, 15))
     bdateutil.BTEND = time(8, 0)
     self.assertRaises(ValueError,
                       lambda: time(16, 30) + relativedelta(bminutes=60))
     bdateutil.BTEND = None
     self.assertRaises(TypeError,
                       lambda: time(16, 30) + relativedelta(bminutes=60))
     bdateutil.BTSTART = time(9, 0)
     bdateutil.BTEND = time(17, 0)