Comments (8)
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.
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.
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.
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.
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.
@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.
@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.
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)
- business_time_until doesn't account for holidays when called on Time objects HOT 1
- initiate business_time instead of global definitions HOT 3
- Short days before holiday HOT 1
- Still finding problems next business day for mondays HOT 3
- factory time vs. office time HOT 2
- Business day calculation wrong for weekends HOT 1
- Request for API for 'next business Friday' etc
- Wrong Result or unexpected not-business day ? HOT 1
- Business day calculations off when starting with a non-workday HOT 1
- business_days.after weird behaviour when not in workday and out of business hours. HOT 2
- Support Ruby 3.0.0 HOT 2
- No CHANGELOG for newer versions HOT 1
- [Bug] business_days.after inconsistencies HOT 3
- during_business_hours? returning nil since 0.10.0 HOT 3
- [Bug] Concurrency issues HOT 6
- rubocop-users: Rubocop-rails autocorrection mistake
- Support Time gem version >= 0.2.0 HOT 1
- Consider dropping external deps: sorted_set and rbtree dependencies? HOT 4
- The method from_now of Class: BusinessTime::BusinessDays returns different results under the same context HOT 6
- Allow business hours that cross midnight HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from business_time.