Sha256: 060c389a390890098cf8693f886d30a0b18fa90d9059b397444a93e1c72b221d

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'active_support/time_with_zone'
require 'working_hours/module'

module WorkingHours
  module CoreExt
    module DateAndTime

      def self.included base
        base.class_eval do
          alias_method :minus_without_working_hours, :-
          alias_method :-, :minus_with_working_hours
          alias_method :plus_without_working_hours, :+
          alias_method :+, :plus_with_working_hours
        end
      end

      def plus_with_working_hours(other)
        if WorkingHours::Duration === other
          other.since(self)
        else
          plus_without_working_hours(other)
        end
      end

      def minus_with_working_hours(other)
        if WorkingHours::Duration === other
          other.until(self)
        else
          minus_without_working_hours(other)
        end
      end

      def working_days_until(other)
        WorkingHours.working_days_between(self, other)
      end

      def working_time_until(other)
        WorkingHours.working_time_between(self, other)
      end

      def working_day?
        WorkingHours.working_day?(self)
      end

      def in_working_hours?
        WorkingHours.in_working_hours?(self)
      end
    end
  end
end

class Date
  include WorkingHours::CoreExt::DateAndTime
end

class DateTime
  include WorkingHours::CoreExt::DateAndTime
end

class Time
  include WorkingHours::CoreExt::DateAndTime
end

class ActiveSupport::TimeWithZone
  include WorkingHours::CoreExt::DateAndTime
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
working_hours-1.0.3 lib/working_hours/core_ext/date_and_time.rb
working_hours-1.0.2 lib/working_hours/core_ext/date_and_time.rb