-
Notifications
You must be signed in to change notification settings - Fork 3
add fiscal year versioning #1896
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
|
|
||
|
|
||
| class DateVersionFormat(StrEnum): | ||
| fiscal_year = "Fiscal Year" | ||
| quarter = "Quarter" | ||
| month = "Month" | ||
| date = "Date" | ||
|
|
@@ -159,6 +160,11 @@ class Date(Version): | |
| @property | ||
| def label(self) -> str: | ||
| match self.format: | ||
| case DateVersionFormat.fiscal_year: | ||
| if self.patch == 0: | ||
| return f"FY{self.date.strftime('%Y')}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remind me what the label is used for?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like it's used in
|
||
| else: | ||
| return f"FY{self.date.strftime('%Y')}.{self.patch}" | ||
| case DateVersionFormat.quarter: | ||
| if self.patch == 0: | ||
| return ( | ||
|
|
@@ -176,6 +182,8 @@ def label(self) -> str: | |
| return self.date.strftime("%Y-%m-%d") | ||
| else: | ||
| return f"{self.date.strftime('%Y-%m-%d')}.{self.patch}" | ||
| case _: | ||
| raise ValueError(f"Unsupported DateVersionFormat '{self.format}'") | ||
|
|
||
| def __lt__(self, other) -> bool: | ||
| match other: | ||
|
|
@@ -253,6 +261,11 @@ def parse(v: str) -> Version: | |
| return MajorMinor( | ||
| year=int(m[1]), major=int(m[2]), minor=int(m[3]), patch=int(m[4]) | ||
| ) | ||
| case r"^FY(\d{4})$" as m: | ||
| return Date( | ||
| date(int(m[1]), 1, 1), | ||
| format=DateVersionFormat.fiscal_year, | ||
| ) | ||
| case r"^(\d{2})Q(\d)$" as m: | ||
| return Date( | ||
| date(2000 + int(m[1]), int(m[2]) * 3 - 2, 1), | ||
|
|
@@ -403,6 +416,11 @@ def bump( | |
| minor=previous_version.minor, | ||
| patch=previous_version.patch + bump_by, | ||
| ) | ||
| case Date(format=DateVersionFormat.fiscal_year), None: | ||
| return Date( | ||
| date=previous_version.date + relativedelta(years=bump_by), | ||
| format=previous_version.format, | ||
| ) | ||
| case Date(format=DateVersionFormat.quarter), None: | ||
| return Date( | ||
| date=previous_version.date + relativedelta(months=bump_by * 3), | ||
|
|
@@ -436,7 +454,7 @@ def bump( | |
| case Date(), None: | ||
| raise ValueError(f"Unsupported date format {previous_version.format}") | ||
| case Date(), _: | ||
| raise Exception( | ||
| raise ValueError( | ||
| f"Version subtype {bump_type} not applicable for Date versions" | ||
| ) | ||
| case CapitalBudget(), None: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a calendar year?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup all the
DateVersionFormatformats are declared this way. like 31 is what makes this afiscal_yearversionSince the actual start of the city's fiscal year doesn't factor into how we version our data products, I went with January 1st (no extra logic for) for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, sorry, I spaced a little bit. (read too fast, and thought this was a date default, rather than a test case). All good.