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

First day of the week notation is inconsistent with dart-core's DateTime #138

Closed
vincevargadev opened this issue Feb 29, 2020 · 3 comments
Closed

Comments

@vincevargadev
Copy link

It seems to me that the intl package's FIRSTDAYOFWEEK is not consistent with how DateTime represents weekdays.

In the dart-core's DateTime class, there are constants for the weekdays: DateTime.monday is 1, DateTime.tuesday is 2, ..., and DateTime.sunday is 7. As far as I know, this is in accordance with ISO 8601 on how to represent weekdays: Monday is represented as 1.

However, the intl package DateSymbol class has a FIRSTDAYOFWEEK property that is currently described as:

The first day of the week, in ISO 8601 style, where the first day of the week, i.e. index 0, is Monday.

After taking a look at the implementation of theintl package date_symbol_data_local, the source can be found on GitHub, it appears to be that the FIRSTDAYOFWEEK values do use 0 for Monday (so the documentation is correct, but inconsistent with the DateTime value).

Examples:

  • In the US, weeks in calendars start with Sunday. The intl package for en_US says: FIRSTDAYOFWEEK: 6.
  • In Hungary hu, Spain es_ES, and Germany de, the first day of the week is Monday. In the source, it's marked as 0, which according to the intl docs corresponds to Monday, but if I were to use DateTime, I would find the issue that germanDateSymbol.FIRSTDAYOFWEEK != DateTime.Monday.
@jamesderlin
Copy link
Contributor

jamesderlin commented May 2, 2022

I'm not familiar with this code, but it seems like the locale data is automaticallly generated from ICU, and FIRSTDAYOFWEEK is intended to be an index into a List.

The generated code probably could be changed, but I'm not sure that it should necessarily be true that FIRSTDAYOFWEEK be consistent with DateTime.weekday. That would be more convenient, but it also feels like a data abstraction violation. Ideally they'd be different types so that you couldn't accidentally use one in place of the other. In the meantime, you could do something like:

extension DateTimeFirstDayOfWeek on DateSymbols {
  /// Returns the first day of the week as a [DateTime.weekday] value.
  int get firstDayOfWeek => FIRSTDAYOFWEEK + 1;
}

and then you could compare germanDateSymbol.firstDayofWeek != DateTime.monday.

@alan-knight
Copy link
Contributor

👋 Yes, as I recall, it's weird, but consistent with CLDR does, which is where the data comes from. I feel like this has come up before, and I ended up trying to write an explanatory comment, but in a quick search I don't find either an issue or the comment. But it ended up being a "after several hours of carefully studying the issue this is in fact obviously correct" kind of situation. The issue may have been Google-internal.

@vincevargadev
Copy link
Author

Okay, thank you @alan-knight and @jamesderlin.

If there is no way to fix this (or there is nothing to fix), I'd close this issue.

@mosuem mosuem transferred this issue from dart-archive/intl Apr 18, 2023
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

No branches or pull requests

3 participants