Module: WorkingHours::CoreExt::DateAndTime

Included in:
ActiveSupport::TimeWithZone, Date, Time
Defined in:
lib/working_hours/core_ext/date_and_time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/working_hours/core_ext/date_and_time.rb', line 8

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

Instance Method Details

#in_working_hours?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/working_hours/core_ext/date_and_time.rb', line 45

def in_working_hours?
  WorkingHours.in_working_hours?(self)
end

#minus_with_working_hours(other) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/working_hours/core_ext/date_and_time.rb', line 25

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

#plus_with_working_hours(other) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/working_hours/core_ext/date_and_time.rb', line 17

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

#working_day?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/working_hours/core_ext/date_and_time.rb', line 41

def working_day?
  WorkingHours.working_day?(self)
end

#working_days_until(other) ⇒ Object



33
34
35
# File 'lib/working_hours/core_ext/date_and_time.rb', line 33

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

#working_time_until(other) ⇒ Object



37
38
39
# File 'lib/working_hours/core_ext/date_and_time.rb', line 37

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