# Modifying Time with DPrecision to work with Runt

**URL:** <https://www.ruby-forum.com/t/modifying-time-with-dprecision-to-work-with-runt/75088>\
**Category:** Ruby\
**Created:** [November 7, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/modifying-time-with-dprecision-to-work-with-runt/75088 "2006-11-07T13:37:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pozza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e8cbc/32.png) [@pozza](https://www.ruby-forum.com/u/pozza)\
**Post date:** [November 7, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/modifying-time-with-dprecision-to-work-with-runt/75088/1 "2006-11-07T13:37:38Z")

</div>

Hi there,

I’m currently trying out Runt for a project at work where we want to  
work out the number of ‘business’ hours that have occurred between two  
dates. Using Runt I’ve found this super easy to express the working  
hours but I’ve noticed there’s a bit of a performance hit to using  
DateTime instead of Time. To start with I was using the following:

working\_hours\_expr = DIWeek.new(Mon) & REDay.new(9,30,17,30)) |  
(REWeek.new(Tue, Fri) & REDay.new(9,00,17,30)  
working\_hours\_expr.include?( DateTime.parse(event.created\_at.to\_s) )

If I tried to pass event.created\_at straight into include?() it would  
error with “undefined method `date\_precision’ for Tue Nov 07 11:12:34  
GMT 2006:Time (NoMethodError)”. I added the code below (which is  
pretty much identical to the DateTime modification included with Runt)  
and now it works (plus it’s a lot faster), but I’m wondering if  
there’s any unintended consequences I should be looking out for? If  
not, would it make sense to include this in the Runt gem?

class Time  
include Runt::DPrecision

attr\_accessor :date\_precision

def date\_precision  
return @date\_precision unless @date\_precision.nil?  
return Runt::DPrecision::DEFAULT  
end  
end

(Also, if anyone knows of a better way to work out how many business  
hours have elapsed between two dates other than fast-forwarding  
through the start and finish times whilst counting time within the  
range I’m all ears.)

Cheers

Paul.
