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: Display informative message when date has wrong format #4019

Merged
merged 10 commits into from
Nov 8, 2024

Conversation

ndonkoHenri
Copy link
Collaborator

@ndonkoHenri ndonkoHenri commented Sep 20, 2024

Description

Closes #4017

Summary by Sourcery

Improve date and time picker components by adding validation for date values and refactoring attribute handling to enhance code clarity and robustness.

Bug Fixes:

  • Add validation to ensure date values are of type date, datetime, or None, raising a ValueError if not.

Enhancements:

  • Refactor date and time picker components to improve attribute handling and validation.

Copy link
Contributor

sourcery-ai bot commented Sep 20, 2024

Reviewer's Guide by Sourcery

This pull request improves the handling of date and time inputs in the Flet library. It introduces a new utility function for datetime conversion and validation, updates the DatePicker and CupertinoDatePicker classes to use this function, and adds error handling for datetime parsing in the Control class.

File-Level Changes

Change Details Files
Introduce new utility function for datetime conversion and validation
  • Add new file with datetime_to_string function
  • Implement has_valid_datetime_format function to check string format
  • Add assertion to ensure valid datetime format
sdk/python/packages/flet-core/src/flet_core/utils/datetime.py
Update DatePicker class to use new datetime utility function
  • Modify init method to accept Union[datetime, str] for date-related parameters
  • Replace inline datetime conversion with calls to datetime_to_string function
  • Update type hints for setter methods
sdk/python/packages/flet-core/src/flet_core/date_picker.py
Update CupertinoDatePicker class to use new datetime utility function
  • Modify init method to accept Union[datetime, str] for date-related parameters
  • Replace inline datetime conversion with calls to datetime_to_string function
  • Update type hints for setter methods
sdk/python/packages/flet-core/src/flet_core/cupertino_date_picker.py
Add error handling for datetime parsing in Control class
  • Wrap DateTime.parse call in a try-except block
  • Return null if parsing fails instead of throwing an exception
packages/flet/lib/src/models/control.dart
Minor refactoring in TimePicker class
  • Move comment about value_string format to a more appropriate location
sdk/python/packages/flet-core/src/flet_core/time_picker.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ndonkoHenri - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

packages/flet/lib/src/models/control.dart Show resolved Hide resolved
sdk/python/packages/flet-core/src/flet_core/time_picker.py Outdated Show resolved Hide resolved
@ndonkoHenri

This comment was marked as resolved.

@FeodorFitsner FeodorFitsner merged commit 26ed9dd into main Nov 8, 2024
1 of 2 checks passed
@FeodorFitsner FeodorFitsner deleted the assert-for-wrong-date-formats branch November 8, 2024 19:22
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.

Display informative message when date is in a wrong format
2 participants