def test_start_end_properties(self):
     rng = dt_range('1980-1990')
     self.assertEqual(rng.start, dt('1980'))
     self.assertEqual(rng.end, dt('1990'))
     rng = dt_range('19800101-19871225')
     self.assertEqual(rng.start, dt('19800101'))
     self.assertEqual(rng.end, dt('19871225'))
 def test_repr(self):
     globs = {'DateRange': dt_range, 'Date': dt}
     r1 = dt_range('2000-2010')
     self.assertEqual(r1, eval(repr(r1), globs))
     r1 = dt_range('199912-200001')
     self.assertEqual(r1, eval(repr(r1), globs))
     r1 = dt_range('20000101-20000201')
     self.assertEqual(r1, eval(repr(r1), globs))
 def test_span(self):
     dtr1 = dt_range('20190101', '20190131')
     dtr2 = dt_range('20190201', '20190228')
     dt0 = dt('2019-09-18')
     self.assertEqual(dt_range.from_contiguous_span(FXDateRange),
                      FXDateRange)
     with self.assertRaises(FXDateException):
         _ = dt_range.from_contiguous_span(FXDateRange, FXDateRange)
     with self.assertRaises(FXDateException):
         _ = dt_range.from_contiguous_span(dtr1, FXDateRange, dtr2)
     with self.assertRaises(FXDateException):
         _ = dt_range.from_contiguous_span(dtr1, dtr2, FXDateRange)
     with self.assertRaises(FXDateException):
         _ = dt_range.from_date_span(FXDateMin, FXDateMax)
     with self.assertRaises(FXDateException):
         _ = dt_range.from_date_span(dt0, FXDateMax)
 def test_more_intersection(self):
     # mixed precision
     rng1 = dt_range('1980-1990')
     rng2 = [
         dt_range('19780501-19871225'),
         dt_range('19780501-19901231'),
         dt_range('19780501-19981225'),
         dt_range('19800101-19871225'),
         dt_range('19800101-19901231'),
         dt_range('19800101-19981225'),
         dt_range('19830501-19871225'),
         dt_range('19830501-19901231'),
         dt_range('19830501-19981225')
     ]
     for d in rng2:
         self.assertTrue(rng1.intersection(d) == d.intersection(rng1))
 def test_is_static(self):
     dtr = dt_range('19800101-19901231')
     dt0 = dt('2019-09-18')
     self.assertTrue(FXDateMin.is_static)
     self.assertTrue(FXDateMax.is_static)
     self.assertTrue(FXDateRange.is_static)
     self.assertFalse(dt0.is_static)
     self.assertFalse(dtr.is_static)
 def test_contain(self):
     dtr = dt_range('19800101-19901231')
     dt0 = dt('2019-09-18')
     self.assertTrue(dtr in FXDateRange)
     self.assertTrue(dt0 in FXDateRange)
     self.assertTrue(FXDateRange.contains(dtr))
     self.assertTrue(FXDateRange.contains(dt0))
     self.assertTrue(FXDateRange.overlaps(dtr))
     self.assertTrue(FXDateRange.overlaps(dt0))
     self.assertFalse(dtr.contains(FXDateRange))
     self.assertTrue(dtr.overlaps(FXDateRange))
     with self.assertRaises(FXDateException):
         _ = (dtr.intersection(FXDateRange))
     with self.assertRaises(FXDateException):
         _ = (FXDateRange.intersection(dtr))
 def test_more_contains(self):
     # mixed precision
     self.assertTrue(
         dt_range('198001010130-199912312230').contains(
             dt_range('1992-1999')))
     self.assertTrue(
         dt_range('199201010130-199912312230').contains(
             dt_range('1992-1999')))
     self.assertTrue(
         dt_range('1980-1999').contains(dt_range('19800101-19991231')))
 def test_compare(self):
     dtr = dt_range('19800101-19901231')
     dt0 = dt('2019-09-18')
     with self.assertRaises(FXDateException):
         _ = (dt0 > FXDateMin)
     with self.assertRaises(FXDateException):
         _ = (dt0 <= FXDateMax)
     with self.assertRaises(FXDateException):
         _ = (dtr > FXDateMin)
     with self.assertRaises(FXDateException):
         _ = (dtr <= FXDateMax)
     with self.assertRaises(FXDateException):
         _ = (FXDateMin <= FXDateMax)
     with self.assertRaises(FXDateException):
         _ = (dtr <= FXDateRange)
     self.assertTrue(dtr != FXDateRange)
     self.assertTrue(dt0 != FXDateMax)
 def test_input_range_parsing(self):
     dtr1 = dt_range('20190101', '20190131')
     dtr2 = dt_range('20190201', '20190228')
     dtr3 = dt_range('20190301', '20190331')
     self.assertEqual(dt_range.from_contiguous_span(dtr1, dtr2, dtr3),
                      dt_range(dt(2019, 1, 1), dt(2019, 3, 31)))
     self.assertEqual(dt_range.from_contiguous_span(dtr3, dtr1, dtr2),
                      dt_range(dt(2019, 1, 1), dt(2019, 3, 31)))
     with self.assertRaises(ValueError):
         _ = dt_range.from_contiguous_span(dtr3, dtr1)
     with self.assertRaises(ValueError):
         _ = dt_range.from_contiguous_span(dtr1,
                                           dt_range('20190214', '20190215'))
     with self.assertRaises(ValueError):
         _ = dt_range.from_contiguous_span(dtr1, dtr2, dtr3,
                                           dt_range('20190214', '20190215'))
     with self.assertRaises(ValueError):
         _ = dt_range.from_contiguous_span(dtr3, dtr1,
                                           dt_range('20181214', '20190215'),
                                           dtr2)
 def test_more_overlaps(self):
     # mixed precision
     rng1 = dt_range('1980-1990')
     rng2 = [(dt_range('19780501-19781225'), False, False, False, False),
             (dt_range('19780501-19800101'), True, True, False, False),
             (dt_range('19780501-19871225'), True, True, False, False),
             (dt_range('19780501-19901231'), True, True, True, False),
             (dt_range('19780501-19981225'), True, True, True, False),
             (dt_range('19800101-19871225'), True, True, False, True),
             (dt_range('19800101-19901231'), True, True, True, True),
             (dt_range('19800101-19981225'), True, True, True, False),
             (dt_range('19830501-19871225'), True, True, False, True),
             (dt_range('19830501-19901231'), True, True, False, True),
             (dt_range('19830501-19981225'), True, True, False, False),
             (dt_range('19901231-19981225'), True, True, False, False),
             (dt_range('19930501-19981225'), False, False, False, False)]
     for d in rng2:
         self.assertTrue(rng1.overlaps(d[0]) == d[1])
         self.assertTrue(d[0].overlaps(rng1) == d[2])
         self.assertTrue(d[0].contains(rng1) == d[3])
         self.assertTrue(rng1.contains(d[0]) == d[4])
 def test_intersect(self):
     r1 = dt_range('2000-2010')
     with self.assertRaises(ValueError):
         _ = r1.intersection(dt_range('1900-1990'))
     self.assertEqual(r1.intersection(dt_range('2002-2008')),
                      dt_range('2002-2008'))
     self.assertEqual(r1.intersection(dt_range('1999-2018')),
                      dt_range('2000-2010'))
     self.assertEqual(r1.intersection(dt_range('2002-2018')),
                      dt_range('2002-2010'))
     self.assertEqual(r1.intersection(dt_range('1999-2008')),
                      dt_range('2000-2008'))
     self.assertEqual(r1.intersection(dt_range('2000-2010')),
                      dt_range('2000-2010'))
    def test_in_contains(self):
        r1 = dt_range(dt(2010), dt(2020))
        # move right endpoint, then left endpoint of test interval
        self.assertEqual(r1 in dt_range('2008-2009'), False)
        self.assertEqual(r1 in dt_range('2008-2010'), False)
        self.assertEqual(r1 in dt_range('2008-2019'), False)
        self.assertEqual(r1 in dt_range('2008-2020'), True)
        self.assertEqual(r1 in dt_range('2008-2022'), True)

        self.assertEqual(r1 in dt_range('2010-2019'), False)
        self.assertEqual(r1 in dt_range('2010-2020'), True)
        self.assertEqual(r1 in dt_range('2010-2022'), True)

        self.assertEqual(r1 in dt_range('2011-2019'), False)
        self.assertEqual(r1 in dt_range('2011-2020'), False)
        self.assertEqual(r1 in dt_range('2011-2022'), False)

        self.assertEqual(r1 in dt_range('2020-2022'), False)
        self.assertEqual(r1 in dt_range('2021-2022'), False)
 def test_input_list_parsing(self):
     self.assertEqual(
         dt_range.from_date_span(dt(2015), dt(2010), dt(2019), dt(2017)),
         dt_range(2010, 2019))
     self.assertEqual(dt_range(['20100201', '20190918']),
                      dt_range('20100201', '20190918'))
 def test_input_string_parsing(self):
     self.assertEqual(dt_range(2010, 2019), dt_range(dt(2010), dt(2019)))
     self.assertEqual(dt_range('20100201', '20190918'),
                      dt_range(dt(2010, 2, 1), dt(2019, 9, 18)))