F219245be3a984ebe2b754c64866551f

I have a time in second and a Hash with seconds minutes and hours.
I'm sure you have some pretty tricks

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 !

880cbab435f00197613c9cc2065b4f5a

danielharan

June 11, 2008, June 11, 2008 21:44, permalink

1 rating. Login to rate!

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
F219245be3a984ebe2b754c64866551f

kyzh

June 11, 2008, June 11, 2008 23:42, permalink

No rating. Login to rate!

I got a "xx:xx:xx", I add some second to it and then write it back.
So I don't found Time very usefull.
a atime.hms could be nice

I use this piece of code to modify a .srt to syncronise it with a video when it needs the knife :)

Your refactoring





Format Copy from initial code

or Cancel