Skip to content

Commit 6589ee9

Browse files
authored
feat(bs-moment): add localization tests (#2466)
* feat(bs-moment): add localization tests * chore(build): fix ts errors
1 parent 38e562d commit 6589ee9

30 files changed

+440
-106
lines changed

demo/src/ng-api-doc.ts

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,19 @@ export const ngdoc: any = {
139139
"properties": []
140140
},
141141
"LocaleData": {
142-
"fileName": "src/datepicker/models/index.ts",
142+
"fileName": "src/bs-moment/locale/locale.class.ts",
143143
"className": "LocaleData",
144144
"description": "",
145145
"methods": [],
146146
"properties": []
147147
},
148+
"TimeUnit": {
149+
"fileName": "src/bs-moment/types.ts",
150+
"className": "TimeUnit",
151+
"description": "",
152+
"methods": [],
153+
"properties": []
154+
},
148155
"ButtonCheckboxDirective": {
149156
"fileName": "src/buttons/button-checkbox.directive.ts",
150157
"className": "ButtonCheckboxDirective",
@@ -489,9 +496,14 @@ export const ngdoc: any = {
489496
"fileName": "src/datepicker/bs-datepicker.component.ts",
490497
"className": "BsDatepickerComponent",
491498
"description": "",
492-
"selector": "bs-datepicker",
499+
"selector": "bs-datepicker,[bsDatepicker]",
493500
"exportAs": "bsDatepicker",
494501
"inputs": [
502+
{
503+
"name": "bsValue",
504+
"type": "Date",
505+
"description": ""
506+
},
495507
{
496508
"name": "container",
497509
"defaultValue": "body",
@@ -503,6 +515,12 @@ export const ngdoc: any = {
503515
"type": "boolean",
504516
"description": "<p>Returns whether or not the popover is currently being shown</p>\n"
505517
},
518+
{
519+
"name": "outsideClick",
520+
"defaultValue": "true",
521+
"type": "boolean",
522+
"description": ""
523+
},
506524
{
507525
"name": "placement",
508526
"defaultValue": "bottom",
@@ -514,25 +532,20 @@ export const ngdoc: any = {
514532
"defaultValue": "click",
515533
"type": "string",
516534
"description": "<p>Specifies events that should trigger. Supports a space separated list of\nevent names.</p>\n"
517-
},
518-
{
519-
"name": "value",
520-
"type": "Date",
521-
"description": ""
522535
}
523536
],
524537
"outputs": [
538+
{
539+
"name": "bsValueChange",
540+
"description": ""
541+
},
525542
{
526543
"name": "onHidden",
527544
"description": "<p>Emits an event when the popover is hidden</p>\n"
528545
},
529546
{
530547
"name": "onShown",
531548
"description": "<p>Emits an event when the popover is shown</p>\n"
532-
},
533-
{
534-
"name": "valueChange",
535-
"description": ""
536549
}
537550
],
538551
"properties": [],
@@ -561,8 +574,14 @@ export const ngdoc: any = {
561574
"fileName": "src/datepicker/bs-daterangepicker.component.ts",
562575
"className": "BsDaterangepickerComponent",
563576
"description": "",
564-
"selector": "bs-daterangepicker",
577+
"selector": "bs-daterangepicker,[bsDaterangepicker]",
578+
"exportAs": "bsDaterangepicker",
565579
"inputs": [
580+
{
581+
"name": "bsValue",
582+
"type": "Date[]",
583+
"description": ""
584+
},
566585
{
567586
"name": "container",
568587
"defaultValue": "body",
@@ -574,6 +593,12 @@ export const ngdoc: any = {
574593
"type": "boolean",
575594
"description": "<p>Returns whether or not the popover is currently being shown</p>\n"
576595
},
596+
{
597+
"name": "outsideClick",
598+
"defaultValue": "true",
599+
"type": "boolean",
600+
"description": ""
601+
},
577602
{
578603
"name": "placement",
579604
"defaultValue": "bottom",
@@ -585,25 +610,20 @@ export const ngdoc: any = {
585610
"defaultValue": "click",
586611
"type": "string",
587612
"description": "<p>Specifies events that should trigger. Supports a space separated list of\nevent names.</p>\n"
588-
},
589-
{
590-
"name": "value",
591-
"type": "Date[]",
592-
"description": ""
593613
}
594614
],
595615
"outputs": [
616+
{
617+
"name": "bsValueChange",
618+
"description": ""
619+
},
596620
{
597621
"name": "onHidden",
598622
"description": "<p>Emits an event when the popover is hidden</p>\n"
599623
},
600624
{
601625
"name": "onShown",
602626
"description": "<p>Emits an event when the popover is shown</p>\n"
603-
},
604-
{
605-
"name": "valueChange",
606-
"description": ""
607627
}
608628
],
609629
"properties": [],
@@ -967,13 +987,6 @@ export const ngdoc: any = {
967987
"methods": [],
968988
"properties": []
969989
},
970-
"TimeUnit": {
971-
"fileName": "src/datepicker/models/index.ts",
972-
"className": "TimeUnit",
973-
"description": "",
974-
"methods": [],
975-
"properties": []
976-
},
977990
"BsNavigationEvent": {
978991
"fileName": "src/datepicker/models/index.ts",
979992
"className": "BsNavigationEvent",
@@ -1040,28 +1053,19 @@ export const ngdoc: any = {
10401053
"properties": [],
10411054
"methods": []
10421055
},
1043-
"BsDatepickerDayViewComponent": {
1044-
"fileName": "src/datepicker/themes/bs/bs-datepicker-day-view.component.ts",
1045-
"className": "BsDatepickerDayViewComponent",
1056+
"BsDatepickerDayDecoratorComponent": {
1057+
"fileName": "src/datepicker/themes/bs/bs-datepicker-day-decorator.directive.ts",
1058+
"className": "BsDatepickerDayDecoratorComponent",
10461059
"description": "",
1047-
"selector": "bs-datepicker-day-view",
1060+
"selector": "[bsDatepickerDayDecorator]",
10481061
"inputs": [
10491062
{
10501063
"name": "day",
10511064
"type": "DayViewModel",
10521065
"description": ""
10531066
}
10541067
],
1055-
"outputs": [
1056-
{
1057-
"name": "onHover",
1058-
"description": ""
1059-
},
1060-
{
1061-
"name": "onSelect",
1062-
"description": ""
1063-
}
1064-
],
1068+
"outputs": [],
10651069
"properties": [],
10661070
"methods": []
10671071
},

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"demo.docs": "node scripts/docs/get-doc.js",
1010
"demo.serve": "run-s build link demo.docs demo.build lite-server",
1111
"demo.gh-pages": "run-s build demo.docs demo.build demo.deploy",
12-
"demo.build": "ng build -prod --aot && npm run generate-bs4",
12+
"demo.build": "ng build -prod --aot --build-optimizer && npm run generate-bs4",
1313
"demo.deploy": "gh-pages -d demo/dist",
1414
"demo-beta-deploy": "gh-pages -d demo/dist -r git@github.com:valorkin/ngx-bootstrap.git -b gh-pages",
1515
"link": "ngm link -p src --here",
@@ -55,8 +55,7 @@
5555
"url": "https://github.com/valor-software/ngx-bootstrap/issues"
5656
},
5757
"homepage": "https://github.com/valor-software/ngx-bootstrap#readme",
58-
"dependencies": {
59-
},
58+
"dependencies": {},
6059
"peerDependencies": {
6160
"@angular/common": "^2.3.1 || >=4.0.0",
6261
"@angular/compiler": "^2.3.1 || >=4.0.0",

src/bs-moment/format-functions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Locale } from './locale/locale.class';
2-
import { DateFormatterFn } from '../datepicker/models/index';
32
import { zeroFill } from './utils';
43
import { isFunction } from './utils/type-checks';
4+
import { DateFormatterFn } from '../datepicker/models/index';
55

6-
export let formatFunctions: {[key:string]: (date: Date, locale: Locale) => string} = {};
6+
export let formatFunctions: { [key: string]: (date: Date, locale: Locale) => string } = {};
77
export let formatTokenFunctions: { [key: string]: DateFormatterFn } = {};
88

99
export const formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
@@ -13,14 +13,14 @@ export const formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DD
1313
// ordinal: 'Mo'
1414
// callback: function () { this.month() + 1 }
1515
export function addFormatToken(token: string,
16-
padded: {[key: number]: any},
16+
padded: { [key: number]: any },
1717
ordinal: string,
1818
callback: DateFormatterFn): void {
1919
let func: DateFormatterFn = callback;
2020
if (token) {
2121
formatTokenFunctions[token] = func;
2222
}
23-
if (padded as {[key: number]: any}) {
23+
if (padded as { [key: number]: any }) {
2424
let key = padded[0] as string;
2525
formatTokenFunctions[key] = function (date: Date, format: string, locale?: Locale): string {
2626
return zeroFill(func.apply(null, arguments), padded[1] as number, padded[2] as boolean);

src/bs-moment/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import { formatFunctions, makeFormatFunction } from './format-functions';
88
import './locale';
9+
import './units';
910
import { Locale } from './locale/locale.class';
1011
import { getLocale } from './locale/locales.service';
11-
import './units';
1212
import { isDateValid } from './utils/type-checks';
1313

1414
export function formatDate(date: Date, format: string, locale = 'en'): string {

src/bs-moment/i18n/ar.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// author : Ahmed Elkhatib
55
// author : forabi https://github.com/forabi
66

7+
import { LocaleData } from '../locale/locale.class';
8+
79
const symbolMap: { [key: string]: string } = {
810
'1': '١',
911
'2': '٢',
@@ -31,22 +33,23 @@ const numberMap: { [key: string]: string } = {
3133
const pluralForm = function (n: number): number {
3234
return n === 0 ? 0 : n === 1 ? 1 : n === 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5;
3335
};
34-
const plurals = {
36+
const plurals: any = {
3537
s: ['أقل من ثانية', 'ثانية واحدة', ['ثانيتان', 'ثانيتين'], '%d ثوان', '%d ثانية', '%d ثانية'],
3638
m: ['أقل من دقيقة', 'دقيقة واحدة', ['دقيقتان', 'دقيقتين'], '%d دقائق', '%d دقيقة', '%d دقيقة'],
3739
h: ['أقل من ساعة', 'ساعة واحدة', ['ساعتان', 'ساعتين'], '%d ساعات', '%d ساعة', '%d ساعة'],
3840
d: ['أقل من يوم', 'يوم واحد', ['يومان', 'يومين'], '%d أيام', '%d يومًا', '%d يوم'],
3941
M: ['أقل من شهر', 'شهر واحد', ['شهران', 'شهرين'], '%d أشهر', '%d شهرا', '%d شهر'],
4042
y: ['أقل من عام', 'عام واحد', ['عامان', 'عامين'], '%d أعوام', '%d عامًا', '%d عام']
4143
};
42-
const pluralize = function (u) {
43-
return function (number, withoutSuffix, string, isFuture) {
44-
const f = pluralForm(number);
45-
let str = plurals[u][pluralForm(number)];
44+
const pluralize = function (u: string) {
45+
return function (num: number, withoutSuffix: boolean/*, string, isFuture*/) {
46+
const f = pluralForm(num);
47+
let str = plurals[u][pluralForm(num)];
4648
if (f === 2) {
4749
str = str[withoutSuffix ? 0 : 1];
4850
}
49-
return str.replace(/%d/i, number);
51+
52+
return str.replace(/%d/i, num);
5053
};
5154
};
5255
const months = [
@@ -64,9 +67,9 @@ const months = [
6467
'كانون الأول ديسمبر'
6568
];
6669

67-
export const arLocale = {
70+
export const ar: LocaleData = {
6871
abbr: 'ar',
69-
months: months,
72+
months,
7073
monthsShort: months,
7174
weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
7275
weekdaysShort: 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'.split('_'),
@@ -81,10 +84,10 @@ export const arLocale = {
8184
LLLL: 'dddd D MMMM YYYY HH:mm'
8285
},
8386
meridiemParse: /ص|م/,
84-
isPM: function (input) {
85-
return 'م' === input;
87+
isPM(input: string): boolean {
88+
return input === 'م';
8689
},
87-
meridiem: function (hour, minute, isLower) {
90+
meridiem(hour: number, minute: number, isLower: boolean): string {
8891
if (hour < 12) {
8992
return 'ص';
9093
} else {
@@ -114,13 +117,13 @@ export const arLocale = {
114117
y: pluralize('y'),
115118
yy: pluralize('y')
116119
},
117-
preparse: function (string) {
118-
return string.replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
120+
preparse(str: string): string {
121+
return str.replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
119122
return numberMap[match];
120123
}).replace(/،/g, ',');
121124
},
122-
postformat: function (string) {
123-
return string.replace(/\d/g, function (match) {
125+
postformat(str: string): string {
126+
return str.replace(/\d/g, function (match) {
124127
return symbolMap[match];
125128
}).replace(/,/g, '،');
126129
},

src/bs-moment/locale/locale.class.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export interface LocaleData {
3131
week?: { dow: number, doy: number };
3232

3333
dayOfMonthOrdinalParse?: RegExp;
34-
ordinal?: (num: number) => string;
35-
postformat?: (num: string) => string;
34+
meridiemParse?: RegExp;
35+
36+
ordinal?(num: number, token?: string): string;
37+
postformat?(num: string): string;
3638
}
3739

3840
export class Locale {
@@ -57,7 +59,7 @@ export class Locale {
5759
}
5860
}
5961

60-
set (config: LocaleData): void {
62+
set(config: LocaleData): void {
6163
for (const i in config) {
6264
if (!config.hasOwnProperty(i)) {
6365
continue;
@@ -99,7 +101,7 @@ export class Locale {
99101
return (this._monthsShort as string[])[getMonth(date)];
100102
}
101103
let key = MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone';
102-
return ((this._monthsShort as any)[key] as string[])[getMonth(date)];
104+
return ((this._monthsShort as any)[key] as string[])[getMonth(date)];
103105
}
104106

105107
// Days of week
@@ -141,6 +143,14 @@ export class Locale {
141143
return this._week.doy;
142144
}
143145

146+
meridiem(hours: number, minutes: number, isLower: boolean): string {
147+
if (hours > 11) {
148+
return isLower ? 'pm' : 'PM';
149+
}
150+
151+
return isLower ? 'am' : 'AM';
152+
}
153+
144154
ordinal(num: number, token?: string): string {
145155
return this._ordinal.replace('%d', num.toString(10));
146156
}

src/bs-moment/locale/locale.defaults.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const defaultLocaleWeek = {
1111
doy : 6 // The week that contains Jan 1st is the first week of the year.
1212
};
1313

14+
export const defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
15+
1416
export const baseConfig: LocaleData = {
1517
// calendar: defaultCalendar,
1618
// longDateFormat: defaultLongDateFormat,
@@ -28,5 +30,5 @@ export const baseConfig: LocaleData = {
2830
weekdaysMin: defaultLocaleWeekdaysMin,
2931
weekdaysShort: defaultLocaleWeekdaysShort,
3032

31-
// meridiemParse: defaultLocaleMeridiemParse
33+
meridiemParse: defaultLocaleMeridiemParse
3234
};

0 commit comments

Comments
 (0)