def test_date_cleaner(self): """We return the value if it's convertable to a python datetime.""" self.assertEqual(cleaners.date_cleaner(u'2/12/2012'), u'2/12/2012') self.assertEqual(cleaners.date_cleaner(u''), None) self.assertEqual(cleaners.date_cleaner(u'some string'), None) self.assertEqual(cleaners.date_cleaner(u'00'), None) now = datetime.datetime.now() self.assertEqual(cleaners.date_cleaner(now), now)
def test_date_cleaner(self): """We return the value if it's convertible to a python datetime.""" self.assertEqual( cleaners.date_cleaner(u'2/12/2012'), datetime.datetime(2012, 2, 12, 0, 0, tzinfo=timezone.get_current_timezone())) self.assertEqual(cleaners.date_cleaner(u''), None) self.assertEqual(cleaners.date_cleaner(u'some string'), None) self.assertEqual(cleaners.date_cleaner(u'00'), None) now = datetime.datetime.now() self.assertEqual(cleaners.date_cleaner(now), now)
def clean(self): date_field_names = ('year_ending', 'generation_date', 'release_date', 'recent_sale_date') for field in date_field_names: value = getattr(self, field) if value and isinstance(value, basestring): _log.info("Saving %s which is a date time" % field) _log.info(convert_datestr(value)) _log.info(date_cleaner(value))
def test_date_conversion(self): date = datetime(2016, 7, 15).date() self.assertEqual(date_cleaner(date.strftime("%Y-%m-%d")), date) # self.assertEqual(convert_datestr(date.strftime("%Y-%m-%d")), date) dt = datetime(2016, 7, 15, 12, 30) self.assertEqual(convert_datestr(dt.strftime("%Y-%m-%d %H:%M")), dt) # with TZ info dt = make_aware(datetime(2016, 7, 15, 12, 30), pytz.UTC) self.assertEqual(convert_datestr(dt.strftime("%Y-%m-%d %H:%M"), True), dt)