Exemplo n.º 1
0
    def test_interval_level_0(self):
        for i, o, r in [
            ('1964/2008', ('1964', '2008'),
             ('1964-01-01', '1964-12-31', '2008-01-01', '2008-12-31')
            ),
            ('2004-06/2006-08', ('2004-06', '2006-08'),
             ('2004-06-01', '2004-06-30', '2006-08-01', '2006-08-31')
            ),
            ('2004-02-01/2005-02-08', ('2004-02-01', '2005-02-08'),
             ('2004-02-01', '2004-02-01', '2005-02-08', '2005-02-08')
            ),
            ('2004-02-01/2005-02', ('2004-02-01', '2005-02'),
             ('2004-02-01', '2004-02-01', '2005-02-01', '2005-02-28')
            ),
            ('2004-02-01/2005', ('2004-02-01', '2005'),
             ('2004-02-01', '2004-02-01', '2005-01-01', '2005-12-31')
            ),
            ('2005/2006-02', ('2005', '2006-02'),
             ('2005-01-01', '2005-12-31', '2006-02-01', '2006-02-28')
            ),
        ]:
            o1, o2 = o
            e = EDTFInterval(i)
            self.assertEqual(unicode(e), i)
            self.assertEqual(unicode(e.start), o1)
            self.assertEqual(unicode(e.end), o2)

            start_earliest, start_latest, end_earliest, end_latest = r
            self.assertEqual(e.start_date_earliest().isoformat(), start_earliest)
            self.assertEqual(e.start_date_latest().isoformat(), start_latest)
            self.assertEqual(e.end_date_earliest().isoformat(), end_earliest)
            self.assertEqual(e.end_date_latest().isoformat(), end_latest)
Exemplo n.º 2
0
 def test_interval_sort_value(self):
     for i, o1, o2 in [
         ('2001/2004', '2004-12-31', '2001-01-01'),
         ('2001/unknown', '2001-12-31', '2001-01-01'),
         ('unknown/2001', '2001-12-31', '2001-01-01'),
         ('unknown/unknown', MAX_ISO, MIN_ISO),
     ]:
         e = EDTFInterval(i)
         self.assertEqual(e.sort_date_earliest().isoformat(), o2)
         self.assertEqual(e.sort_date_latest().isoformat(), o1)
Exemplo n.º 3
0
    def test_interval_level_1(self):

        for i, r in [
            # unknown vs open at different precisions
            # assuming complete overlap
            # for open, we go to the max/min
            # for unknown, we add
            # if precision = millenium, 10000 years
            # if precision = century, 1000 years
            # if precision = decade, 100 years
            # if precision = year, 10 years
            # if precision = month, 1 year
            # if precision = day, 1 month
            ('2004-06-01/unknown',
             ('2004-06-01', '2004-06-01', '2004-06-01', '2004-07-01')),
            ('2004-06/unknown',
             ('2004-06-01', '2004-06-30', '2004-06-01', '2005-06-30')),
            ('2004/unknown',
            ('2004-01-01', '2004-12-31', '2004-01-01', '2009-12-31')),
            ('2004-01-01/open',
            ('2004-01-01', '2004-01-01', '2004-01-01', MAX_ISO)),
            ('2004-01/open',
            ('2004-01-01', '2004-01-31', '2004-01-01', MAX_ISO)),
            ('2004/open',
            ('2004-01-01', '2004-12-31', '2004-01-01', MAX_ISO)),

            ('unknown/2004-06-01',
             ('2004-05-01', '2004-06-01', '2004-06-01', '2004-06-01')),
            ('unknown/2004-06',
             ('2003-06-01', '2004-06-30', '2004-06-01', '2004-06-30')),
            ('unknown/2004',
             ('1999-01-01', '2004-12-31', '2004-01-01', '2004-12-31')),
            ('open/2004-06-01',
             (MIN_ISO, '2004-06-01', '2004-06-01', '2004-06-01')),
            ('open/2004-06',
             (MIN_ISO, '2004-06-30', '2004-06-01', '2004-06-30')),
            ('open/2004',
             (MIN_ISO, '2004-12-31', '2004-01-01', '2004-12-31')),

            #unknown vs open with different accuracies
            ('2004-06-01?~/unknown',
             ('2004-05-30', '2004-06-03', '2004-05-30', '2004-07-03')),
            ('2004-06?~/unknown',
             ('2004-04-30', '2004-08-01', '2004-04-30', '2005-08-01')),
            ('2004?~/unknown',
             ('2003-01-01', '2005-12-31', '2003-01-01', '2010-12-31')),
            ('2004-01-01?~/open',
             ('2003-12-30', '2004-01-03', '2003-12-30', MAX_ISO)),
            ('2004-01?~/open',
             ('2003-11-30', '2004-03-03', '2003-11-30', MAX_ISO)),
            ('2004?~/open',
             ('2003-01-01', '2005-12-31', '2003-01-01', MAX_ISO)),

            #weird ones
            ('open/open',
             (MIN_ISO, MAX_ISO, MIN_ISO, MAX_ISO)),
            ('open/unknown',
             (MIN_ISO, MAX_ISO, MIN_ISO, MAX_ISO)),
            ('unknown/open',
             (MIN_ISO, MAX_ISO, MIN_ISO, MAX_ISO)),
            ('unknown/unknown',
             (MIN_ISO, MAX_ISO, MIN_ISO, MAX_ISO)),

            # combinations of inaccuracies
            ('1984~/2004-06',
             ('1983-07-01', '1985-06-30', '2004-06-01', '2004-06-30')),
            ('1984/2004-06~',
             ('1984-01-01', '1984-12-31', '2004-05-16', '2004-07-16')),
            ('1984~/2004~',
             ('1983-07-01', '1985-06-30', '2003-07-01', '2005-06-30')),
            ('1984?/2004?~',
             ('1983-07-01', '1985-06-30', '2003-01-01', '2005-12-31')),
            ('1984-06?/2004-08?',
             ('1984-05-16', '1984-07-16', '2004-07-16', '2004-09-16')),
            ('1984-06-02?/2004-08-08~',
             ('1984-06-01', '1984-06-03', '2004-08-07', '2004-08-09')),
        ]:
            e = EDTFInterval(i)
            start_earliest, start_latest, end_earliest, end_latest = r
            self.assertEqual(e.start_date_earliest().isoformat(), start_earliest)
            self.assertEqual(e.start_date_latest().isoformat(), start_latest)
            self.assertEqual(e.end_date_earliest().isoformat(), end_earliest)
            self.assertEqual(e.end_date_latest().isoformat(), end_latest)