Sha256: 02e002089ea1d715a3b8e1174ac67c8368b2e6a87bb83ddc1931931f9d042d6d

Contents?: true

Size: 724 Bytes

Versions: 6

Compression:

Stored size: 724 Bytes

Contents

require 'gb_work_day/interval'
module GBWorkDay
  class Time < ::Time
    attr_accessor :work_week

    def -(other)
      if other.is_a?(::Time) || other.is_a?(::Date)
        Interval.new(self, other, week: work_week).work_days
      else
        super
      end
    end

    private

    # @return [GBWorkDay::WorkWeek]
    def default_week
      self.work_week || GBWorkDay::WorkWeek.current
    end

    class << self
      # Create {GBWorkingDay::Time} object from a given Time object.
      # Copy constructor.
      #
      # @param time [Time]
      def from_time(time, work_week=nil)
        new_time = self.at(time)
        new_time.work_week = work_week if work_week
        new_time
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gb_work_day-0.1.0 lib/gb_work_day/helpers/time.rb
gb_work_day-0.0.6 lib/gb_work_day/helpers/time.rb
gb_work_day-0.0.4 lib/gb_work_day/helpers/time.rb
gb_work_day-0.0.3 lib/gb_work_day/helpers/time.rb
gb_work_day-0.0.2 lib/gb_work_day/helpers/time.rb
gb_work_day-0.0.1 lib/gb_work_day/helpers/time.rb