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

Parsing of dates in "ar" locale fails when typed #852

Open
jokraft opened this issue Jun 26, 2024 · 3 comments
Open

Parsing of dates in "ar" locale fails when typed #852

jokraft opened this issue Jun 26, 2024 · 3 comments
Labels
P3 A lower priority bug or feature request package:intl type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jokraft
Copy link

jokraft commented Jun 26, 2024

Describe the bug
There is a problem with parsing type dates in "ar" locale (see: flutter/flutter#138635)

To Reproduce
see examples in flutter/flutter#138635
Alternatively:

import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';

void main() {
  initializeDateFormatting("ar");
  // works
  DateFormat('yMd', "ar").parseStrict(String.fromCharCodes(
      [1633, 1633, 8207, 47, 1633, 1633, 8207, 47, 1634, 1632, 1632, 1633]));
  // fails (codeUnits of typed date)
  try {
    DateFormat('yMd', "ar").parseStrict(String.fromCharCodes(
        [1633, 1633, 47, 1633, 1633, 47, 1634, 1632, 1632, 1633]));
  } catch (e) {
    print(e);
  }
}

Did some digging and my current theory is, that date_time_patterns.dart contains some unneeded "RLM" characters. Are they supposed to be generated there?
If I change keyboard to arabic and type the date there will be no such characters and as such parsing fails.

System Info Dart SDK 3.5.0-277.0.dev Flutter SDK 3.23.0-13.0.pre.277 flutter_personal_test 0.0.0

dependencies:

  • flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
  • flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]

dev dependencies:

  • file 7.0.0 [meta path]

transitive dependencies:

  • characters 1.3.0
  • clock 1.1.1
  • collection 1.18.0
  • intl 0.19.0 [clock meta path]
  • material_color_utilities 0.11.1 [collection]
  • meta 1.15.0
  • path 1.9.0
  • sky_engine 0.0.99
  • vector_math 2.1.4
@jokraft jokraft added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 26, 2024
@mosuem
Copy link
Member

mosuem commented Jun 27, 2024

The date time patterns are autogenerated from the Unicode CLDR database. Date parsing is unfortunately very fragile.

@mosuem mosuem added P3 A lower priority bug or feature request package:intl labels Jun 27, 2024
@jokraft
Copy link
Author

jokraft commented Jun 27, 2024

RLMs are also in ar.xml in CLDR
https://unicode-org.atlassian.net/jira/software/c/projects/CLDR/issues/CLDR-14076 suggests to me that is supposed to be like that. (I am personally not sure since the RLM is for strings with mixed text directions as far as I can see, which should not normally be the case if someone is simply using arabic locale, right?)
I did not manage to get RLM into the string by typing. (Also had a look at some arabic dates I found online and they also did not include RLMs)
Question remains where this should be mitigated. Does every caller of parseStrict need to handle adding the RLMs when in arabic locale? Or should DateFormat handle this?

@mosuem
Copy link
Member

mosuem commented Jun 28, 2024

I don't know what the best strategy is - parsing is inherently fragile exactly because of cases like this. Maybe the logic of parsing could be special-cased for arabic parsing. I am open for reviewing a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request package:intl type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants