Skip to content

Instantly share code, notes, and snippets.

@hannestyden
Last active August 29, 2015 13:56
Show Gist options
  • Save hannestyden/9088250 to your computer and use it in GitHub Desktop.
Save hannestyden/9088250 to your computer and use it in GitHub Desktop.
# http://rubular.com/r/UMTb5KhY8A
DATE=/\d{4}-\d{2}-\d{2}/
ZONE=/Z|[-+]\d{2}(?::\d{2})?/
TIME=/\d{2}(?::\d{2}(?::\d{2}(?:\.\d+)?)?)?/
TIME_WITH_ZONE=/#{TIME}(?:#{ZONE})?/
ISO8601_FORMAT=/^(#{DATE})(?:T(#{TIME_WITH_ZONE}))?$/
ISO8601_FORMAT.match('2008-08-30T01:45:36.100Z') # => #<MatchData "2008-08-30T01:45:36.100Z" 1:"2008-08-30" 2:"01:45:36.100Z">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment