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

Fix OverflowError when calculating datetime.min date for left-hand TZs #2401

Merged
merged 7 commits into from
Oct 9, 2023

Conversation

xispa
Copy link
Member

@xispa xispa commented Oct 9, 2023

Description of the issue/feature this PR addresses

This Pull Request fixes the following issue when validating a max_date in a Timezone that is before GMT+0:

Pdb++) value
'2023-10-02T00:00'
(Pdb++) max_date
DateTime('9999/12/31 23:59:59.999999 US/Central')
(Pdb++) dtime.to_ansi(value)
'20231002000000'
(Pdb++) dtime.to_ansi(max_date)
*** OverflowError: date value out of range
(Pdb++) dtime.to_ansi(dtime.datetime.min)
'00010101000000'
(Pdb++) dtime.to_ansi(dtime.datetime.max)
'99991231235959'

Current behavior before PR

Traceback when validating max dates in TZ that are on the left-hand of GMT+0

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 176, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 385, in publish_module
  Module ZPublisher.WSGIPublisher, line 288, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module bika.lims.decorators, line 51, in decorator
  Module bika.lims.browser.analysisrequest.add2, line 708, in __call__
  Module bika.lims.browser.analysisrequest.add2, line 1753, in ajax_submit
  Module senaite.core.browser.fields.datetime, line 77, in validate
  Module senaite.core.browser.fields.datetime, line 117, in validate_max_date
  Module senaite.core.api.dtime, line 205, in to_ansi
  Module senaite.core.api.dtime, line 166, in to_dt
  Module senaite.core.api.dtime, line 320, in to_zone
  Module pytz.tzinfo, line 328, in localize
  Module pytz.tzinfo, line 254, in normalize
OverflowError: date value out of range

Desired behavior after PR is merged

No traceback when validating max dates in TZ that are on the left-hand of GMT+0

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa changed the title Fix OverflowError: date value out of range when calculating min date for left-hand TZs Fix OverflowError when calculating datetime.min date for left-hand TZs Oct 9, 2023
@xispa xispa requested a review from ramonski October 9, 2023 16:09
@xispa xispa added the Bug 🐞 label Oct 9, 2023
@ramonski ramonski merged commit 4648d73 into 2.x Oct 9, 2023
2 checks passed
@ramonski ramonski deleted the fix-max-dt-ansi branch October 9, 2023 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants