-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
business_time_until and ActiveSupport::TimeWithZone #50
Comments
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. |
thanks for your feedback. ticket_resolved_in = ticket_reported.created_at.business_time_until(ticket_resolved.created_at) |
i am not getting the results you are getting in your example above. You say that: 5.hours.ago.class => ActiveSupport::TimeWithZonebut I see:
Further, the example you provide works for me:
What version of ActiveSupport are you using? These results are consistent for me with both activesupport 3.2.13 and 4.0.0. |
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... |
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. |
@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! |
@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] |
I'm experiencing some issues here as well. Here is an interesting failing test case:
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! |
Hello,
Assuming
current issue is :
So 5 hours - 1 hours = 4 hours, the correct result is :
So why these 2 results are different ?
Basically the main difference is the class used when dealing with business_time_until Time vs ActiveSupport::TimeWithZone
https://github.com/bokmann/business_time/blob/master/lib/business_time/core_ext/time.rb#L100 when using an ActiveSupport::TimeWithZone, it is converted to Time without converting using timezone properly.
I know that business_time is timezone agnostic, but using rails .ago, .from_now helpers are pretty convenient.
Any feedback is appreciated :) !
The text was updated successfully, but these errors were encountered: