Class: MerchCalendar::DateCalculator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/merch_calendar/date_calculator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#end_of_month(year, merch_month) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


44
45
46
47
48
49
50
# File 'lib/merch_calendar/date_calculator.rb', line 44

def end_of_month(year, merch_month)
  if merch_month == 12
    end_of_year(year)
  else
    start_of_month(year, merch_month + 1) - 1
  end
end

#end_of_quarter(year, quarter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the ending date for a particular quarter


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/merch_calendar/date_calculator.rb', line 67

def end_of_quarter(year, quarter)
  case quarter
  when 1
    end_of_month(year, 9)
  when 2
    end_of_month(year, 12)
  when 3
    end_of_month(year, 3)
  when 4
    end_of_month(year, 6)
  end
end

#end_of_year(year) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/merch_calendar/date_calculator.rb', line 6

def end_of_year(year)
  year_end = Date.new (year + 1), 1, -1
  wday = (year_end.wday + 1) % 7

  if wday > 3
    year_end += 7 - wday
  elsif wday > 0
    year_end -= wday
  end
  year_end
end

#julian_to_merch(julian_month) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


93
94
95
96
97
98
99
# File 'lib/merch_calendar/date_calculator.rb', line 93

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

#merch_to_julian(merch_month) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


85
86
87
88
89
90
91
# File 'lib/merch_calendar/date_calculator.rb', line 85

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

#start_of_month(year, merch_month) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The starting date of a given month THIS IS THE MERCH MONTH 1 = feb


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/merch_calendar/date_calculator.rb', line 27

def start_of_month(year, merch_month)
  # 91 = number of days in a single 4-5-4 set 
  start = start_of_year(year) + ((merch_month - 1) / 3).to_i * 91

  case merch_month
  when 2,5,8,11
    # 28 = 4 weeks
    start = start + 28
  when 3,6,9,12
    # The 5 week months
    # 63 = 4 weeks + 5 weeks
    start = start + 63
  end
  
  start
end

#start_of_quarter(year, quarter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the starting date for a particular quarter


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/merch_calendar/date_calculator.rb', line 53

def start_of_quarter(year, quarter)
  case quarter
  when 1
    start_of_month(year, 7)
  when 2
    start_of_month(year, 10)
  when 3
    start_of_month(year, 1)
  when 4
    start_of_month(year, 4)
  end
end

#start_of_year(year) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The day after last years' end date


19
20
21
# File 'lib/merch_calendar/date_calculator.rb', line 19

def start_of_year(year)
  end_of_year(year - 1) + 1
end

#weeks_in_year(year) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the number of weeks in a particular year


81
82
83
# File 'lib/merch_calendar/date_calculator.rb', line 81

def weeks_in_year(year)
  ((start_of_year(year + 1) - start_of_year(year)) / 7).to_i
end