Re: Modifying Time with DPrecision to work with Runt

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

On 09/11/06, Lipper, Matthew [email protected] 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