Sha256: fb7b7ca1f408f7b09b471476b3b64c4a7d823e4c36c90bdf7bb7dbdb8b4df280

Contents?: true

Size: 556 Bytes

Versions: 5

Compression:

Stored size: 556 Bytes

Contents

require "time"

module WB
  class Day
    def self.working?
      now = Time.now
      date = now.strftime("%Y-%m-%d")
      from, to = WB.config.working_hours
      start_time = TimeUtils.get_beginning_of(from, within: date)
      end_time = TimeUtils.get_end_of(to, within: date)

      now.between?(start_time, end_time)
    end
  end

  class TimeUtils
    def self.get_beginning_of(hour, within:)
      Time.parse("#{within} #{hour}:00:00")
    end

    def self.get_end_of(hour, within:)
      Time.parse("#{within} #{hour}:59:59")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wb-1.1.0 lib/wb/day.rb
wb-1.0.3 lib/wb/day.rb
wb-1.0.2 lib/wb/day.rb
wb-1.0.1 lib/wb/day.rb
wb-1.0.0 lib/wb/day.rb