Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- iso_regex = re.compile(
- '([0-9]{4})' #year
- '-?'
- '([0-9]{1,2})' #month
- '(?:'
- '-?'
- '('
- '[0-9]{1,2}' #day?
- ')'
- '(?:'
- '[T ]'
- '([0-9]{1,2})' #hour??
- '(?:'
- ':?'
- '([0-9]{1,2})' #minute???
- '(?:'
- ':?'
- '(?:'
- '([0-9]{1,2})' #second????
- '(?:'
- '\\.?([0-9]+)' #ms?????
- ')?'
- ')'
- ')?'
- '(?:'
- '(Z)|([+-][0-9]{1,2})' #
- ':?'
- '([0-9]{1,2})' #TZ???
- ')'
- ')?'
- ')?'
- ')?'
- )
- def regex_parse_datetime(s):
- match = iso_regex.match(s)
- if not match:
- return
- groups = list(itertools.takewhile(lambda e: e is not None, match.groups()))
- args = [int(g) for g in groups[:7]]
- # No tzinfo
- return datetime.datetime(*args)
Advertisement
Add Comment
Please, Sign In to add comment