def test_year_with_century(self): """ Tests the format_date function for %Y. """ date_str = '1988-08-16' date_format = '%Y-%m-%d' actual = dt.format_date(date_str, date_format) self.assertEqual(actual.year, 1988) self.assertEqual(actual.month, 8) self.assertEqual(actual.day, 16)
def test_locale_datetime(self): """ Tests the format_date function for %c. """ date_str = 'Tue Aug 16 21:30:00 1988' date_format = '%c' actual = dt.format_date(date_str, date_format) self.assertEqual(actual.year, 1988) self.assertEqual(actual.month, 8) self.assertEqual(actual.day, 16)
def test_year_without_century(self): """ Tests the format_date function for %y. """ date_str = '08-16-88' date_format = '%m-%d-%y' actual = dt.format_date(date_str, date_format) self.assertEqual(actual.year, 1988) self.assertEqual(actual.month, 8) self.assertEqual(actual.day, 16)
def test_no_year(self): """ Tests the format_date function for a date without a year. """ date_str = 'Aug 16 20:16:38' date_format = '%b %d %X' utc_now = datetime.datetime.now(datetime.timezone.utc) actual = dt.format_date(date_str, date_format) self.assertEqual(actual.year, utc_now.year) self.assertEqual(actual.month, 8) self.assertEqual(actual.day, 16)
def test_locale_date(self): """ Tests the format_date function for %x. """ date_str = '08/16/88' date_format = '%x' actual = dt.format_date(date_str, date_format) self.assertEqual(actual.year, 1988) self.assertEqual(actual.month, 8) self.assertEqual(actual.day, 16) self.assertEqual(str(actual.tzinfo), 'UTC')