adamjstewart / fiscalyear

:calendar: Utilities for managing the fiscal calendar
MIT License
52 stars 13 forks source link

Add FiscalWeek and fiscal_week attribute to FiscalDate and FiscalDateTime #17

Open nicmendoza opened 3 years ago

nicmendoza commented 3 years ago

I had some time so I thought I'd take a whack at this. No urgency at all on my end on as far as release, I just thought it'd be nice to close out #10.

This PR depends on the fix from #16. Otherwise it's a tiny PR. Implementation is terse, but maybe a bit opaque, so let me know what you think.

adamjstewart commented 3 years ago

Can you add a FiscalWeek class and update the docs as well? Just want to be consistent with the other attrs.

nicmendoza commented 3 years ago

I built and pushed a quick FiscalWeek implementation based off of FiscalDay, but then realized maybe this isn't the correct spec. This implementation calculates the week based on the number of 7-day periods from the start of the year.

I think the more typical way fiscal weeks are counted is based on a user-overridable "start of week" (e.g. Sunday or Monday), which means the first and last weeks of the year are weird lengths and there's a bonus 53rd week every handful of years. Or, put another way, the first week starts on whatever calendar day is defined as the first day of the year. The first week is from that day until the day before the "start of the week," and then the weeks are counted normally until the last week which runs until the day before the new calendar year starts.

I pushed up what I have so far (it's 99% copy and pasted from FiscalDay with minor tweaks). I'm happy to document it as-written or I can find some time to look at it with the alternative spec described above. Let me know what you want to do.

Edit: Actually, and without thinking too hard about it, that might be a relatively straightforward extension of what I just built.

adamjstewart commented 3 years ago

Hmm, I see what you mean. This is getting pretty complicated. Let's go back to the original issue and try to decide on a single robust definition of what a "week" is and what the API should return.