Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/gb_work_day/core_ext/time.rb

Direct Known Subclasses

GBWorkDay::Time

Instance Method Summary collapse

Instance Method Details

#free?(week = default_week) ⇒ boolean

Check if it is a work day.

Returns:

  • (boolean)


35
36
37
# File 'lib/gb_work_day/core_ext/time.rb', line 35

def free?(week = default_week)
  week.free_day? self
end

#minus_with_work_duration(other) ⇒ Object Also known as: -



14
15
16
17
18
19
20
21
22
# File 'lib/gb_work_day/core_ext/time.rb', line 14

def minus_with_work_duration(other)
  if GBWorkDay::Duration === other
    plus_with_work_duration(-other)
  elsif GBWorkDay::Time === other
    - (other - self)
  else
    minus_without_work_duration(other)
  end
end

#next_work_day(week = default_week) ⇒ Time

Return next working day

Returns:



41
42
43
44
45
46
47
# File 'lib/gb_work_day/core_ext/time.rb', line 41

def next_work_day(week = default_week)
  if week.free_day? self
    self.beginning_of_week + 7.days
  else
    self + GBWorkDay::Duration.new(1, week)
  end
end

#plus_with_work_duration(other) ⇒ Object Also known as: +



4
5
6
7
8
9
10
# File 'lib/gb_work_day/core_ext/time.rb', line 4

def plus_with_work_duration(other)
  if GBWorkDay::Duration === other
    other.since(self)
  else
    plus_without_work_duration(other)
  end
end

#previous_work_day(week = default_week) ⇒ Time

Return previous working day

Returns:



51
52
53
54
55
56
57
# File 'lib/gb_work_day/core_ext/time.rb', line 51

def previous_work_day(week = default_week)
  if week.free_day? self
    next_work_day(week) - (week.free_days_per_week + 1).days
  else
    self - GBWorkDay::Duration.new(1, week)
  end
end

#work?(week = default_week) ⇒ boolean

Check if it is a work day.

Returns:

  • (boolean)


29
30
31
# File 'lib/gb_work_day/core_ext/time.rb', line 29

def work?(week = default_week)
  week.work_day? self
end

#work_time(week = nil) ⇒ Object Also known as: to_work, to_work_time

Get time object for calculating working days

Parameters:

  • week (GBWorkDay::WorkWeek) (defaults to: nil)

    if not set, it will use week set globally. For more check GBWorkingDay::WorkWeek#current



62
63
64
# File 'lib/gb_work_day/core_ext/time.rb', line 62

def work_time(week = nil)
  GBWorkDay::Time.from_time self, week
end