Beispiel #1
0
 def test_datetime_from_str_p04_match_ts_maintain(self):
     self.assertEqual(kvdate.datetime_from_str('2021-12-31'),
                      datetime.datetime(2021, 12, 31))
     self.assertEqual(kvdate.datetime_from_str('2021-12-31 00:00:00'),
                      datetime.datetime(2021, 12, 31))
     self.assertEqual(kvdate.datetime_from_str('12/31/2021'),
                      datetime.datetime(2021, 12, 31))
     self.assertEqual(kvdate.datetime_from_str('2021-12-31T00:00:00Z'),
                      datetime.datetime(2021, 12, 31))
Beispiel #2
0
 def test_datetime_from_str_p02_notzero_padded(self):
     self.assertEqual(kvdate.datetime_from_str('1/1/19'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('1/1/2019'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('1-1-19'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('1-1-2019'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('2019-1-1'),
                      datetime.datetime(2019, 1, 1))
Beispiel #3
0
def xldate_to_datetime(xldate, skipblank=False):
    if isinstance(xldate, str):
        logger.debug(
            'converting xldate string to date using kvdate.datetime_from_str:%s',
            xldate)
        return kvdate.datetime_from_str(xldate, skipblank)
    else:
        logger.debug('converting xldate float to date:%s', xldate)
        temp = datetime.datetime(1899, 12, 30)
        delta = datetime.timedelta(days=xldate)
        return temp + delta
Beispiel #4
0
 def test_datetime_from_str_p01_zero_padded(self):
     self.assertEqual(kvdate.datetime_from_str('01/01/19'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('01/01/2019'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('01-01-19'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('01-01-2019'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('2019-01-01'),
                      datetime.datetime(2019, 1, 1))
     self.assertEqual(kvdate.datetime_from_str('20190101'),
                      datetime.datetime(2019, 1, 1))
Beispiel #5
0
 def test_datetime_from_str_f03_blank(self):
     with self.assertRaises(Exception) as context:
         kvdate.datetime_from_str('')
Beispiel #6
0
 def test_datetime_from_str_f02_no_matching_format(self):
     with self.assertRaises(Exception) as context:
         kvdate.datetime_from_str('1/1/20019')
Beispiel #7
0
 def test_datetime_from_str_f01_invalid_date(self):
     with self.assertRaises(Exception) as context:
         kvdate.datetime_from_str('20/1/19')
Beispiel #8
0
 def test_datetime_from_str_p03_blank_stripblank(self):
     self.assertEqual(kvdate.datetime_from_str('', True), '')