generated from aboutcode-org/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Datetime versioning scheme #149
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
Open
immqu
wants to merge
13
commits into
aboutcode-org:main
Choose a base branch
from
immqu:datetime-scheme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
992b3c4
datetime versioning scheme
immqu f2cd21c
code style
immqu 794fc6b
code style
immqu 7c4427d
add tests
immqu e12f69f
add dateutil to setup.cfg
immqu 64aecfb
code style
immqu 249ecf0
use standard lib datetime instead of third party library
immqu 6bd9052
code style
immqu 45665de
reimplement datetime parsing logic
immqu 93be448
code style
immqu 8725fee
parse leap second correctly
immqu ec39593
code style
immqu 18e33ac
Merge branch 'main' into datetime-scheme
immqu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ pyparsing==2.4.7 | |
| semantic-version==2.8.5 | ||
| semver==2.13.0 | ||
| isort==5.10.1 | ||
| python-dateutil==2.9.0.post0 | ||
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 |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ install_requires = | |
| packaging | ||
| semantic-version | ||
| semver | ||
| python-dateutil | ||
|
|
||
|
|
||
| [options.packages.find] | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download. | ||
|
|
||
| import re | ||
|
|
||
| from dateutil.parser import isoparse | ||
|
|
||
|
|
||
| class DatetimeVersion: | ||
| """ | ||
| datetime version. | ||
|
|
||
| The timestamp must be RFC3339-compliant, i.e., a subset of ISO8601, where the date AND time are always specified. Therefore, we can use dateutil's ISO-parser but have to check for compliance with the RFC format first via a regex. | ||
| """ | ||
|
|
||
| VERSION_PATTERN = re.compile( | ||
| r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$" | ||
| ) | ||
|
|
||
| def __init__(self, version): | ||
| if not self.is_valid(version): | ||
| raise InvalidVersionError(version) | ||
|
|
||
| version = str(version).strip() | ||
| self.original = version | ||
| self.parsed_stamp = isoparse(version) | ||
|
|
||
| def __eq__(self, other): | ||
| return self.parsed_stamp == other.parsed_stamp | ||
|
|
||
| def __lt__(self, other): | ||
| return self.parsed_stamp < other.parsed_stamp | ||
|
|
||
| def __le__(self, other): | ||
| return self.parsed_stamp <= other.parsed_stamp | ||
|
|
||
| def __gt__(self, other): | ||
| return self.parsed_stamp > other.parsed_stamp | ||
|
|
||
| def __ge__(self, other): | ||
| return self.parsed_stamp >= other.parsed_stamp | ||
|
|
||
| @classmethod | ||
| def is_valid(cls, string): | ||
| return cls.VERSION_PATTERN.match(string) | ||
|
|
||
|
|
||
| class InvalidVersionError(ValueError): | ||
| pass |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.