# Another elementary problem... :-(

**URL:** <https://rubytalk.org/t/another-elementary-problem/3103>\
**Category:** ruby-talk\
**Created:** [27 November 2002 07:56 UTC](https://rubytalk.org/t/another-elementary-problem/3103 "2002-11-27T07:56:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ted\_Rolle](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Ted\_Rolle](https://rubytalk.org/u/Ted_Rolle)\
**Post date:** [27 November 2002 07:56 UTC](https://rubytalk.org/t/another-elementary-problem/3103/1 "2002-11-27T07:56:12Z")

</div>

Here’s the code:  
#!/usr/bin/env ruby

class S2hhmmss

def to\_hhmmss(duration)  
@duration = duration  
@t = @duration / 86400 # Number of days + fraction in interval.  
@DD = @t.to\_i # Remove fractional part of day.  
@t -= @DD # Compute fractional part of day  
@hh = @t \* 24 # Hours from fractional part of day.  
@mm = @hh-@hh.to\_i_60 # Compute minutes + fraction.  
 @ss = @mm-@mm.to\_i_60 # Compute seconds + fraction.  
printf ("%d days %02d:%02d:%02d\n",@DD,@hh,@mm,@ss)  
end

end  
dl = Time.mktime(2004,5,18,0,0,0,0.0) - Time.now  
puts dl.to\_s  
S2hhmmss.to\_hhmmss(dl)  
dl /= 86400  
puts dl.to\_i.to\_s+’ days until Teddy gets his learner’s permit!‘  
puts dl.to\_s+’ days until Teddy gets his learner’s permit!’

Here’s what happens when I run it:  
46480555.570496  
/usr/local/bin/tttdl.rb:19: undefined method `to\_hhmmss’ for S2hhmmss:Class (NoMethodError)  
46480541.596954

And… is there a more “Ruby-like” way to write it? (I don’t even know  
whether it works…)
