Skip to content

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Jan 16, 2026

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:

  • Support MessagePack extension decoding on web and WebSocket backends via a shared FletMsgpack decoder.

Bug Fixes:

  • Ensure datetimes are always converted to timezone-aware UTC values before MessagePack encoding on both Python and Dart sides, avoiding platform-specific issues with naive or out-of-range datetimes.
  • Adjust DatePicker control to use fully specified default boundary dates and convert stored UTC datetimes back to local time when reading control values.
  • Make Dart-side ISO datetime serialization compatible with Python's datetime.fromisoformat by replacing the trailing Z suffix with an explicit +00:00 offset.

Enhancements:

  • Add documentation tips and clarify formatting for environment variables, including boolean value handling.
  • Add small protocol encoder/decoder docstrings and wire up the MessagePack decoder in web transport channels.

Documentation:

  • Document how to set boolean environment variables and improve structure and wording of the environment variables reference.

@ndonkoHenri ndonkoHenri changed the title feat: Convert datetime instances to UTC while passing over the wire fix: Convert datetime instances to UTC while passing over the wire Jan 16, 2026
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 16, 2026

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

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

View logs

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.

We've reviewed this pull request using the Sourcery rules engine

Copy link
Contributor

Copilot AI left a 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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 16, 2026

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

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)
Copy link
Contributor

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>
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.

feature: Convert datetime instances to UTC while passing over the wire bug: obj.astimezone() raised OSError: [Errno 22] Invalid argument

3 participants