aiopyarr icon indicating copy to clipboard operation
aiopyarr copied to clipboard

Parse datetime strings to timezone aware objects

Open tkdrob opened this issue 1 year ago • 4 comments

Proposed change

This PR attempts to fix the error in getting the wrong date for calendar items. All dates are now parsed as UTC if a timezone is not provided in the input string.

Type of change

  • [ ] Dependency upgrade
  • [x] Bugfix (non-breaking change which fixes an issue)
  • [ ] New feature (which adds functionality)
  • [ ] Breaking change (fix/feature causing existing functionality to break)
  • [ ] Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes https://github.com/home-assistant/core/issues/110107
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • [x] The code change is tested and works locally.
  • [x] Local tests pass.
  • [x] There is no commented out code in this PR.
  • [x] The code has been formatted (make lint)
  • [x] Tests have been added to verify that the new code works.

Summary by CodeRabbit

  • New Features

    • Enhanced datetime handling across the application, ensuring consistency and accuracy in date and time processing.
    • Introduced a new categorization for release types, improving clarity in release management.
  • Bug Fixes

    • Resolved potential issues with datetime comparisons by ensuring all datetime objects are timezone-aware.
  • Tests

    • Updated test cases to consistently use UTC timezone for datetime assertions, improving test reliability and accuracy.

tkdrob avatar Sep 07 '24 14:09 tkdrob

[!WARNING]

Rate limit exceeded

@tkdrob has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 56 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between b6b82b8749ecbe365e7e934b8a5072d8881e1a76 and cb7e6cc778c4b763b5294f8a84f1a102c9a1630d.

Walkthrough

The changes involve modifications to datetime handling across multiple files in the aiopyarr project. Key updates include the simplification of the get_datetime function, the removal of the get_date function, and the introduction of new constants for release types. Additionally, various test files have been updated to ensure consistent timezone handling using UTC, enhancing the accuracy of datetime assertions throughout the codebase.

Changes

Files Change Summary
aiopyarr/models/base.py Simplified get_datetime function by removing utc parameter; removed get_date function.
aiopyarr/models/const.py Replaced CONVERT_TO_DATE with RELEASE_TYPES; modified CONVERT_TO_DATETIME to include RELEASE_TYPES.
aiopyarr/models/radarr_common.py Updated releaseDateType method to accept datetime instead of date, enhancing date handling.
tests/test_lidarr.py Updated datetime assertions to include UTC timezone, ensuring consistency across tests.
tests/test_radarr.py Replaced date with datetime in assertions to ensure timezone awareness.
tests/test_request.py Modified datetime assertions to include UTC timezone for accuracy.
tests/test_sonarr.py Transitioned to using UTC for timezone handling in assertions, enhancing compatibility.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Application
    participant Database

    User->>Application: Request datetime handling
    Application->>Database: Fetch datetime data
    Database-->>Application: Return datetime data
    Application->>User: Provide datetime response

🐰 In the meadow where I hop and play,
The datetime changes brightened my day!
With UTC now guiding the way,
No more confusion, come what may!
Hooray for constants, clear and bright,
In the world of code, all feels just right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Sep 07 '24 14:09 coderabbitai[bot]

As previously mentioned on Discord, the changes in this PR are more extensive than I expected: Why do we now parse the dates to timezone aware objects, I think it would be more natural to just let them be dates? From the API we get for example 'inCinemas': '2024-09-11T00:00:00Z', I'm assuming the intention is not to signal the movie was released at midnight September 11th in the UTC timezone, but that the movie is released today?

Or is the plan that the Home Assistant integration knows inCinemas, among other fields, should be interpreted as a date, and we worry about converting times to dates there?

@allenporter maybe you could also take a look since you helped with https://github.com/home-assistant/core/pull/118251

emontnemery avatar Nov 07 '24 09:11 emontnemery

As previously mentioned on Discord, the changes in this PR are more extensive than I expected: Why do we now parse the dates to timezone aware objects, I think it would be more natural to just let them be dates? From the API we get for example 'inCinemas': '2024-09-11T00:00:00Z', I'm assuming the intention is not to signal the movie was released at midnight September 11th in the UTC timezone, but that the movie is released today?

Or is the plan that the Home Assistant integration knows inCinemas, among other fields, should be interpreted as a date, and we worry about converting times to dates there?

@allenporter maybe you could also take a look since you helped with home-assistant/core#118251

I agree that it seems like releaseDate would be simplest returned as a datetime.date here. You can do it in home assistant also, but doing it here seems nice. However, this might be considered a breaking change, so not sure how large of a deal this is for other clients of this API. I assume with this all home assistant will need to do is call .date() on the time though so maybe not so bad.

allenporter avatar Nov 07 '24 15:11 allenporter

As previously mentioned on Discord, the changes in this PR are more extensive than I expected: Why do we now parse the dates to timezone aware objects, I think it would be more natural to just let them be dates? From the API we get for example 'inCinemas': '2024-09-11T00:00:00Z', I'm assuming the intention is not to signal the movie was released at midnight September 11th in the UTC timezone, but that the movie is released today? Or is the plan that the Home Assistant integration knows inCinemas, among other fields, should be interpreted as a date, and we worry about converting times to dates there? @allenporter maybe you could also take a look since you helped with home-assistant/core#118251

I agree that it seems like releaseDate would be simplest returned as a datetime.date here. You can do it in home assistant also, but doing it here seems nice. However, this might be considered a breaking change, so not sure how large of a deal this is for other clients of this API. I assume with this all home assistant will need to do is call .date() on the time though so maybe not so bad.

I misread the diffs. This PR is changing some of the datetime.date return values to datetime.datetime and i think it would be best to keep them as datetime.date as suggested.

allenporter avatar Nov 07 '24 15:11 allenporter