Sha256: a7ead602dc429fc140b4f4720116dce0d543248795294c955c4e6bbdf06054d7

Contents?: true

Size: 819 Bytes

Versions: 9

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

module Qismo
  class Util
    class << self
      def in_office_hour?(data)
        return false if data.timezone.blank?

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

        today_office_hour = data.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

        start_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{start_hour} #{data.timezone}")
        end_time = Time.parse("#{tz_current.year}-#{tz_current.month}-#{tz_current.day} #{end_hour} #{data.timezone}")

        tz_current.between?(start_time, end_time)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
qismo-0.8.6 lib/qismo/util.rb
qismo-0.8.5 lib/qismo/util.rb
qismo-0.8.4 lib/qismo/util.rb
qismo-0.8.3 lib/qismo/util.rb
qismo-0.8.2 lib/qismo/util.rb
qismo-0.8.1 lib/qismo/util.rb
qismo-0.8.0 lib/qismo/util.rb
qismo-0.7.1 lib/qismo/util.rb
qismo-0.7.0 lib/qismo/util.rb