fix: Update timezone to get wday
from working_hours (#5605)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
parent
1b5a335f93
commit
fca629a32a
4 changed files with 20 additions and 1 deletions
|
@ -40,7 +40,10 @@ class WorkingHour < ApplicationRecord
|
||||||
validate :open_all_day_and_closed_all_day
|
validate :open_all_day_and_closed_all_day
|
||||||
|
|
||||||
def self.today
|
def self.today
|
||||||
find_by(day_of_week: Date.current.wday)
|
# While getting the day of the week, consider the timezone as well. `first` would
|
||||||
|
# return the first working hour from the list of working hours available per week.
|
||||||
|
inbox = first.inbox
|
||||||
|
find_by(day_of_week: Time.zone.now.in_time_zone(inbox.timezone).to_date.wday)
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_at?(time)
|
def open_at?(time)
|
||||||
|
|
|
@ -88,4 +88,18 @@ RSpec.describe WorkingHour do
|
||||||
'Validation failed: open_all_day and closed_all_day cannot be true at the same time')
|
'Validation failed: open_all_day and closed_all_day cannot be true at the same time')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when on monday 9am in Sydney timezone' do
|
||||||
|
let(:inbox) { create(:inbox) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Time.zone = 'Australia/Sydney'
|
||||||
|
inbox.update(timezone: 'Australia/Sydney')
|
||||||
|
travel_to '10.10.2022 9:00 AEDT'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is considered working hour' do
|
||||||
|
expect(described_class.today.open_now?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -167,6 +167,7 @@ describe ::Contacts::FilterService do
|
||||||
|
|
||||||
context 'with x_days_before filter' do
|
context 'with x_days_before filter' do
|
||||||
before do
|
before do
|
||||||
|
Time.zone = 'UTC'
|
||||||
el_contact.update(last_activity_at: (Time.zone.today - 4.days))
|
el_contact.update(last_activity_at: (Time.zone.today - 4.days))
|
||||||
cs_contact.update(last_activity_at: (Time.zone.today - 5.days))
|
cs_contact.update(last_activity_at: (Time.zone.today - 5.days))
|
||||||
en_contact.update(last_activity_at: (Time.zone.today - 2.days))
|
en_contact.update(last_activity_at: (Time.zone.today - 2.days))
|
||||||
|
|
|
@ -309,6 +309,7 @@ describe ::Conversations::FilterService do
|
||||||
|
|
||||||
context 'with x_days_before filter' do
|
context 'with x_days_before filter' do
|
||||||
before do
|
before do
|
||||||
|
Time.zone = 'UTC'
|
||||||
en_conversation_1.update!(last_activity_at: (Time.zone.today - 4.days))
|
en_conversation_1.update!(last_activity_at: (Time.zone.today - 4.days))
|
||||||
en_conversation_2.update!(last_activity_at: (Time.zone.today - 5.days))
|
en_conversation_2.update!(last_activity_at: (Time.zone.today - 5.days))
|
||||||
user_2_assigned_conversation.update!(last_activity_at: (Time.zone.today - 2.days))
|
user_2_assigned_conversation.update!(last_activity_at: (Time.zone.today - 2.days))
|
||||||
|
|
Loading…
Reference in a new issue