-
Notifications
You must be signed in to change notification settings - Fork 607
fix: Convert datetime instances to UTC while passing over the wire
#6023
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
base: main
Are you sure you want to change the base?
Conversation
datetime instances to UTC while passing over the wiredatetime instances to UTC while passing over the wire
Deploying flet-examples with
|
| Latest commit: |
1a3078e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1d1298e4.flet-examples.pages.dev |
| Branch Preview URL: | https://fix-windows-time-issue.flet-examples.pages.dev |
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.
We've reviewed this pull request using the Sourcery rules engine
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.
Pull request overview
This PR implements UTC-based datetime serialization over the wire to ensure cross-platform consistency when passing datetime values between Python and Dart/Flutter. It addresses two issues: (1) Windows compatibility when calling astimezone() on out-of-range dates, and (2) timezone inconsistencies across platforms in web deployments.
Changes:
- Python encoder now converts naive datetimes to local timezone (with fallback for Windows compatibility), then normalizes all datetimes to UTC before serialization
- Dart decoder converts received UTC datetimes back to local time for UI display
- Dart encoder normalizes datetimes to UTC and formats ISO strings compatible with Python's
fromisoformat() - Date picker default values updated for consistency (adding explicit day parameters)
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/messaging/protocol.py | Added UTC normalization for datetime encoding with Windows compatibility fallback |
| packages/flet/lib/src/utils/time.dart | Added .toLocal() conversion when retrieving datetime values |
| packages/flet/lib/src/transport/flet_msgpack_encoder.dart | Convert datetimes to UTC and replace 'Z' suffix with '+00:00' for Python compatibility |
| packages/flet/lib/src/transport/flet_backend_channel_web_socket.dart | Added FletMsgpackDecoder to enable proper datetime decoding |
| packages/flet/lib/src/transport/flet_backend_channel_javascript_web.dart | Added FletMsgpackDecoder to enable proper datetime decoding |
| packages/flet/lib/src/controls/date_picker.dart | Added explicit day parameter (1) to DateTime constructor for consistency |
| sdk/python/packages/flet/docs/reference/environment-variables.md | Restructured documentation - moved boolean setting tip to top, changed headers from #### to ###, minor grammar improvements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Deploying flet-docs with
|
| Latest commit: |
1a3078e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b801c12f.flet-docs.pages.dev |
| Branch Preview URL: | https://fix-windows-time-issue.flet-docs.pages.dev |
| tz = datetime.timezone.utc | ||
| obj = obj.replace(tzinfo=tz or datetime.timezone.utc) | ||
| # Normalize to UTC to ensure cross-platform consistency. | ||
| obj = obj.astimezone(datetime.timezone.utc) |
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.
Looks like in case with naive we call astimezone() twice: first converting to a local tz and then to UTC. We can convert naive to UTC right away, no?
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fix #5923
Fix #5895
Summary by Sourcery
Normalize cross-platform date and time handling between Python backend and Dart/Flutter clients and update related documentation.
New Features:
Bug Fixes:
Enhancements:
Documentation: