-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support for week number of a date in a FiscalYear #10
Comments
@aravinds502 there is currently no way to do this (aside from manually calculating it), but I think that would be a great addition. We already have If you would like to take a stab at implementing this, PRs are always welcome. Otherwise, if there's enough demand, I can take a look at this when I get a chance. |
Note that #11 adds a |
@adamjstewart if there were a FiscalMonth class (for example), would you expect it to have year and month properties that returned the calendar year and month like the example below? So for a fiscal year that starts prior year, October:
Translating back from fiscal year and month to date is, naturally, my project's next requirement. |
I would expect |
Got it, so for my use case (where I'm actually specifically interested in getting the calendar month and year back out from a FiscalMonth) it would look like this, right?:
|
Yep, that looks correct. |
Hey @adamjstewart, hopefully continuing the conversation here makes sense. Plus I think eventually someone could readily build the original The definition of a "fiscal day" seems a little less universally-defined from my limited research, but would you expect Fiscal Day to work like the following? This is basically what I need for my own use case so I thought it could potentially fit into the fiscalyear library:
And then right on up to Or something else? |
I think that API makes sense. I'm trying to think about the easiest way to implement this feature (and other features). Since the start of the fiscal year is a well defined point in time, we could simply use |
Opened #13 for FiscalDay and fiscal_day. |
I calculate the week number in the Fiscal Quarter in a separate function and combine it with Fiscal quarter, but native support would be fantastic.
Happy to add this properly when the FiscalDay PR is merged if there's interest. |
The |
Okay, support for fiscal months and days is merged and documented. Would anyone like to submit a PR to add fiscal weeks, or should I cut a new release at this point? |
@adamjstewart ready to release? |
Yeah, I can cut a new release if no one wants to work on fiscal week at the moment. |
Didn't see anything from @davedavis on this, so I put together a quick PR (#17) to cover the original request in this Issue. If anyone thinks of any missing test cases, please let me know. |
@aravinds502 @davedavis how do you define week number? Is it the number of weeks since the start of the fiscal year, or do you also need to consider the days of the week? For example, if the fiscal year starts on a Monday, and you consider weeks to go from Monday to Sunday, then both definitions are equal, but if the fiscal year starts in the middle of a week, would you add 1 to the week count? |
In support of @adamjstewart 's question, I found this example US fiscal calendar (although it notably doesn't have week numbers on it unlike 4-4-5 calendars I've sen) which standardizes on a Sunday-Saturday week without being a 4-4-5 calendar. Helpful for the visually oriented. Aside from the central point Adam has raised here, it does beg the question of how to best handle the contains logic for checking if a week is in a month, since a week can straddle two. Relevant question regardless of which approach we take. |
Sorry guys, got swamped with another PR so unable to do this. So thanks @nicmendoza for going ahead. @adamjstewart I just used relativedelta from dateutil. My requirement is basically that the first week in each quarter is quarter week 1. From the first day of Q1 is the same, but fiscal week 1. Each quarter quarter week resets but fiscal week doesn't. This is not how other organizations do it so I wasn't going to mess around. |
I looked to see if there is a standard for counting weeks and it looks like ISO has one: https://en.wikipedia.org/wiki/ISO_week_date
I think we should stick to ISO whenever possible. Any objections? |
Excel also follows ISO 8601, although it's not the default behavior of their weeknum function. I guess because the default follows normal-people calendar conventions. No objections to following ISO 8601 in principle. What I haven't wrapped my head around is how to butt this up against the current implementation of fiscalyear. The first day of the year won't necessarily line up to October 1 or April 6 most year. Would FiscalYear(2016,1) have a different start date than FiscalWeek(2016,1)? Poking around for examples in the wild a bit, I came across Zap BI. I've never heard of them but they seem to talk a bit about their approach to this Tableau's docs seem to gloss over it. Lots of conversations online about how to get Excel to spit out a fiscal week Also this: https://pypi.org/project/isoweek/ |
Is there any way to get the Week number for given date in a fiscal year or any plans to support this API?
Ex:
import fiscalyear
fiscalyear.START_MONTH = 7
fiscalyear.START_DAY = 1
cur_date = fiscalyear.FiscalDate(2019, 7, 1)
print(cur_date.week) -> should give 1
The text was updated successfully, but these errors were encountered: