# Another elementary problem... :-(

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

<div class="post-metadata">

**Author:** ![Christopher\_J\_Meisen](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@Christopher\_J\_Meisen](https://rubytalk.org/u/Christopher_J_Meisen)\
**Post date:** [27 November 2002 12:53 UTC](https://rubytalk.org/t/another-elementary-problem/3115/1 "2002-11-27T12:53:21Z")

</div>

I just tried it. I get the same results, but when I run it in IRB I get:

“537.6310001 days until Teddy gets his learner’s permit!”

> **···**
>
> ####################  
> Date: Wed, 27 Nov 2002 16:56:12 +0900  
> Posted: Tue, 26 Nov 2002 23:56:06 -0800 (PST)  
> From: ted [ted@php.net](mailto:ted@php.net)  
> Reply-To: [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Subject: Another elementary problem… ☹  
> To: [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org) (ruby-talk ML)
> 
> 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…)
> 
> Christopher J. Meisenzahl CPS, CSTE  
> Senior Software Testing Consultant  
> Spherion  
> [christopher.j.meisenzahl@citicorp.com](mailto:christopher.j.meisenzahl@citicorp.com)
