Skip to content
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

Add FiscalWeek and fiscal_week attribute to FiscalDate and FiscalDateTime #17

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nicmendoza
Copy link
Contributor

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.

"""returns: The fiscal week
:rtype: int
"""
return -(-self.fiscal_day // 7)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamjstewart Let me know if you'd rather I just imported and used math.ceil

@adamjstewart
Copy link
Owner

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

@nicmendoza
Copy link
Contributor Author

nicmendoza commented Feb 4, 2021

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.

@nicmendoza nicmendoza changed the title Add simple fiscal_week attribute to FiscalDate and FiscalDateTime Add FiscalWeek and fiscal_week attribute to FiscalDate and FiscalDateTime Feb 4, 2021
@adamjstewart
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants