Ejemplo n.º 1
0
def validate_time_tenths(v):
    if isinstance(v, list):
        return [validate_time_tenths(x) for x in v]
    elif isinstance(v, datetime):
        if v.tzname():
            v = v.astimezone(tz=timezone.utc).replace(tzinfo=None)
        return '{}.0Z'.format(validators.validate_time(v)[0:-1])
    else:
        return validators.validate_time(v)
 def test_validate_time_invalid_str_with_timezone(self):
     validated = validate_time('20170317094232+24')
     self.assertFalse(validated)
 def test_validate_time_invalid_str_2(self):
     validated = validate_time('20170317254201Z')
     self.assertFalse(validated)
 def test_validate_time_invalid_str_1(self):
     validated = validate_time('abc')
     self.assertFalse(validated)
 def test_validate_time_valid_str_with_timezone(self):
     validated = validate_time('20170317094232+0100')
     self.assertTrue(validated)
 def test_validate_time_valid_str(self):
     validated = validate_time('20170317094232Z')
     self.assertTrue(validated)
 def test_validate_time_valid_datetime_with_timezone(self):
     validated = validate_time(datetime.now(OffsetTzInfo(0, 'UTC')))
     self.assertTrue(validated)
 def test_validate_time_valid_datetime(self):
     validated = validate_time(datetime.now())
     self.assertTrue(validated)