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

feat: port DurationPattern #155

Merged
merged 1 commit into from
May 31, 2024
Merged

feat: port DurationPattern #155

merged 1 commit into from
May 31, 2024

Conversation

chrisimcevoy
Copy link
Owner

@chrisimcevoy chrisimcevoy commented May 31, 2024

Brief bit of exposition needed here first.

In .NET, spans of time tend to be represented by TimeSpan. The Noda Time equivalent to that is a Duration. Noda Time's Duration is capable of conversion to and from all the values in the range of TimeSpan, which covers 292 years or so. In fact, Noda Time's Duration has a much larger range than that, something like 20,000+ years.

When Duration was implemented back in #47, I decided that for Pyoda Time, Duration should have a similar relationship with datetime.timedelta, i.e. it should be possible to convert all possible timedelta values to and from the Pyoda type. The thing is that timedelta's range is so vast that it makes the .NET range look measly by comparison.

At the time, I decided to drastically increase the range of Duration from the range offered by Noda Time, so that the Pyoda Duration would have a range which is slightly larger than timedelta. That decision has had knock-on effects for the DurationPattern port, particularly with regard to parsing validation and so forth.

The end result is that this DurationPattern implementation is very reminiscent of the one you'll find in the mother project, but it allows for much, much greater values to be parsed and formatted.

One other small note. I'm currently having a discussion with myself over in #154 about string formatting stuff. Included in this PR is the use of the new pattern in Duration.__str__ and Duration.__format__. There is no test coverage for that currently, but I had a bit of a play in a REPL and...

>>> from pyoda_time import Duration
>>> 
>>> 
>>> Duration.max_value
1073741823:23:59:59.999999999
>>> Duration.min_value
-1073741824:00:00:00
>>> Duration.epsilon
0:00:00:00.000000001
>>> f"{Duration.max_value:o}"
'1073741823:23:59:59.999999999'
>>> f"{Duration.max_value:j}"
'25769803775:59:59.999999999'
>>> f"{Duration.max_value:D hh mm ss 'hello world'}"
'1073741823 23 59 59 hello world'

Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 95.12195% with 12 lines in your changes missing coverage. Please review.

Project coverage is 95.54%. Comparing base (d989c2b) to head (cf5bf40).
Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
pyoda_time/_duration.py 40.00% 6 Missing ⚠️
pyoda_time/text/_duration_pattern.py 92.20% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   95.54%   95.54%   -0.01%     
==========================================
  Files         238      241       +3     
  Lines       18710    18953     +243     
==========================================
+ Hits        17876    18108     +232     
- Misses        834      845      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chrisimcevoy chrisimcevoy merged commit ea5960f into main May 31, 2024
7 of 9 checks passed
@chrisimcevoy chrisimcevoy deleted the duration-pattern branch May 31, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant