Skip to content

Comments

[package:intl4x] DateTime formatting redesign#1003

Merged
mosuem merged 15 commits intomainfrom
cleanups
Aug 27, 2025
Merged

[package:intl4x] DateTime formatting redesign#1003
mosuem merged 15 commits intomainfrom
cleanups

Conversation

@mosuem
Copy link
Member

@mosuem mosuem commented Aug 18, 2025

Redesign the date/time/datetime formatting to a builder-like style. This get rid of the custom linking process, as we get a closer mapping to the ICU4X API, and improves usability.

The mapping between this API and the ECMA-style API is not perfect, so the options will need another round of refactorings to get them right. Especially, the share DateTimeFormatOptions object should be either removed completely or at least contain only shared options for all formatters.

cc @sffc as we talked about this kind of API style.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @mosuem, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces significant API cleanups and refactoring across the Intl4x library. The primary focus is on redesigning the DateTimeFormat API to offer a more fluent and composable approach to date and time formatting, including enhanced control over timezone display. Additionally, the LocaleMatcher concept has been entirely removed from the library, simplifying the overall API surface and reducing configuration overhead for all internationalization features. These changes aim to improve the usability and maintainability of the Intl4x package.

Highlights

  • DateTimeFormat API Redesign: The DateTimeFormat class has been significantly refactored. Instead of directly returning formatted strings, methods like d(), m(), y(), ymd(), time(), etc., now return dedicated formatter objects (e.g., DateFormatter, TimeFormatter, DateTimeFormatter). These formatter objects then expose a format(DateTime datetime) method, enabling a more fluent and chainable API for date and time formatting (e.g., intl.dateTimeFormat().d().format(dateTime)).
  • Enhanced Time Zone Formatting: New withTimezone methods have been introduced on the new formatter objects (e.g., withTimezoneShort, withTimezoneLong, withTimeZoneShortOffset, etc.). This provides explicit control over how time zones are applied during date and time formatting, allowing for more precise and flexible timezone display options.
  • Removal of LocaleMatcher: The LocaleMatcher concept and its associated property have been completely removed from the Intl class and all internationalization feature options (CaseMapping, Collation, DateTimeFormat, DisplayNames, ListFormat, NumberFormat, PluralRules). This simplifies the API by removing a configuration option that was likely redundant or unnecessary for the library's intended use cases, streamlining API calls and reducing complexity.
  • Internal Code Simplification: Various internal code cleanups have been performed across the library. This includes the removal of unused imports (e.g., package:meta/meta.dart), deprecated helper functions (e.g., _isUnusedSymbol in hook/link.dart), and general code simplification, contributing to a leaner and more maintainable codebase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant API cleanups, most notably removing the LocaleMatcher parameter from most top-level functions and refactoring the DateTimeFormat API to a more fluent, builder-style pattern. These changes greatly simplify the public API. The refactoring of DateTimeFormat is extensive and introduces a set of Formatter classes, which is a good design. However, I've found a few issues: a critical bug in the ECMA implementation for timezone formatting, some API naming inconsistencies and missing documentation in the new DateTimeFormat API, and some leftover commented-out code and an incomplete comment.

@github-actions
Copy link

github-actions bot commented Aug 18, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
intl4x Breaking 0.12.2 0.13.0 0.13.0 ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Coverage ⚠️
File Coverage
pkgs/intl4x/example/bin/example.dart 💔 Not covered
pkgs/intl4x/lib/datetime_format.dart 💔 Not covered
pkgs/intl4x/lib/intl4x.dart 💚 100 % ⬆️ 14 %
pkgs/intl4x/lib/src/case_mapping/case_mapping_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/case_mapping/case_mapping_impl.dart 💚 100 %
pkgs/intl4x/lib/src/case_mapping/case_mapping_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/collation/collation_4x.dart 💚 77 %
pkgs/intl4x/lib/src/collation/collation_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/collation/collation_impl.dart 💚 100 %
pkgs/intl4x/lib/src/collation/collation_options.dart 💚 9 % ⬆️ 9 %
pkgs/intl4x/lib/src/collation/collation_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/datetime_format/datetime_format.dart 💔 82 % ⬇️ 11 %
pkgs/intl4x/lib/src/datetime_format/datetime_format_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/datetime_format/datetime_format_impl.dart 💔 85 % ⬇️ 15 %
pkgs/intl4x/lib/src/datetime_format/datetime_format_options.dart 💔 33 % ⬇️ 21 %
pkgs/intl4x/lib/src/datetime_format/datetime_format_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/datetime_format/icu4x/date_formatter.dart 💚 96 %
pkgs/intl4x/lib/src/datetime_format/icu4x/date_time_formatter.dart 💚 95 %
pkgs/intl4x/lib/src/datetime_format/icu4x/datetime_format_4x.dart 💚 90 %
pkgs/intl4x/lib/src/datetime_format/icu4x/time_formatter.dart 💚 9 %
pkgs/intl4x/lib/src/display_names/display_names_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/display_names/display_names_impl.dart 💚 100 %
pkgs/intl4x/lib/src/display_names/display_names_options.dart 💚 17 % ⬆️ 17 %
pkgs/intl4x/lib/src/display_names/display_names_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/list_format/list_format_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/list_format/list_format_impl.dart 💚 100 %
pkgs/intl4x/lib/src/list_format/list_format_options.dart 💚 17 % ⬆️ 17 %
pkgs/intl4x/lib/src/list_format/list_format_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/number_format/number_format_4x.dart 💔 91 % ⬇️ 2 %
pkgs/intl4x/lib/src/number_format/number_format_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/number_format/number_format_impl.dart 💚 100 %
pkgs/intl4x/lib/src/number_format/number_format_options.dart 💚 31 % ⬆️ 1 %
pkgs/intl4x/lib/src/number_format/number_format_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/options.dart 💚 100 % ⬆️ 100 %
pkgs/intl4x/lib/src/plural_rules/plural_rules_ecma.dart 💔 Not covered
pkgs/intl4x/lib/src/plural_rules/plural_rules_impl.dart 💚 100 %
pkgs/intl4x/lib/src/plural_rules/plural_rules_options.dart 💚 22 % ⬆️ 11 %
pkgs/intl4x/lib/src/plural_rules/plural_rules_stub.dart 💔 0 % ⬇️ NaN %
pkgs/intl4x/lib/src/utils.dart 💔 67 % ⬇️ 17 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

