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

fix(datepicker): fix long date format #2630

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/bs-moment/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function expandFormat(_format: string, locale: Locale) {
const localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;

const replaceLongDateFormatTokens = (input: any) => {
return locale.longDateFormat(input) || input;
return locale.formatLongDate(input) || input;
};

localFormattingTokens.lastIndex = 0;
Expand Down
12 changes: 7 additions & 5 deletions src/bs-moment/locale/locale.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Locale {
private _weekdaysShort: string[];
private _weekdaysMin: string[];
private _week: { dow: number; doy: number };
private _longDateFormat: {[key: string]: any};

private _ordinal: string;

Expand Down Expand Up @@ -184,20 +185,21 @@ export class Locale {
return str;
}

longDateFormat(key: string) {
const format = defaultLongDateFormat[key];
const formatUpper = defaultLongDateFormat[key.toUpperCase()];
formatLongDate(key: string) {
this._longDateFormat = this._longDateFormat ? this._longDateFormat : defaultLongDateFormat;
const format = this._longDateFormat[key];
const formatUpper = this._longDateFormat[key.toUpperCase()];

if (format || !formatUpper) {
return format;
}

defaultLongDateFormat[
this._longDateFormat[
key
] = formatUpper.replace(/MMMM|MM|DD|dddd/g, (val: string) => {
return val.slice(1);
});

return defaultLongDateFormat[key];
return this._longDateFormat[key];
}
}