flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.09k stars 27.43k forks source link

MaterialLocalizations has incorrect compact date pattern (d/M/y format instead of dd/MM/y format) #145685

Open dmarotta77 opened 7 months ago

dmarotta77 commented 7 months ago

It seems that the date pattern is wrong. It uses d/M/y instead of dd/MM/y.

Comparing the entry with key 'it' for the datePatterns map in the file packages/flutter_localizations/lib/src/l10n/generated_date_localizations.dart and the one in the intl project pkgs/intl/lib/date_time_patterns.dart, there are the following differences (flutter on the right, intl on the left):

'Md': 'd/M' -> 'Md': 'dd/MM' 'MEd': 'EEE d/M' -> 'MEd': 'EEE dd/MM' 'yM': 'M/y' -> 'yM': 'MM/y' 'yMd': 'd/M/y' -> 'yMd': 'dd/MM/y' 'yMEd': 'EEE d/M/y' -> 'yMEd': 'EEE dd/MM/y'

The correct format should be the one from the intl library.

Steps to reproduce

  1. Create a Flutter project.
  2. Add flutter_localizations to pubspec
  3. Set the app's supported locale to it_IT
  4. Initialize date with the value DateTime(2024, 1, 2)
  5. Print the value of localizations.formatCompactDate(date)

Expected results

The output should be 02/01/2024

Actual results

Printed value is 2/1/2024

Code sample

pubspec.yaml


name: dateformat
description: A new Flutter project.
publish_to: "none"
version: 1.0.0+1
environment:
  sdk: '>=3.3.1 <4.0.0'
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true

main.dart


import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Date Format Test',
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('it', 'IT'),
        // ... other locales the app supports
      ],
      home: Scaffold(
        appBar: AppBar(title: Text('Date Format Test')),
        body: Builder(builder: (context) {
          final locale = Localizations.localeOf(context);
          final localizations = MaterialLocalizations.of(context);
          final date = DateTime(2024, 1, 2);
          return ListView(
            children: [
              Text('Current Locale: ${locale.toString()}'),
              Text('dateHelpText: ${localizations.dateHelpText}'),
              Text('Compact Date: ${localizations.formatCompactDate(date)}'),
              Text('Short Date: ${localizations.formatShortDate(date)}'),
              Text('Medium Date: ${localizations.formatMediumDate(date)}'),
              Text('Full Date: ${localizations.formatFullDate(date)}'),
            ],
          );
        }),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

Doctor output ```console [√] Flutter (Channel stable, 3.19.3, on Microsoft Windows [Versione 10.0.22000.2538], locale it-IT) • Flutter version 3.19.3 on channel stable • Upstream repository https://github.com/flutter/flutter.git • Framework revision ba39319843 (3 weeks ago), 2024-03-07 15:22:21 -0600 • Engine revision 2e4ba9c6fb • Dart version 3.3.1 • DevTools version 2.31.1 [√] Windows Version (Installed version of Windows is version 10 or higher) [X] Android toolchain - develop for Android devices X Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions). If the Android SDK has been installed to a custom location, please use `flutter config --android-sdk` to update to that location. [√] Chrome - develop for the web • Chrome [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.2.3) • Visual Studio Community 2022 version 17.2.32526.322 • Windows 10 SDK version 10.0.19041.0 [!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions). [√] IntelliJ IDEA (version 2023.3) • Flutter plugin version 78.4.2 • Dart plugin version 233.14888 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Versione 10.0.22000.2538] • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.58 • Edge (web) • edge • web-javascript • Microsoft Edge 122.0.2365.92 [√] Network resources • All expected network resources are available. ```
danagbemava-nc commented 7 months ago

https://github.com/flutter/flutter/blob/a8345d539996b4cd6605c0f7848349340d0d206c/packages/flutter/lib/src/material/material_localizations.dart#L244-L255

This doesn't seem to be limited to Italian, it appears to be the same with US english as well. The format displayed doesn't match the docs.

Labeling for further investigation

italian us english
Screenshot 2024-03-26 at 07 52 19 Screenshot 2024-03-26 at 07 59 59
flutter doctor -v ``` [✓] Flutter (Channel stable, 3.19.4, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB) • Flutter version 3.19.4 on channel stable at /Users/nexus/dev/sdks/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 68bfaea224 (5 days ago), 2024-03-20 15:36:31 -0700 • Engine revision a5c24f538d • Dart version 3.3.2 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/nexus/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.2.2 • Dart plugin version 232.10286 [✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.84.0 [✓] Connected device (5 available) • Pixel 7 (mobile) • 28291FDH2001SA • android-arm64 • Android 14 (API 34) • Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 17.4.1 21E236 • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.59 ! Error: Dean’s Apple Watch has recently restarted. To use Dean’s Apple Watch with Xcode, unlock it and its companion iPhone (code 19) [✓] Network resources • All expected network resources are available. • No issues found! [!] Flutter (Channel master, 3.21.0-14.0.pre.29, on macOS 14.3.1 23D60 darwin-arm64, locale en-GB) • Flutter version 3.21.0-14.0.pre.29 on channel master at /Users/nexus/dev/sdks/flutters ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision a8345d5399 (7 hours ago), 2024-03-25 21:07:30 -0400 • Engine revision 3c881b75cc • Dart version 3.4.0 (build 3.4.0-268.0.dev) • DevTools version 2.34.0-dev.12 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/nexus/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.2.2 • Dart plugin version 232.10286 [✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.84.0 [✓] Connected device (6 available) • Pixel 7 (mobile) • 28291FDH2001SA • android-arm64 • Android 14 (API 34) • Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 17.4.1 21E236 • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.3.1 23D60 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.59 ! Error: Dean’s Apple Watch has recently restarted. To use Dean’s Apple Watch with Xcode, unlock it and its companion iPhone (code 19) [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```