From ad00dc2548debfb504358a7c1f1269f781caf06b Mon Sep 17 00:00:00 2001 From: Ilya Surmay Date: Tue, 12 Sep 2017 15:18:59 +0300 Subject: [PATCH] fix(datepicker): fix long date format --- src/bs-moment/format.ts | 2 +- src/bs-moment/locale/locale.class.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bs-moment/format.ts b/src/bs-moment/format.ts index 0463eb6fb9..ccd6045ec4 100644 --- a/src/bs-moment/format.ts +++ b/src/bs-moment/format.ts @@ -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; diff --git a/src/bs-moment/locale/locale.class.ts b/src/bs-moment/locale/locale.class.ts index c8f292046a..0dab2f2ac7 100644 --- a/src/bs-moment/locale/locale.class.ts +++ b/src/bs-moment/locale/locale.class.ts @@ -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; @@ -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]; } }