def sec_to_time(sec) t = Hash.new a_sec = sec.divmod(60) s = a_sec[1] a_min = a_sec[0].divmod(60) m = a_min[1] a_h = a_min[0].divmod(24) h = a_h[1] t["secondes"],t["minutes"],t["heures"]= s,m,h return t end def time_to_sec(t) sec = t["secondes"] + (t["minutes"] * 60) + (t["heures"] * 60 * 60) return sec end
Refactorings
No refactoring yet !
danielharan
June 11, 2008, June 11, 2008 21:44, permalink
Why not just use Time ?
>> start = Time.at 0 => Wed Dec 31 19:00:00 -0500 1969 >> later = start + 60 * 60 * 2 + 60 * 3 + 1 # add 2 hours, 3 minutes and 1 second => Wed Dec 31 21:01:01 -0500 1969 >> later.hour - start.hour => 2 >> later.min - start.min => 3 >> later.sec - start.sec => 1
I have a time in second and a Hash with seconds minutes and hours.
I'm sure you have some pretty tricks