Class: Qismo::Objects::OfficeHour

Inherits:
Qismo::Object show all
Defined in:
lib/qismo/objects/office_hour.rb

Overview

Office hour object

Defined Under Namespace

Classes: OfficeHourElement

Constant Summary

Constants included from Types

Types::Bool, Types::Hash, Types::Int, Types::String

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Qismo::Object

from_array

Instance Attribute Details

#office_hoursArray<Qismo::Objects::OfficeHour::OfficeHourElement> (readonly)



44
# File 'lib/qismo/objects/office_hour.rb', line 44

attribute? :office_hours, Types.Array(OfficeHourElement.optional).optional

#offline_messageString (readonly)

Returns:



28
# File 'lib/qismo/objects/office_hour.rb', line 28

attribute? :offline_message, Types::String.optional

#online_messageString (readonly)

Returns:



24
# File 'lib/qismo/objects/office_hour.rb', line 24

attribute? :online_message, Types::String.optional

#send_offline_each_messageTrueClass, FalseClass (readonly)

Returns:

  • (TrueClass, FalseClass)


40
# File 'lib/qismo/objects/office_hour.rb', line 40

attribute? :send_offline_each_message, Types::Bool.optional

#send_online_if_resolvedTrueClass, FalseClass (readonly)

Returns:

  • (TrueClass, FalseClass)


36
# File 'lib/qismo/objects/office_hour.rb', line 36

attribute? :send_online_if_resolved, Types::Bool.optional

#timezoneString (readonly)

Returns:



32
# File 'lib/qismo/objects/office_hour.rb', line 32

attribute? :timezone, Types::String.optional

Instance Method Details

#in_office_hour?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/qismo/objects/office_hour.rb', line 46

def in_office_hour?
  return false if timezone.blank?

  offset = ::Time.zone_offset(timezone)
  tz_current = ::Time.current.getlocal(offset)

  today_office_hour = office_hours.find { |oh| oh.day == tz_current.strftime("%u").to_i }
  return false if today_office_hour.nil?

  start_hour = today_office_hour.starttime
  end_hour = today_office_hour.endtime

  # rubocop:disable Layout/LineLength
  start_time = ::Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{start_hour} #{timezone}")
  end_time = ::Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{end_hour} #{timezone}")
  # rubocop:enable Layout/LineLength

  tz_current.between?(start_time, end_time)
end