-
Notifications
You must be signed in to change notification settings - Fork 523
Closes #582: Allow partial minutes for python 3.6 or newer #763
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
Conversation
630a6fe to
091c496
Compare
8d88191 to
d2600d8
Compare
dateutil/tz/tz.py
Outdated
| return (dt.replace(tzinfo=None) - EPOCH).total_seconds() | ||
|
|
||
|
|
||
| def supports_seconds(): |
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.
I would not like to change the public API at all with this, there should be no way to query this.
Also, this has a runtime cost when I would prefer an import-time cost.
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.
fixed, made private and calculate correct function at import
dateutil/test/test_tz.py
Outdated
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), | ||
| "1900-01-01 00:00:00+01:40") | ||
| # For python version pre-3.6, this will be rounded | ||
| set_as_old_python() |
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.
There's no need to mock out the old behavior - we don't need to verify that this behavior is accurate on all versions of Python. It's best to split this into two tests, one for pre-3.6 and one for 3.6+, and then use pytest.skipif to run them selectively based on version.
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.
done
b81d332 to
6413db4
Compare
dateutil/test/test_tz.py
Outdated
| def testPartialMinuteSupport(self): | ||
| # If user running python 3.6 or newer, exact offset is used | ||
| tzc = tz.tzfile(BytesIO(base64.b64decode(EUROPE_HELSINKI))) | ||
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), |
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.
I think I would prefer a test that looks like this:
assert datetime(1900, 1, 1, 0, 0, tzinfo=tzc).utcoffset() == timedelta(hours=1, minutes=39, seconds=52)Though I am a bit torn because I will admit that the "compare the string" version sure is easy to read.
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.
The original was with string (see testRoundNonFullMinutes), but I can change them both to timedelta.
However, note that the two would test slightly different things (assert datetime(1900, 1, 1, 0, 0, tzinfo=tzc).utcoffset() == timedelta(hours=1, minutes=39, seconds=52) tests the date offset through utcoffset function, while the current version tests just the date formation from specified offset)
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.
I'll make the change, but in separate commit for easy undo in case we decide to go with original method
dateutil/test/test_tz.py
Outdated
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), | ||
| "1900-01-01 00:00:00+01:39:52") | ||
|
|
||
| delta = timedelta(hours=12, seconds=30) |
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.
I would prefer this to be a separate test (or better yet, a parametrized test).
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.
sure, made this and second part of testRoundNonFullMinutes separate tests
dbc0a17 to
29605a0
Compare
cssherry
left a comment
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.
I noticed there's also offset in tzlocal class and tzfile.fromutc function. Not sure where/if that needs to get trimmed, but haven't touched them
dateutil/test/test_tz.py
Outdated
| assert dt_r == dt_exp | ||
| assert dt_r.tzname() == dt_exp.tzname() | ||
| assert dt_r.utcoffset() == dt_exp.utcoffset() | ||
| if tz.supports_seconds() or tzi != tz.gettz('Africa/Monrovia'): |
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.
Alternatively, just remove Africa/Monrovia test from this set of tests
dateutil/tz/tz.py
Outdated
| sys.version_info[0] > 3 | ||
|
|
||
|
|
||
| def get_supported_offset(offset): |
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.
There's also offset in tzlocal class. Not sure where/if that needs to get trimmed
dateutil/test/test_tz.py
Outdated
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), | ||
| "1900-01-01 00:00:00+01:40") | ||
| # For python version pre-3.6, this will be rounded | ||
| set_as_old_python() |
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.
done
dateutil/tz/tz.py
Outdated
| return (dt.replace(tzinfo=None) - EPOCH).total_seconds() | ||
|
|
||
|
|
||
| def supports_seconds(): |
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.
fixed, made private and calculate correct function at import
dateutil/test/test_tz.py
Outdated
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), | ||
| "1900-01-01 00:00:00+01:39:52") | ||
|
|
||
| delta = timedelta(hours=12, seconds=30) |
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.
sure, made this and second part of testRoundNonFullMinutes separate tests
dateutil/test/test_tz.py
Outdated
| def testPartialMinuteSupport(self): | ||
| # If user running python 3.6 or newer, exact offset is used | ||
| tzc = tz.tzfile(BytesIO(base64.b64decode(EUROPE_HELSINKI))) | ||
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), |
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.
The original was with string (see testRoundNonFullMinutes), but I can change them both to timedelta.
However, note that the two would test slightly different things (assert datetime(1900, 1, 1, 0, 0, tzinfo=tzc).utcoffset() == timedelta(hours=1, minutes=39, seconds=52) tests the date offset through utcoffset function, while the current version tests just the date formation from specified offset)
dateutil/test/test_tz.py
Outdated
| def testPartialMinuteSupport(self): | ||
| # If user running python 3.6 or newer, exact offset is used | ||
| tzc = tz.tzfile(BytesIO(base64.b64decode(EUROPE_HELSINKI))) | ||
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), |
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.
I'll make the change, but in separate commit for easy undo in case we decide to go with original method
dateutil/test/test_tz.py
Outdated
| tzc = tz.tzfile(BytesIO(base64.b64decode(EUROPE_HELSINKI))) | ||
| self.assertEqual(str(datetime(1900, 1, 1, 0, 0, tzinfo=tzc)), | ||
| "1900-01-01 00:00:00+01:40") | ||
| assert datetime(1900, 1, 1, 0, 0, tzinfo=tzc).utcoffset(), timedelta(hours=1, minutes=40) |
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.
I think this needs to be:
assert datetime(1900, 1, 1, 0, 0, tzinfo=tzc).utcoffset() == timedelta(hours=1, minutes=40)0ed3eb6 to
d676718
Compare
d676718 to
44e4a6c
Compare
- Add "Africa/Monrovia" to test_resolve_imaginary test for python 3.6 or newer - Test that partial minutes is supported in python 3.6 or newer for tz.tzfile and datetime.utcoffset - Enable partial minutes in both tz.tzoffset and tz.tzfile - For now, don't warn user when rounding to nearest minute for python pre-3.6
44e4a6c to
41e5176
Compare
Summary of changes
As described in python bug tracker (https://bugs.python.org/issue5288), datetime now allows offsets that are not an integer number of minutes. Dateutil now accounts for this when running in newer versions of python
Closes #582
Pull Request Checklist