-
Notifications
You must be signed in to change notification settings - Fork 1
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
preliminary str parse and format methods #90
Changes from 2 commits
640705c
a8802d6
3913997
25ba4ad
540bd10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,27 @@ def __repr__(self) -> str: | |
return "<Undate '%s' (%s)>" % (self.label, self) | ||
return "<Undate %s>" % self | ||
|
||
@classmethod | ||
def parse(cls, date_string, format) -> Union["Undate", "UndateInterval"]: | ||
"""parse a string to an undate or undate interval using the specified format; | ||
for now, only supports named formatters""" | ||
formatter_cls = BaseDateFormat.available_formatters().get(format, None) | ||
if formatter_cls: | ||
# NOTE: some parsers may return intervals; is that ok here? | ||
return formatter_cls().parse(date_string) | ||
|
||
raise ValueError(f"Unsupported format '{format}'") | ||
Comment on lines
+172
to
+181
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. Review the implementation of the The Additionally, the comment on line 172 notes that some parsers may return intervals. It's important to clarify whether this behavior is acceptable or if additional handling is needed when an interval is not expected.
rlskoeser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def format(self, format) -> str: | ||
"""format this undate as a string using the specified format; | ||
for now, only supports named formatters""" | ||
formatter_cls = BaseDateFormat.available_formatters().get(format, None) | ||
if formatter_cls: | ||
# NOTE: some parsers may return intervals; is that ok here? | ||
return formatter_cls().to_string(self) | ||
|
||
raise ValueError(f"Unsupported format '{format}'") | ||
rlskoeser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _comparison_type(self, other: object) -> "Undate": | ||
"""Common logic for type handling in comparison methods. | ||
Converts to Undate object if possible, otherwise raises | ||
|
@@ -424,6 +445,15 @@ def __str__(self) -> str: | |
# using EDTF syntax for open ranges | ||
return "%s/%s" % (self.earliest or "..", self.latest or "") | ||
|
||
def format(self, format) -> str: | ||
"""format this undate interval as a string using the specified format; | ||
for now, only supports named formatters""" | ||
formatter_cls = BaseDateFormat.available_formatters().get(format, None) | ||
if formatter_cls: | ||
return formatter_cls().to_string(self) | ||
|
||
raise ValueError(f"Unsupported format '{format}'") | ||
|
||
def __repr__(self) -> str: | ||
if self.label: | ||
return "<UndateInterval '%s' (%s)>" % (self.label, self) | ||
|
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.
Remove unused import:
Union
.The import of
Union
from thetyping
module is flagged as unused by the static analysis tool. If it's not needed, consider removing it to keep the code clean and efficient.Committable suggestion
Tools
Ruff