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

STCOM-849 wrong day of week #1583

Merged
merged 7 commits into from
Jul 8, 2021
Merged

STCOM-849 wrong day of week #1583

merged 7 commits into from
Jul 8, 2021

Conversation

JohnC-80
Copy link
Contributor

@JohnC-80 JohnC-80 commented Jun 29, 2021

resolves https://issues.folio.org/browse/STCOM-849

Problem(s)

a) FOLIO's hard-coded locales are inconsistently formatted in 2-letter (ex: "ru") and 4-letter (ex: "en-SE") versions. Both forms are valid, but the 2nd 2 letters (region) is particularly important for calendar-rendering since it is necessary to derive the first day of the week.
b) MomentJS stores its i18n info in locale configuration files. If momentJS is asked to apply a locale, and it doesn't have that specific static locale file, it defaults to 'en'. If the locale is set incorrectly, calendar days will render as if 'Sunday' was the first day of the week.

Approach

I've added a static mapping of 'default' common region codes so that the incoming 2-letter locale can be normalized for Calendar's purposes. 'ru' is adjusted to be 'ru-RU' , 'sv' adjusted to be 'sv-SE' etc...
If we ever need a different region from the default, then a new language/region locale will actually need to be added to stripes. ex: we've got 'ru' - but not 'ru-US'.
Using the adjusted locale, we can get the correct first-day-of-the-week.
Taking that first day of week and offsetting the default 'english' weekday rendering by x days takes care of the calendar offset issue.

Would be awesome if browser Intl API had first-day-of-week info, but it doesn't yet... "yet" could happen 10 years from now... but some recent movement is here - tc39/ecma402#580 This progress after another thread from 2015 tc39/ecma402#6 ... so it'll be another 5 years before browsers actually pick it up XD...

Future work.

It would be nice to jettison local static files like these in favor (maybe) of unicode CLDR via CLDRjs :

@JohnC-80 JohnC-80 changed the title Stcom 849 wrong day of week STCOM-849 wrong day of week Jun 29, 2021
Copy link
Contributor

@mkuklis mkuklis left a comment

Choose a reason for hiding this comment

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

Great work @JohnC-80! Thank you for addressing it.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 8, 2021

@JohnC-80 JohnC-80 merged commit 54ccca4 into master Jul 8, 2021
@zburke zburke deleted the stcom-849-wrong-day-of-week branch October 21, 2021 03:17
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

Successfully merging this pull request may close these issues.

3 participants