This check can be disabled by tagging the PR with skip-license-check.

@github-actions
Copy link

github-actions bot commented Aug 21, 2025

Package publishing

Package Version Status Publish tag (post-merge)
package:intl 0.20.3-wip WIP (no publish necessary)
package:intl4x 0.13.0 ready to publish intl4x-v0.13.0
package:intl_translation 0.20.1 already published at pub.dev
package:messages_shrinker 0.2.2-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@mosuem
Copy link
Member Author

mosuem commented Aug 21, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant API cleanups, most notably a more fluent, builder-style API for DateTime formatting and the removal of LocaleMatcher from various option classes. The changes are consistent and well-structured, improving the overall API design. I've identified a few areas for improvement, including removing leftover debugging statements, cleaning up commented-out code, and adding documentation to new public APIs to align with the style guide.

@mosuem mosuem changed the title Intl4x API Cleanups [package:intl4x] DateTime formatting redesign Aug 21, 2025
@mosuem mosuem marked this pull request as ready for review August 21, 2025 13:09
@mosuem mosuem requested a review from robertbastian as a code owner August 21, 2025 13:09
@github-actions github-actions bot added the type-infra A repository infrastructure change or enhancement label Aug 21, 2025
@mosuem mosuem requested a review from robertbastian August 26, 2025 11:36
@mosuem mosuem requested a review from robertbastian August 26, 2025 12:42
@mosuem
Copy link
Member Author

mosuem commented Aug 26, 2025

A TBD is also to further remove fields from the DateTimeFormatOptions object until it contains only common options or is gone. WDYT?

Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
@robertbastian
Copy link
Collaborator

I think the options should be the union of all options, and then the constructors ignore irrelevant options

@mosuem mosuem requested a review from robertbastian August 27, 2025 13:03
@mosuem mosuem merged commit 9a211d1 into main Aug 27, 2025
15 checks passed
@mosuem mosuem deleted the cleanups branch August 27, 2025 13:26
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 28, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

ecosystem (https://github.com/dart-lang/ecosystem/compare/68ff911..fd28be2):
  fd28be2  2025-08-27  Moritz  Dont show warnings by default (dart-lang/ecosystem#365)

http (https://github.com/dart-lang/http/compare/6656f15..ef05b37):
  ef05b37  2025-08-27  Brian Quinlan  [cupertino_http]: Switch to ffigen 19.1.0 (dart-lang/http#1811)

i18n (https://github.com/dart-lang/i18n/compare/6a8f9c7..9a211d1):
  9a211d14  2025-08-27  Moritz  [package:intl4x] `DateTime` formatting redesign (dart-lang/i18n#1003)

protobuf (https://github.com/dart-lang/protobuf/compare/6e9c9f4..765ba8a):
  765ba8a  2025-08-28  Ömer Sinan Ağacan  Fix non-proto3 JSON format double decoding (google/protobuf.dart#1043)
  703bf7c  2025-08-27  Ömer Sinan Ağacan  Compile dart2wasm benchmarks with --no-strip-wasm (google/protobuf.dart#1044)
  9939965  2025-08-26  Ömer Sinan Ağacan  Fix JS interop annotations (google/protobuf.dart#1042)
  da354a2  2025-08-22  Ömer Sinan Ağacan  Update benchmark builder to use -O2 with dart2wasm, add output dir to gitignore (google/protobuf.dart#1041)
  41eba19  2025-08-22  Ömer Sinan Ağacan  Add sinks to benchmarks to prevent smart tools eliminating benchmarked code (google/protobuf.dart#1040)
  3ccc8ab  2025-08-19  dependabot[bot]  Bump actions/checkout from 3.5.3 to 4.2.2 (google/protobuf.dart#1036)
  6bce9d7  2025-08-19  Ömer Sinan Ağacan  Fix unknown enum handling (google/protobuf.dart#853)
  19e5a25  2025-08-15  Ömer Sinan Ağacan  Implement deepCopy as copying, instead of merge (google/protobuf.dart#742)

web (https://github.com/dart-lang/web/compare/ee9733f..e7895bd):
  e7895bd  2025-08-27  Nikechukwu  [interop] Add Support for Declaration Merging and Overloading (dart-lang/web#449)

webdev (https://github.com/dart-lang/webdev/compare/9724fea..a7d3d2f):
  a7d3d2fc  2025-08-27  Ben Konyi  [ DWDS ] Fix issue where null was repeatedly sent to connected clients (dart-lang/webdev#2678)
  e3009dfb  2025-08-27  Nate Biggs  Remove stale calls to dartSdkIsAtLeast. (dart-lang/webdev#2677)
  e0d58082  2025-08-26  Nate Biggs  Fix expectation in test accessing private field. (dart-lang/webdev#2676)

Change-Id: Ia98a8f065830865f6922ca032939380683645d72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447640
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package:intl4x type-infra A repository infrastructure change or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants