Skip to content

Commit

Permalink
moment: use this.locale when specified (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Oct 19, 2022
1 parent 3e11970 commit 44bfe7d
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit 44bfe7d

Please sign in to comment.