Skip to content

Instantly share code, notes, and snippets.

@patrikjohansson
Created May 10, 2012 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrikjohansson/2652025 to your computer and use it in GitHub Desktop.
Save patrikjohansson/2652025 to your computer and use it in GitHub Desktop.
# encoding: UTF-8
module StringToDatetimeForSoap
def to_datetime
begin
if /^([+\-]?\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ self.strip
return Time.xmlschema(self).localtime
end
super
rescue
# If a invalid date is supplied, it will automatically turn it into the first Julian Day
# Jan/01 - 4712 BC - This is a simple solution, until a better one appear :)
return Date.new
end
end
end
String.send :include, StringToDatetimeForSoap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment