Skip to content

Commit

Permalink
fix(dayjs-utils): corrected locale type and parse function
Browse files Browse the repository at this point in the history
  • Loading branch information
rcout1nhoo committed Feb 14, 2022
1 parent dc9a2ba commit a8ed664
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/dayjs/src/dayjs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defaultDayjs.extend(localizedFormatPlugin);
defaultDayjs.extend(isBetweenPlugin);

interface Opts {
locale?: string;
locale?: ILocale;
/** Make sure that your dayjs instance extends customParseFormat and advancedFormat */
instance?: typeof defaultDayjs;
formats?: Partial<DateIOFormats>;
Expand Down Expand Up @@ -59,24 +59,24 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
public rawDayJsInstance: typeof defaultDayjs;
public lib = "dayjs";
public dayjs: Constructor<TDate>;
public locale?: string;
public locale?: ILocale;
public formats: DateIOFormats;

constructor({ locale, formats, instance }: Opts = {}) {
this.rawDayJsInstance = instance || defaultDayjs;
this.dayjs = withLocale(this.rawDayJsInstance, locale);
this.dayjs = withLocale(this.rawDayJsInstance, locale.name);
this.locale = locale;

this.formats = Object.assign({}, defaultFormats, formats);
}

public is12HourCycleInCurrentLocale = () => {
/* istanbul ignore next */
return /A|a/.test(this.rawDayJsInstance.Ls[this.locale || "en"]?.formats?.LT);
return /A|a/.test(this.rawDayJsInstance.Ls[this.locale.name || "en"]?.formats?.LT);
};

public getCurrentLocaleCode = () => {
return this.locale || "en";
return this.locale.name || "en";
};

public getFormatHelperText = (format: string) => {
Expand All @@ -88,7 +88,9 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
var firstCharacter = token[0];
if (firstCharacter === "L") {
/* istanbul ignore next */
return this.rawDayJsInstance.Ls[this.locale || "en"]?.formats[token] ?? token;
return (
this.rawDayJsInstance.Ls[this.locale.name || "en"]?.formats[token] ?? token
);
}
return token;
})
Expand All @@ -110,7 +112,7 @@ export default class DayjsUtils<TDate extends Dayjs = Dayjs> implements IUtils<T
return null;
}

return this.dayjs(value, format, this.locale);
return this.dayjs(value, format, this.locale?.name, true);
};

public date = (value?: any) => {
Expand Down

0 comments on commit a8ed664

Please sign in to comment.