Created
May 10, 2012 09:06
-
-
Save patrikjohansson/2652025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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