Dear all
Is there any existing function in rails to calculate time? I have google it but no information found..
For example a = "2009-07-16 12:34".to_time b = "2009-07-16 12:04".to_time some_method(a,b) return "30 mins ago"
c = "2009-07-16 12:34".to_time d = "2009-07-12 09:09".to_time some_method(c,d) return "4 days ago"
If not, I will write it by my own. But it can save my time if there is existing method to do so...
Have a look at the documentation for the Time class. You can just subtract the times.
a = "2009-07-16 12:34".to_time
=> Thu Jul 16 12:34:00 UTC 2009
b = "2009-07-16 12:04".to_time
=> Thu Jul 16 12:04:00 UTC 2009
diff = a-b
=> 1800.0 # 30 mins in seconds
Colin