-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4-4-5 support? #27
Comments
If anyone still looking for a solution for this, I made a gem https://github.com/yoelblum/retail_calendar/ |
@yoelblum, I think you can do the trick by overriding the class Calendar445 < MerchCalendar::RetailCalendar
FOUR_WEEK_MONTHS = [2, 5, 8, 11].freeze
FIVE_WEEK_MONTHS = [3, 6, 9, 12].freeze
def start_of_month(year, merch_month)
# 91 = number of days in a single 4-4-5 set
# Merch months
# ============
# row 1 (4 weeks): feb(1) may(4) aug(7) nov(10)
# row 2 (4 weeks): mar(2) jun(5) sep(8) dec(11)
# row 3 (5 weeks): apr(3) jul(6) oct(9) jan(12)
# This line will get the start of the month for any of the merch months in row 1
start = start_of_year(year) + ((merch_month - 1) / 3).to_i * 91
# This code will get the start of the month of any of the merch months in row 2 or row 3
case merch_month
when *FOUR_WEEK_MONTHS
# 28 = 4 weeks
start += 28
when *FIVE_WEEK_MONTHS
# 56 = 8 weeks
start += 56
end
start
end
end So you can use it as this: merch_week = MerchCalendar::MerchWeek.from_date('2022-01-25', calendar: Calendar445.new)
puts merch_week.start_of_month # 2021-12-26 If you need to get the start or end date of the quarter, you can monkey patching the module MerchCalendar
class MerchWeek
def end_of_quarter
calendar.end_of_quarter(year, quarter)
end
def start_of_quarter
calendar.start_of_quarter(year, quarter)
end
end
end So you can use the stuff like this: merch_week = MerchCalendar::MerchWeek.from_date('2022-01-25', calendar: Calendar445.new)
puts merch_week.start_of_quarter # 2021-10-31
puts merch_week.end_of_quarter # 2022-01-29 |
Hello,
I am using the gem and may have the requirement to support 4-4-5 calendar. Is it possible to do with little monkey patching or is it big changes and I'll have to look at some other solutions?
I thought perhaps changing these constants could do the trick or is it not that simple?
The text was updated successfully, but these errors were encountered: