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 date comparisons during coupon activations #11

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

1-Byte
Copy link
Contributor

@1-Byte 1-Byte commented Nov 12, 2023

Fix the following error on Python 3.11:

Traceback (most recent call last):
  File ".venv/bin/lidl-plus", line 8, in <module>
    sys.exit(start())
             ^^^^^^^
  File "lidlplus/__main__.py", line 162, in start
    main()
  File "lidlplus/__main__.py", line 156, in main
    activate_coupons(args)
  File "lidlplus/__main__.py", line 138, in activate_coupons
    if datetime.fromisoformat(coupon["startValidityDate"]) > datetime.now():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

Copy link
Owner

@Andre0512 Andre0512 left a comment

Choose a reason for hiding this comment

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

Hi, I would prefer to use datetime.utcnow() here. It's a bit shorter and doesn't need the import.

@1-Byte
Copy link
Contributor Author

1-Byte commented Nov 20, 2023

Hi, this would not fix the issue because datetime.utcnow() returns a naive datetime (and the comparison would be off). fromisoformat() needs a timezone-aware date to compare against.

@Andre0512
Copy link
Owner

That's a good point I didn't consider... thank you! 😃

@Andre0512 Andre0512 merged commit 75b97fc into Andre0512:main Nov 20, 2023
5 checks passed
@1-Byte 1-Byte deleted the timzone branch December 18, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants