Ejemplo n.º 1
0
 def is_definitely(self, obj: Any) -> bool:
     if isinstance(obj, str) and 14 <= len(obj) <= 26:
         if is_numberish(obj):
             # Numbers aren't dates!
             return False
         try:
             parser.isoparse(obj)
             return True
         except (parser.ParserError, TypeError, ValueError):
             pass
         return False
     else:
         return isinstance(obj, datetime)
Ejemplo n.º 2
0
 def is_maybe(self, obj: Any) -> bool:
     if isinstance(obj, time):
         return True
     if is_numberish(obj):
         # Numbers aren't times!
         return False
     if not isinstance(obj, str):
         obj = str(obj)
     try:
         # We use ancient date as default to detect when only time was found
         # Will fail if trying to parse actual ancient dates!
         dt = parser.parse(obj, default=datetime(1, 1, 1))
         if dt.year < 2:
             # dateutil parser found just a time
             return True
     except Exception:
         return False
     return False
Ejemplo n.º 3
0
 def is_maybe(self, obj: Any) -> bool:
     if isinstance(obj, datetime):
         return True
     if isinstance(obj, time):
         return False
     if is_numberish(obj):
         # Numbers aren't datetimes!
         return False
     if not isinstance(obj, str):
         obj = str(obj)
     try:
         dt = parser.parse(obj, default=datetime(1, 1, 1))
         if dt.year < 2:
             # dateutil parser only found a time, not a date
             return False
     except (parser.ParserError, TypeError, ValueError):
         return False
     return True