Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Modifying Time with DPrecision to work with Runt

Reply
Thread Tools

Modifying Time with DPrecision to work with Runt

 
 
Paul Wright
Guest
Posts: n/a
 
      11-07-2006
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:Precision

attr_accessor :date_precision

def date_precision
return @date_precision unless @date_precision.nil?
return Runt:Precision:EFAULT
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I find overlaps between two Ruby Runt patterns? Amit Rawal Ruby 0 06-23-2009 07:50 AM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
runt and jabber Shane NZ Computing 8 08-29-2006 09:13 AM
How to add multiple items to Item template col of datagrid at runt Abhishek ASP .Net Web Controls 0 03-24-2006 08:32 AM
Runt: Matching the year Pat Maddox Ruby 0 12-14-2005 09:16 AM



Advertisments