Skip to content

business_time_until and ActiveSupport::TimeWithZone #50

@sbounmy

Description

@sbounmy

Hello,

Assuming

  • we are in a full working day (00:00:00-23:59:59)
  • Time.zone = 'Paris'

current issue is :

5.hours.ago.business_time_until 1.hours.ago
# => 7200.00005698204 // 2 hours
5.hours.ago.to_time.business_time_until 1.hours.ago.to_time
# => 14400.000063 // 4 hours

So 5 hours - 1 hours = 4 hours, the correct result is :

5.hours.ago.to_time.business_time_until 1.hours.ago.to_time

So why these 2 results are different ?

5.hours.ago.class
# => ActiveSupport::TimeWithZone
5.hours.ago.to_time
# => Time

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 :) !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions