Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit b835923

Browse files
Fix merge
1 parent 1139efa commit b835923

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed

src/modules/datepicker/helpers/date-fns.ts

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,70 @@ import { IDatepickerLocaleValues } from "../../../behaviors/localization/interna
22
import { format, parse } from "date-fns";
33
import * as defaultLocale from "date-fns/locale/en-US";
44

5-
<<<<<<< HEAD
65
interface IDateFnsLocaleValues {
7-
[name: string]: string[];
6+
[name:string]:string[];
87
}
98

109
interface IDateFnsHelperOptions {
11-
type?: string;
10+
type:string;
1211
}
1312

14-
type DateFnsHelper<U, T> = (value: U, options: IDateFnsHelperOptions) => T;
15-
=======
16-
interface IDateFnsLocaleValues { [name:string]:string[]; }
17-
interface IDateFnsHelperOptions { type:string; }
1813
type DateFnsHelper<U, T> = (value:U, options:IDateFnsHelperOptions) => T;
19-
>>>>>>> 4c27b73... move element-closest to polyfills.ts
2014
type DateFnsWeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
2115

2216
interface IDateFnsCustomLocale {
23-
localize: {
24-
weekday: DateFnsHelper<number, string>;
25-
weekdays: DateFnsHelper<IDateFnsHelperOptions, string[]>;
26-
month: DateFnsHelper<number, string>;
27-
months: DateFnsHelper<IDateFnsHelperOptions, string[]>;
28-
timeOfDay: DateFnsHelper<number, string>;
29-
timesOfDay: DateFnsHelper<IDateFnsHelperOptions, string[]>;
17+
localize:{
18+
weekday:DateFnsHelper<number, string>;
19+
weekdays:DateFnsHelper<IDateFnsHelperOptions, string[]>;
20+
month:DateFnsHelper<number, string>;
21+
months:DateFnsHelper<IDateFnsHelperOptions, string[]>;
22+
timeOfDay:DateFnsHelper<number, string>;
23+
timesOfDay:DateFnsHelper<IDateFnsHelperOptions, string[]>;
3024
};
31-
match: {
32-
weekdays: DateFnsHelper<string, RegExpMatchArray | null>;
33-
weekday?: DateFnsHelper<RegExpMatchArray, number>;
34-
months: DateFnsHelper<string, RegExpMatchArray | null>;
35-
month?: DateFnsHelper<RegExpMatchArray, number>;
36-
timesOfDay: DateFnsHelper<string, RegExpMatchArray | null>;
37-
timeOfDay?: DateFnsHelper<RegExpMatchArray, number>;
25+
match:{
26+
weekdays:DateFnsHelper<string, RegExpMatchArray | null>;
27+
weekday?:DateFnsHelper<RegExpMatchArray, number>;
28+
months:DateFnsHelper<string, RegExpMatchArray | null>;
29+
month?:DateFnsHelper<RegExpMatchArray, number>;
30+
timesOfDay:DateFnsHelper<string, RegExpMatchArray | null>;
31+
timeOfDay?:DateFnsHelper<RegExpMatchArray, number>;
3832
};
39-
options?: {
40-
weekStartsOn?: number;
33+
options?:{
34+
weekStartsOn?:number;
4135
};
4236
}
4337

44-
function buildLocalizeFn(values: IDateFnsLocaleValues,
45-
defaultType: string,
46-
indexCallback?: (oldIndex: number) => number): DateFnsHelper<number, string> {
38+
function buildLocalizeFn(values:IDateFnsLocaleValues,
39+
defaultType:string,
40+
indexCallback?:(oldIndex:number) => number):DateFnsHelper<number, string> {
4741

48-
return (dirtyIndex: number, {type} = {type: defaultType}) => {
42+
return (dirtyIndex:number, {type} = {type: defaultType}) => {
4943
const index = indexCallback ? indexCallback(dirtyIndex) : dirtyIndex;
5044
return values[`${type}`][index];
5145
};
5246
}
5347

54-
function buildLocalizeArrayFn(values: IDateFnsLocaleValues, defaultType: string): DateFnsHelper<IDateFnsHelperOptions, string[]> {
48+
function buildLocalizeArrayFn(values:IDateFnsLocaleValues, defaultType:string):DateFnsHelper<IDateFnsHelperOptions, string[]> {
5549
return ({type} = {type: defaultType}) => values[`${type}`];
5650
}
5751

58-
function buildMatchFn(patterns: IDateFnsLocaleValues, defaultType: string): DateFnsHelper<string, RegExpMatchArray | null> {
52+
function buildMatchFn(patterns:IDateFnsLocaleValues, defaultType:string):DateFnsHelper<string, RegExpMatchArray | null> {
5953
return (dirtyString, {type} = {type: defaultType}) =>
6054
dirtyString.match(`^(${patterns[`${type}`].join("|")})`);
6155
}
6256

63-
function buildParseFn(patterns: IDateFnsLocaleValues, defaultType: string): DateFnsHelper<RegExpMatchArray, number> {
57+
function buildParseFn(patterns:IDateFnsLocaleValues, defaultType:string):DateFnsHelper<RegExpMatchArray, number> {
6458
return ([, result], {type} = {type: defaultType}) =>
6559
(patterns[`${type}`] || patterns[defaultType])
6660
.map(p => new RegExp(`^${p}`))
6761
.findIndex(pattern => pattern.test(result));
6862
}
6963

7064
export class DateFnsParser {
71-
private _weekStartsOn: DateFnsWeekStartsOn;
72-
private _locale: IDateFnsCustomLocale;
65+
private _weekStartsOn:DateFnsWeekStartsOn;
66+
private _locale:IDateFnsCustomLocale;
7367

74-
constructor(locale: IDatepickerLocaleValues) {
68+
constructor(locale:IDatepickerLocaleValues) {
7569
this._weekStartsOn = locale.firstDayOfWeek as DateFnsWeekStartsOn;
7670

7771
const weekdayValues = {
@@ -104,7 +98,7 @@ export class DateFnsParser {
10498
weekdays: buildLocalizeArrayFn(weekdayValues, "long"),
10599
month: buildLocalizeFn(monthValues, "long"),
106100
months: buildLocalizeArrayFn(monthValues, "long"),
107-
timeOfDay: buildLocalizeFn(timeOfDayValues, "long", (hours: number) => {
101+
timeOfDay: buildLocalizeFn(timeOfDayValues, "long", (hours:number) => {
108102
return hours / 12 >= 1 ? 1 : 0;
109103
}),
110104
timesOfDay: buildLocalizeArrayFn(timeOfDayValues, "long")
@@ -123,18 +117,18 @@ export class DateFnsParser {
123117
};
124118
}
125119

126-
private get _config(): any {
120+
private get _config():any {
127121
return {
128122
weekStartsOn: this._weekStartsOn,
129123
locale: this._locale
130124
};
131125
}
132126

133-
public format(d: Date, f: string): string {
127+
public format(d:Date, f:string):string {
134128
return format(d, f, this._config);
135129
}
136130

137-
public parse(dS: string, f: string, bD: Date): Date {
131+
public parse(dS:string, f:string, bD:Date):Date {
138132
return parse(dS, f, bD, this._config);
139133
}
140134
}

0 commit comments

Comments
 (0)