Created
January 10, 2012 00:22
-
-
Save mattfitzgerald/1585903 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 convert_time_safely time_input | |
begin | |
return nil if time_input.to_i == 0 | |
Time.at(time_input.to_i/1000) | |
rescue | |
return nil | |
end | |
end | |
puts "10000 -> #{convert_time_safely(10000)}" | |
puts "'10000' -> #{convert_time_safely('10000')}" | |
puts "nil -> #{convert_time_safely(nil)}" | |
puts "overflow -> #{convert_time_safely("999999999999999999999999999999")}" | |
puts "Time.now -> #{Time.now}" | |
puts "Time.now.to_s -> #{convert_time_safely(Time.now.to_s)}" | |
puts "Time.now.to_s -> #{convert_time_safely(Time.now.to_s)}" | |
puts "'Tuesday January 10 11:19:39' -> #{convert_time_safely('Tuesday January 10 11:19:39')}" | |
=begin | |
10000 -> Thu Jan 01 10:00:10 +1000 1970 | |
'10000' -> Thu Jan 01 10:00:10 +1000 1970 | |
nil -> | |
overflow -> | |
Time.now -> Tue Jan 10 11:21:10 +1100 2012 | |
Time.now.to_s -> | |
Time.now.to_s -> | |
'Tuesday January 10 11:19:39' -> | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment