class TimeBoss::Calendar::Week

Public Class Methods

new(calendar, start_date, end_date) click to toggle source
Calls superclass method TimeBoss::Calendar::Support::Unit::new
# File lib/timeboss/calendar/week.rb, line 8
def initialize(calendar, start_date, end_date)
  raise UnsupportedUnitError unless calendar.supports_weeks?
  super(calendar, start_date, end_date)
end

Public Instance Methods

index() click to toggle source

Get the index of this week within its containing year. @return [Integer]

# File lib/timeboss/calendar/week.rb, line 33
def index
  @_index ||= (((start_date - year.start_date) + 1) / 7.0).to_i + 1
end
name() click to toggle source

Get a simple representation of this week. @return [String] (e.g. “2020W32”)

# File lib/timeboss/calendar/week.rb, line 15
def name
  "#{year_index}W#{index}"
end
title() click to toggle source

Get a “pretty” representation of this week. @return [String] (e.g. “Week of August 3, 2020”)

# File lib/timeboss/calendar/week.rb, line 21
def title
  "Week of #{start_date.strftime("%B %-d, %Y")}"
end
to_s() click to toggle source

Get a stringified representation of this week. @return [String] (e.g. “2020W32: 2020-08-03 thru 2020-08-09”)

# File lib/timeboss/calendar/week.rb, line 27
def to_s
  "#{name}: #{start_date} thru #{end_date}"
end
year_index() click to toggle source

Get the year number for this week. @return [Integer] (e.g. 2020)

# File lib/timeboss/calendar/week.rb, line 39
def year_index
  @_year_index ||= year.year_index
end

Private Instance Methods

down() click to toggle source
# File lib/timeboss/calendar/week.rb, line 45
def down
  self.class.new(calendar, start_date - 1.week, end_date - 1.week)
end
up() click to toggle source
# File lib/timeboss/calendar/week.rb, line 49
def up
  self.class.new(calendar, start_date + 1.week, end_date + 1.week)
end