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

gh-118948: add support for ISO 8601 basic format to datetime #120553

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Jun 15, 2024

In addition to date and datetime, datetime.time also supports ISO 8601 basic format (the rationale is to make it consistent).


📚 Documentation preview 📚: https://cpython-previews--120553.org.readthedocs.build/

@ericsnowcurrently ericsnowcurrently removed their request for review June 17, 2024 19:27
@picnixz picnixz added the stale Stale PR or inactive for long period of time. label Jan 23, 2025
Copy link
Contributor

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs some polishing and simplification in my opinion, especially tests, but looks very good in general :-)

@@ -2176,76 +2177,117 @@ def test_roundtrip(self):
def test_isoformat(self):
t = self.theclass(1, 2, 3, 4, 5, 1, 123)
self.assertEqual(t.isoformat(), "0001-02-03T04:05:01.000123")
self.assertEqual(t.isoformat(basic=True), "00010203T040501.000123")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there has to be a better way to do this (It could also automatically convert it to basic so we don't have to enter both by hand), a helper function would cut down the amount of lines. (Well, it wouldn't increase.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be out of scope for the PR and in this case, explicit is likely better than implicit IMO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope is subjective, you pretty much doubled the amount of tests. I guess it could be a follow up pr. (I don't mind doing it)

def assertIsoFormats(self, t, expected):
    self.assertEqual(t.isoformat(), expected)
    expected_basic = expected_standard.replace("-", "").replace(":", "")
    self.assertEqual(t.isoformat(basic=True), expected_basic)

Four lines to save 40ish.

explicit is likely better than implicit IMO.

Any specific reason, for readability?

Copy link
Member Author

@picnixz picnixz Mar 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason, for readability?

Yes, and for tracking bugs in this case. However, if we want to assert the ISO format differently, we should do it in a refactoring PR and not in this one. The ISO format is not the only whose checks could be refactored in some sense IMO.

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@@ -2176,76 +2177,117 @@ def test_roundtrip(self):
def test_isoformat(self):
t = self.theclass(1, 2, 3, 4, 5, 1, 123)
self.assertEqual(t.isoformat(), "0001-02-03T04:05:01.000123")
self.assertEqual(t.isoformat(basic=True), "00010203T040501.000123")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be out of scope for the PR and in this case, explicit is likely better than implicit IMO.

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Copy link
Contributor

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can leave refactoring for later. LGTM :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants