예제 #1
0
 def test_validate(self):
     self.assertTrue(dates.validate('2017-04-04T10:30:29'))
     self.assertTrue(dates.validate('2017-04-04T10:30:29Z'))
     self.assertTrue(dates.validate('2017-04-04T10:30:29+01'))
     self.assertTrue(dates.validate('2017-04-04T10:30:29+0200'))
     self.assertTrue(dates.validate('2017-04-04T10:30:29+03:00'))
     self.assertTrue(dates.validate('2017-04-04T10:30:29-04:00'))
     self.assertTrue(dates.validate(datetime.utcnow().isoformat()))
     self.assertFalse(dates.validate('01-02-2003'))
     self.assertFalse(dates.validate('Thursday 21 March 2017'))
예제 #2
0
    def test_convert_datetime(self):
        dt = datetime.utcnow()
        iso, _ = dt.isoformat().split('.', 1)
        self.assertEquals(dates.clean(dt), iso)
        self.assertTrue(dates.validate(iso))

        dt = datetime.utcnow().date()
        iso = dt.isoformat()
        self.assertEquals(dates.clean(dt), iso)
예제 #3
0
 def _validate(self, value):
     if not dates.validate(value):
         raise ValidationError('Invalid date: %s' % value)
예제 #4
0
 def test_is_partial_date(self):
     self.assertTrue(dates.validate('2017-04-04 10:30:29'))
     self.assertTrue(dates.validate('2017-04-04 10:30'))
     self.assertTrue(dates.validate('2017-04-04 10'))
     self.assertTrue(dates.validate('2017-04-04'))
     self.assertTrue(dates.validate('2017-4-4'))
     self.assertTrue(dates.validate('2017-4'))
     self.assertTrue(dates.validate('2017'))
     self.assertFalse(dates.validate('0017'))
     self.assertFalse(dates.validate(None))
     self.assertFalse(dates.validate(5))
     self.assertFalse(dates.validate('2017-20-01'))