You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			18 lines
		
	
	
		
			555 B
		
	
	
	
		
			Python
		
	
			
		
		
	
	
			18 lines
		
	
	
		
			555 B
		
	
	
	
		
			Python
		
	
| import datetime
 | |
| import dateutil
 | |
| from apistar.typesystem import TypeSystemError
 | |
| 
 | |
| 
 | |
| class Datetime(datetime.datetime):
 | |
|     native_type = datetime.datetime
 | |
| 
 | |
|     def __new__(cls, *args, **kwargs) -> datetime:
 | |
|         if args and isinstance(args[0], cls.native_type):
 | |
|             return args[0]
 | |
|         if args and isinstance(args[0], str):
 | |
|             try:
 | |
|                 return dateutil.parser.parse(args[0])
 | |
|             except ValueError:
 | |
|                 raise TypeSystemError(cls=cls, code='type') from None
 | |
|         return cls.native_type(*args, **kwargs)
 |