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

FiscalCalendar starting on 31st day of the month throws ValueError #8

Closed
jmhansen opened this issue Oct 22, 2019 · 2 comments · Fixed by #9
Closed

FiscalCalendar starting on 31st day of the month throws ValueError #8

jmhansen opened this issue Oct 22, 2019 · 2 comments · Fixed by #9
Labels

Comments

@jmhansen
Copy link

jmhansen commented Oct 22, 2019

If the FiscalCalendar starts on the 31st of any month with 31 days, then FiscalDate().quarter throws a ValueError.

Example code:

from fiscalyear import FiscalDate, FiscalYear, fiscal_calendar

with fiscal_calendar(start_month=12, start_day=31):
    fiscal_date = FiscalDate(2019, 10, 22)
    fiscal_date.quarter

Traceback:

Traceback (most recent call last):
  File "<input>", line 3, in <module>
  File "/site-packages/fiscalyear.py", line 594, in quarter
    if self in q:
  File "/site-packages/fiscalyear.py", line 413, in __contains__
    return self.start.date() <= item <= self.end.date()
  File "/site-packages/fiscalyear.py", line 493, in end
    next_start = self.next_quarter.start
  File "/site-packages/fiscalyear.py", line 485, in start
    return FiscalDateTime(year, month, START_DAY, 0, 0, 0)
ValueError: day is out of range for month

The quarters generated are:

  • December 31st
  • March 31st
  • June 31st ← Not a valid day, so it breaks.
@adamjstewart
Copy link
Owner

Thanks for the bug report @jmhansen!

Are there any countries/businesses who actually use a fiscal calendar that starts on the 31st of any month, or is this just a theoretical bug? Either way I'm happy to fix it. What do you think the desired behavior should be? Should it choose the 30th of the month (or 28th if February), or the 1st of the next month?

@jmhansen
Copy link
Author

@adamjstewart - this is definitely an edge case!

I don't know of a company that actually has a fiscal calendar start on the 31st, but we allow users to submit any date, and at least two different users have accidentally submitted the end of year as December 30th, making the 31st the start of their year.

(There is certainly more validation I can do to prevent this, but I do like that this package does aim to handle any fiscal calendar range.)

I think the desired outcome would be to have each quarter start on the last day of the month rather than the 1st of the next month. If someone wants a wonky fiscal calendar, they can have it!

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

Successfully merging a pull request may close this issue.

2 participants