Created
September 8, 2011 17:21
-
-
Save hamannp/1203986 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
def parse_date(date) | |
begin | |
if date_in_numeric_format? date | |
Time.new (date / 1e6).to_int | |
else | |
DateTime.parse date | |
end | |
rescue => e | |
puts e.to_s + " " + date.to_s + " class: " + date.class.to_s | |
end | |
end | |
def is_i? str | |
!!( str =~ /^[-+]?[0-9]+$/) | |
end | |
def date_in_numeric_format? date | |
return true if date.is_a?(Fixnum) | |
return true if date.is_a?(Integer) | |
return true if is_i?(date) | |
false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment