Module: MerchCalendar::Util

Included in:
MerchCalendar
Defined in:
lib/merch_calendar/util.rb

Overview

Utility methods for the merch calendar

Instance Method Summary collapse

Instance Method Details

#end_of_month(year, month_param) ⇒ Date

The end date of the month



60
61
62
63
# File 'lib/merch_calendar/util.rb', line 60

def end_of_month(year, month_param)
  merch_month = get_merch_month_param(month_param)
  retail_calendar.end_of_month(year, merch_month)
end

#end_of_quarter(year, quarter) ⇒ Date

The end date of the quarter



100
101
102
# File 'lib/merch_calendar/util.rb', line 100

def end_of_quarter(year, quarter)
  fiscal_year_calendar.end_of_quarter(year + 1, quarter)
end

#end_of_week(year, month, week) ⇒ Date

The end date of the week



27
28
29
# File 'lib/merch_calendar/util.rb', line 27

def end_of_week(year, month, week)
  retail_calendar.end_of_week(year, julian_to_merch(month), week)
end

#end_of_year(year) ⇒ Date

The end date of the year



79
80
81
# File 'lib/merch_calendar/util.rb', line 79

def end_of_year(year)
  retail_calendar.end_of_year(year)
end

#julian_to_merch(julian_month) ⇒ Fixnum

Converts a julian month to a merch month



143
144
145
146
147
148
149
# File 'lib/merch_calendar/util.rb', line 143

def julian_to_merch(julian_month)
  if julian_month == 1
    12
  else
    julian_month - 1
  end
end

#merch_months_in(start_date, end_date) ⇒ Array<Date>

An array of merch dates in start_date to end_date



121
122
123
# File 'lib/merch_calendar/util.rb', line 121

def merch_months_in(start_date, end_date)
  retail_calendar.merch_months_in(start_date, end_date)
end

#merch_to_julian(merch_month) ⇒ Fixnum

Converts a merch month to the correct julian month



130
131
132
133
134
135
136
# File 'lib/merch_calendar/util.rb', line 130

def merch_to_julian(merch_month)
  if merch_month == 12
    1
  else
    merch_month + 1
  end
end

#start_of_month(year, month_param) ⇒ Date

The start date of the month

Examples:

# The following are all equivalent, and refer to May 2015
MerchCalendar.start_of_month(2015, 5)
MerchCalendar.start_of_month(2015, month: 5)
MerchCalendar.start_of_month(2015, julian_month: 5)
MerchCalendar.start_of_month(2015, merch_month: 4)

Options Hash (month_param):

  • :month (Fixnum)

    the julian month

  • :julian_month (Fixnum)

    the julian month

  • :merch_month (Fixnum)

    the MERCH month



47
48
49
50
# File 'lib/merch_calendar/util.rb', line 47

def start_of_month(year, month_param)
  merch_month = get_merch_month_param(month_param)
  retail_calendar.start_of_month(year, merch_month)
end

#start_of_quarter(year, quarter) ⇒ Date

The start date of the quarter



90
91
92
# File 'lib/merch_calendar/util.rb', line 90

def start_of_quarter(year, quarter)
  fiscal_year_calendar.start_of_quarter(year + 1, quarter)
end

#start_of_week(year, month, week) ⇒ Date

The start date of the week



16
17
18
# File 'lib/merch_calendar/util.rb', line 16

def start_of_week(year, month, week)
  retail_calendar.start_of_week(year, julian_to_merch(month), week)
end

#start_of_year(year) ⇒ Date

The start date of the year



70
71
72
# File 'lib/merch_calendar/util.rb', line 70

def start_of_year(year)
  retail_calendar.start_of_year(year)
end

#weeks_for_month(year, month_param) ⇒ Array<MerchWeek>

An array of merch weeks in a given month



160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/merch_calendar/util.rb', line 160

def weeks_for_month(year, month_param)
  merch_month = get_merch_month_param(month_param)

  start_date = retail_calendar.start_of_month(year, merch_month)

  weeks = (retail_calendar.end_of_month(year, merch_month) - start_date + 1) / 7

  (1..weeks).map do |week_num|
    week_start = start_date + ((week_num - 1) * 7)
    week_end = week_start + 6
    MerchWeek.new(week_start, { start_of_week: week_start, end_of_week: week_end, week: week_num })
  end
end

#weeks_in_year(year) ⇒ Fixnum

Returns the number of weeks in a given merch year



110
111
112
# File 'lib/merch_calendar/util.rb', line 110

def weeks_in_year(year)
  retail_calendar.weeks_in_year(year)
end