Skip to content

[unified_analytics] Initialize date formatting (package:intl requirement) #78

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

Merged

Conversation

eliasyishak
Copy link
Contributor

As part of #70, initializing date formatting upstream within the package will ensure that clients using this package won't need to call it before implementing.

This package requires date formatting for the dates that are written and read from the config file that stores when each tool was onboarded to telemetry collection.

Copy link
Member

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

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

The analysis server's doesn't currently invoke initializeDateFormatting. Does that mean that it's current use of this package (without this change) is broken? If so, wee need to get this landed and pulled in to the SDK repo, and might need a cherry pick.

@eliasyishak
Copy link
Contributor Author

I'm not sure why this wasn't an issue on the Dart side because when I ran this in Flutter, I immediately got an error saying to run this function before any date parsing.

I'm going to do a bit more digging to see how this works in different locales first before opening it up for merging but I agree, ultimately it should be cherry-picked in so that we're safe

@devoncarew
Copy link
Member

cc @mosuem wrt package:intl usage

@mosuem
Copy link
Member

mosuem commented Apr 13, 2023

@bwilkerson @eliasyishak Which code works without calling initializeDateFormatting? If I can help debugging let me know.

@eliasyishak
Copy link
Contributor Author

Hi @mosuem thanks for following up! So if you look at this function in the flutter tool https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/globals.dart#L94-L105

You'll see that I have a function that will return an analytics instance, which comes from package:unified_analytics. Within this package, we are formatting dates into strings to write out to files. However, when I comment out initializeDateFormatting(); on line 96, I get the below error

Unhandled exception:
LocaleDataException: Locale data has not been initialized, call initializeDateFormatting(<locale>).
#0      UninitializedLocaleData._throwException (package:intl/src/intl_helpers.dart:81:5)
#1      UninitializedLocaleData.containsKey (package:intl/src/intl_helpers.dart:75:7)
#2      DateFormat.localeExists (package:intl/src/intl/date_format.dart:824:28)
#3      verifiedLocale (package:intl/src/intl_helpers.dart:186:19)
#4      verifiedLocale (package:intl/src/intl_helpers.dart:183:12)
#5      new DateFormat (package:intl/src/intl/date_format.dart:267:27)
#6      ConfigHandler.dateStamp (package:unified_analytics/src/config_handler.dart:38:12)
#7      ConfigHandler.addTool (package:unified_analytics/src/config_handler.dart:101:30)
#8      AnalyticsImpl.clientShowedMessage (package:unified_analytics/src/analytics.dart:388:22)
#9      _exit (package:flutter_tools/runner.dart:309:23)
#10     _handleToolError (package:flutter_tools/runner.dart:206:14)
<asynchronous suspension>
#11     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:122:7)
<asynchronous suspension>

It tells us to just call the initialization function for the datetimes and that fixes the error, but I just wanted to understand that if I called it within the package, if that will fix it for any tool using this package?

@mosuem
Copy link
Member

mosuem commented Apr 13, 2023

initializeDateFormatting just sets the static dateTimeSymbols field, so this should work for any call to date formatting methods after that.

@eliasyishak
Copy link
Contributor Author

eliasyishak commented Apr 13, 2023

Great, opening up the PR then @bwilkerson

Oops forgot you already approved

@eliasyishak eliasyishak marked this pull request as ready for review April 13, 2023 15:11
@eliasyishak eliasyishak merged commit 924e9ed into dart-lang:main Apr 13, 2023
@bwilkerson
Copy link
Member

Can you pull this version into the SDK, and then create a cherry pick (using https://github.com/dart-lang/sdk/wiki/Cherry-picks-to-a-release-channel) to get this into the 3.0 branch?

@eliasyishak eliasyishak deleted the 70-initialize-date-formatting branch April 13, 2023 15:48
@eliasyishak eliasyishak restored the 70-initialize-date-formatting branch April 13, 2023 21:03
@eliasyishak eliasyishak deleted the 70-initialize-date-formatting branch April 17, 2023 12:41
dcharkes pushed a commit that referenced this pull request May 23, 2023
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@93ea575...755da8c)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants