Giter Club home page Giter Club logo

Comments (8)

bokmann avatar bokmann commented on June 9, 2024

TimeZones are painful. I think the bug you are showing is not due to BusinessTime, but due to mixing Time and TimeWithZone, which would happen in any rails app that happened to mix those two classes.

I'm not a fan of the business_time_until method; I tend to do these things by calculating the 'due date', as in:

due_at = 12.business_hours.from_now

and then doing a test based on a new business_time object... for instance, if something is considered 'urgent' if there are less than 4 hours left, I prefer to do:

urgent = 4.business_hours.from_now > due_at

I think that embodies the requirement better than:

urgent = Time.now.business_hours_until(due_at) < 4

and it doesn't require an extra method and the extra logic that accompanies it. Its why I originally didn't include this method.

Does this line of reasoning help with your immediate issue?

I'll decide this weekend if this is a bug for us to deal with or simply a gotcha to add to the documentation.

from business_time.

sbounmy avatar sbounmy commented on June 9, 2024

thanks for your feedback.
my main issue is when dealing with datetime fields which returns TimeWithZone :

ticket_resolved_in = ticket_reported.created_at.business_time_until(ticket_resolved.created_at)

from business_time.

bokmann avatar bokmann commented on June 9, 2024

i am not getting the results you are getting in your example above.

You say that:

5.hours.ago.class

=> ActiveSupport::TimeWithZone

but I see:

5.hours.ago.class
=> Time

Further, the example you provide works for me:

5.hours.ago.business_time_until 1.hours.ago
=> 7444.091564
5.hours.ago.to_time.business_time_until 1.hours.ago.to_time
=> 7449.364577

What version of ActiveSupport are you using? These results are consistent for me with both activesupport 3.2.13 and 4.0.0.

from business_time.

sbounmy avatar sbounmy commented on June 9, 2024

Hm this is really weird, I am using rails 3.2.13.

5.hours.ago.ancestors
# => [ActiveSupport::TimeWithZone, Mongoid::Extensions::TimeWithZone, Origin::Extensions::TimeWithZone, Comparable, Object, Sinatra::Delegator, V8::Conversion::Object, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable, Mongoid::Extensions::Object, Moped::BSON::Extensions::Object, Origin::Extensions::Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]

Might come from some mixin...

from business_time.

bokmann avatar bokmann commented on June 9, 2024

Are you copying and pasting directly from your console? In your first example, you obviously didn't, because the response you pasted was from 5.hours.ago.to_time.class, but your method called was just 5.hours.ago.to_time.

From your most recent example, I think you mean

5.hours.ago.class.ancestors

to which my console replies:

[Time, DateAndTime::Calculations, Comparable, Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]

TimeZones are difficult. Something else in your ancestor chain is causing this problem.

from business_time.

sbounmy avatar sbounmy commented on June 9, 2024

@bokmann yes first example is a typo, my bad.

5.hours.ago.class.ancestors
# => [ActiveSupport::TimeWithZone, Mongoid::Extensions::TimeWithZone, Origin::Extensions::TimeWithZone, Comparable, Object, Sinatra::Delegator, V8::Conversion::Object, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable, Mongoid::Extensions::Object, Moped::BSON::Extensions::Object, Origin::Extensions::Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]

Thanks for taking time to investigate. I will give update once I find out something in case similar ppl encounter this issue!

from business_time.

sbounmy avatar sbounmy commented on June 9, 2024

@bokmann what version of ruby you are using ?

with a freshly bootstrapped rails 4 project I still have

5.hours.ago.class
=> ActiveSupport::TimeWithZone
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]

from business_time.

barmstrong avatar barmstrong commented on June 9, 2024

I'm experiencing some issues here as well. Here is an interesting failing test case:

irb(main):008:0> DateTime.now.business_days_until(1.business_days.from_now)
=> 1
irb(main):007:0> DateTime.now.business_days_until(2.business_days.from_now)
=> 3
irb(main):009:0> DateTime.now.business_days_until(3.business_days.from_now)
=> 4
irb(main):010:0> DateTime.now
=> Thu, 07 Nov 2013 17:09:19 -0800

Monday is a holiday, which the second and third examples overlap with. I'm using the https://github.com/alexdunae/holidays gem.

Does this spark any ideas? Thanks!

from business_time.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.