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

moment: use this.locale when specified #630

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/moment/src/moment-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export default class MomentUtils implements IUtils<defaultMoment.Moment> {
}

public is12HourCycleInCurrentLocale = () => {
return /A|a/.test(this.moment().localeData().longDateFormat("LT"));
return /A|a/.test(
this.moment.localeData(this.getCurrentLocaleCode()).longDateFormat("LT")
);
};

public getFormatHelperText = (format: string) => {
Expand All @@ -63,7 +65,9 @@ export default class MomentUtils implements IUtils<defaultMoment.Moment> {
.map((token) => {
const firstCharacter = token[0];
if (firstCharacter === "L" || firstCharacter === ";") {
return this.moment.localeData().longDateFormat(token as LongDateFormatKey);
return this.moment
.localeData(this.getCurrentLocaleCode())
.longDateFormat(token as LongDateFormatKey);
}

return token;
Expand Down Expand Up @@ -267,7 +271,9 @@ export default class MomentUtils implements IUtils<defaultMoment.Moment> {
public getMeridiemText = (ampm: "am" | "pm") => {
if (this.is12HourCycleInCurrentLocale()) {
// AM/PM translation only possible in those who have 12 hour cycle in locale.
return this.moment.localeData().meridiem(ampm === "am" ? 0 : 13, 0, false);
return this.moment
.localeData(this.getCurrentLocaleCode())
.meridiem(ampm === "am" ? 0 : 13, 0, false);
}

return ampm === "am" ? "AM" : "PM"; // fallback for de, ru, ...etc
Expand Down