# Re: Modifying Time with DPrecision to work with Runt

**URL:** <https://www.ruby-forum.com/t/re-modifying-time-with-dprecision-to-work-with-runt/75375>\
**Category:** Ruby\
**Created:** [November 9, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/re-modifying-time-with-dprecision-to-work-with-runt/75375 "2006-11-09T14:36:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LipperS\_Matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8491ac/32.png) [@LipperS\_Matthew](https://www.ruby-forum.com/u/LipperS_Matthew)\
**Post date:** [November 9, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/re-modifying-time-with-dprecision-to-work-with-runt/75375/1 "2006-11-09T14:36:54Z")

</div>

> Hi there,

Hi Paul,

> 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?

None that I can think of.

> If not, would it make sense to include this in the Runt gem?

Yes, definitely. Can you please send me either a failing test case  
demonstrating the issue or give me some more details about  
‘event.created\_at’ (‘event.created\_at’ returns a Time instance, true?).

Either way I will be happy to add it.

> end

Thanks for using Runt and helping to make it better!

-Matt

---

<div class="post-metadata">

**Author:** ![LipperS\_Matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8491ac/32.png) [@LipperS\_Matthew](https://www.ruby-forum.com/u/LipperS_Matthew)\
**Post date:** [November 9, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/re-modifying-time-with-dprecision-to-work-with-runt/75375/2 "2006-11-09T22:34:33Z")

</div>

On 09/11/06, Lipper, Matthew [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 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?
> 
> None that I can think of.

Good to hear!

> > If not, would it make sense to include this in the Runt gem?
> 
> Yes, definitely. Can you please send me either a failing test case  
> demonstrating the issue or give me some more details about  
> ‘event.created\_at’ (‘event.created\_at’ returns a Time instance, true?).
> 
> Either way I will be happy to add it.

event is an ActiveRecord object and created\_at is a Time instance,  
thus trying to see if falls within a TemporalExpression doesn’t work  
as Time doesn’t have a date\_precision method.

Not sure this is exactly what you need but hopefully it gets the point  
across. If you run the code below as-is, it will raise:

NoMethodError: undefined method ‘date\_precision’ for Mon Nov 06  
07:38:00 GMT 2006:Time

However if the code modifying Time is uncommented then passing Time  
objects to still\_there? appear to work fine.

Hope it all makes sense,

Paul.

require ‘rubygems’  
require ‘runt’

# 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

class WorkingHours  
include Runt

def initialize  
monday = DIWeek.new(Mon) & REDay.new(9,30,17,30)  
tues\_to\_fri = REWeek.new(Tue, Fri) & REDay.new(9,00,17,30)  
@runt\_exp = monday | tues\_to\_fri  
end

def still\_there?(time)  
@runt\_exp.include? time  
end

end

stuck\_at\_work = WorkingHours.new

in\_the\_land\_of\_nod = Time.parse(‘Monday 06 November 2006 07:38’)  
a\_case\_of\_the\_mondays = Time.parse(‘Monday 06 November 2006 13:37’)  
clock\_watching = Time.parse(‘Friday 10 November 2006 16:59’)  
down\_the\_pub = Time.parse(‘Friday 10 November 2006 17:31’)

p stuck\_at\_work.still\_there?( in\_the\_land\_of\_nod ) #=\> false  
p stuck\_at\_work.still\_there?( a\_case\_of\_the\_mondays ) #=\> true  
p stuck\_at\_work.still\_there?( clock\_watching ) #=\> true  
p stuck\_at\_work.still\_there?( down\_the\_pub ) #=\> false
