Sha256: 0ba3e3c1eb2dbd8dd42db092c008103f9c2638a325fcecc4f4d6359448c9193e

Contents?: true

Size: 734 Bytes

Versions: 5

Compression:

Stored size: 734 Bytes

Contents

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

    def -(other)
      if other.is_a?(::Date) || other.is_a?(::Time)
        Interval.new(other, self, week: self.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::Date} object from a given Date object.
      # Copy constructor.
      #
      # @param date [Date]
      def from_date(date, work_week = nil)
        new_date = self.jd(date.jd)
        new_date.work_week = work_week if work_week
        new_date
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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