@midseelee/date-fns-buddhist-adapter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/LICENSE +22 -0
- package/README.md +49 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +465 -0
- package/dist/models/adapters.d.ts +718 -0
- package/dist/models/adapters.js +2 -0
- package/dist/models/fields.d.ts +229 -0
- package/dist/models/fields.js +2 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +4 -0
- package/dist/models/timezone.d.ts +1 -0
- package/dist/models/timezone.js +2 -0
- package/jest.config.ts +15 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ascendcorp
|
|
4
|
+
Copyright (c) 2025 midseelee (fork modifications)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @midseelee/date-fns-buddhist-adapter
|
|
2
|
+
|
|
3
|
+
> Forked from [ascendcorp/date-fns-buddhist-adapter](https://github.com/ascendcorp/date-fns-buddhist-adapter)
|
|
4
|
+
|
|
5
|
+
date-fns adapter with Buddhist years functionality compatible with [MUI-X](https://github.com/mui/mui-x) date-picker.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install @midseelee/date-fns-buddhist-adapter
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @midseelee/date-fns-buddhist-adapter
|
|
13
|
+
# or
|
|
14
|
+
bun add @midseelee/date-fns-buddhist-adapter
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import AdapterDateFns from '@midseelee/date-fns-buddhist-adapter'
|
|
21
|
+
import { LocalizationProvider } from '@mui/x-date-pickers'
|
|
22
|
+
import { DatePicker } from '@mui/x-date-pickers/DatePicker'
|
|
23
|
+
import { thTH } from 'date-fns/locale/th-TH'
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale={thTH}>
|
|
28
|
+
<DatePicker />
|
|
29
|
+
</LocalizationProvider>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Credits
|
|
35
|
+
|
|
36
|
+
This package is forked from [ascendcorp/date-fns-buddhist-adapter](https://github.com/ascendcorp/date-fns-buddhist-adapter)
|
|
37
|
+
|
|
38
|
+
### Special Thanks
|
|
39
|
+
|
|
40
|
+
1. [Ascendcorp](https://github.com/ascendcorp) - Original implementation
|
|
41
|
+
2. [mui-x](https://github.com/mui/mui-x) - MUI X Date Pickers
|
|
42
|
+
3. [date-fns-be](https://github.com/tarzui/date-fns-be) - Buddhist Era utilities
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT License
|
|
47
|
+
|
|
48
|
+
- Copyright (c) 2023 Ascendcorp (original)
|
|
49
|
+
- Copyright (c) 2025 midseelee (fork modifications)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { enUS as defaultLocale } from 'date-fns/locale/en-US';
|
|
2
|
+
import type { AdapterFormats, AdapterOptions, AdapterUnits, FieldFormatTokenMap, MuiPickersAdapter } from './models';
|
|
3
|
+
type DateFnsLocale = typeof defaultLocale;
|
|
4
|
+
export default class AdapterDateFns implements MuiPickersAdapter<Date, DateFnsLocale> {
|
|
5
|
+
isMUIAdapter: boolean;
|
|
6
|
+
isTimezoneCompatible: boolean;
|
|
7
|
+
lib: string;
|
|
8
|
+
locale?: DateFnsLocale;
|
|
9
|
+
formats: AdapterFormats;
|
|
10
|
+
formatTokenMap: FieldFormatTokenMap;
|
|
11
|
+
escapedCharacters: {
|
|
12
|
+
start: string;
|
|
13
|
+
end: string;
|
|
14
|
+
};
|
|
15
|
+
constructor({ locale, formats }?: AdapterOptions<DateFnsLocale, never>);
|
|
16
|
+
is12HourCycleInCurrentLocale: () => boolean;
|
|
17
|
+
expandFormat: (format: string) => string;
|
|
18
|
+
getFormatHelperText: (format: string) => string;
|
|
19
|
+
parseISO: (isoString: string) => Date;
|
|
20
|
+
toISO: (value: Date) => string;
|
|
21
|
+
getCurrentLocaleCode: () => string;
|
|
22
|
+
addSeconds: (value: Date, count: number) => Date;
|
|
23
|
+
addMinutes: (value: Date, count: number) => Date;
|
|
24
|
+
addHours: (value: Date, count: number) => Date;
|
|
25
|
+
addDays: (value: Date, count: number) => Date;
|
|
26
|
+
addWeeks: (value: Date, count: number) => Date;
|
|
27
|
+
addMonths: (value: Date, count: number) => Date;
|
|
28
|
+
addYears: (value: Date, amount: number) => Date;
|
|
29
|
+
isValid: (value: any) => boolean;
|
|
30
|
+
getDiff: (value: Date, comparing: Date | string, unit?: AdapterUnits) => number;
|
|
31
|
+
isAfter: (value: Date, comparing: Date) => boolean;
|
|
32
|
+
isBefore: (value: Date, comparing: Date) => boolean;
|
|
33
|
+
startOfDay: (value: Date) => Date;
|
|
34
|
+
endOfDay: (value: Date) => Date;
|
|
35
|
+
getHours: (value: Date) => number;
|
|
36
|
+
setHours: (value: Date, count: number) => Date;
|
|
37
|
+
setMinutes: (value: Date, count: number) => Date;
|
|
38
|
+
getSeconds: (value: Date) => number;
|
|
39
|
+
setSeconds: (value: Date, count: number) => Date;
|
|
40
|
+
setMilliseconds: (value: Date, milliseconds: number) => Date;
|
|
41
|
+
getMilliseconds: (value: Date) => number;
|
|
42
|
+
isSameDay: (value: Date, comparing: Date) => boolean;
|
|
43
|
+
isSameMonth: (value: Date, comparing: Date) => boolean;
|
|
44
|
+
isSameYear: (value: Date, comparing: Date) => boolean;
|
|
45
|
+
isSameHour: (value: Date, comparing: Date) => boolean;
|
|
46
|
+
startOfMonth: (value: Date) => Date;
|
|
47
|
+
endOfMonth: (value: Date) => Date;
|
|
48
|
+
startOfWeek: (value: Date) => Date;
|
|
49
|
+
endOfWeek: (value: Date) => Date;
|
|
50
|
+
startOfYear: (value: Date) => Date;
|
|
51
|
+
endOfYear: (value: Date) => Date;
|
|
52
|
+
getYear: (value: Date) => number;
|
|
53
|
+
setYear: (value: Date, count: number) => Date;
|
|
54
|
+
date: (value?: any) => Date | null;
|
|
55
|
+
dateWithTimezone: (value: string | null | undefined) => Date | null;
|
|
56
|
+
getTimezone: () => string;
|
|
57
|
+
setTimezone: (value: Date) => Date;
|
|
58
|
+
toJsDate: (value: Date) => Date;
|
|
59
|
+
parse: (value: string, formatString: string) => Date | null;
|
|
60
|
+
format: (date: Date, formatKey: keyof AdapterFormats) => string;
|
|
61
|
+
formatByString: (date: Date, formatString: string) => string;
|
|
62
|
+
isEqual: (date: any, comparing: any) => boolean;
|
|
63
|
+
isNull: (date: Date) => date is never;
|
|
64
|
+
isAfterDay: (date: Date, value: Date) => boolean;
|
|
65
|
+
isBeforeDay: (date: Date, value: Date) => boolean;
|
|
66
|
+
isBeforeYear: (date: Date, value: Date) => boolean;
|
|
67
|
+
isAfterYear: (date: Date, value: Date) => boolean;
|
|
68
|
+
isWithinRange: (date: Date, [start, end]: [Date, Date]) => boolean;
|
|
69
|
+
formatNumber: (numberToFormat: string) => string;
|
|
70
|
+
getMinutes: (date: Date) => number;
|
|
71
|
+
getDate: (value: Date) => number;
|
|
72
|
+
getMonth: (date: Date) => number;
|
|
73
|
+
getDaysInMonth: (date: Date) => number;
|
|
74
|
+
setMonth: (date: Date, count: number) => Date;
|
|
75
|
+
setDate: (value: Date, date: number) => Date;
|
|
76
|
+
getMeridiemText: (ampm: "am" | "pm") => "AM" | "PM";
|
|
77
|
+
getNextMonth: (date: Date) => Date;
|
|
78
|
+
getPreviousMonth: (date: Date) => Date;
|
|
79
|
+
getMonthArray: (date: Date) => Date[];
|
|
80
|
+
mergeDateAndTime: (date: Date, time: Date) => Date;
|
|
81
|
+
getWeekdays: () => string[];
|
|
82
|
+
getWeekArray: (date: Date) => Date[][];
|
|
83
|
+
getWeekNumber: (value: Date) => number;
|
|
84
|
+
getYearRange: (start: Date, end: Date) => Date[];
|
|
85
|
+
}
|
|
86
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { addDays, addHours, addMinutes, addMonths, addSeconds, addWeeks, addYears, differenceInDays, differenceInHours, differenceInMilliseconds, differenceInMinutes, differenceInMonths, differenceInQuarters, differenceInSeconds, differenceInWeeks, differenceInYears, eachDayOfInterval, endOfDay, endOfMonth, endOfWeek, endOfYear, format, formatISO, getDate, getDay, getDaysInMonth, getHours, getMilliseconds, getSeconds, getWeek, getYear, isAfter, isBefore, isEqual, isSameDay, isSameHour, isSameMonth, isSameYear, isValid, isWithinInterval, parse as dateFnsParse, parseISO, setDate, setHours, setMilliseconds, setMinutes, setMonth, setSeconds, setYear, startOfDay, startOfMonth, startOfWeek, startOfYear, } from 'date-fns';
|
|
2
|
+
import { enUS as defaultLocale } from 'date-fns/locale/en-US';
|
|
3
|
+
const formatTokenMap = {
|
|
4
|
+
// Year
|
|
5
|
+
y: { sectionType: 'year', contentType: 'digit', maxLength: 4 },
|
|
6
|
+
yy: 'year',
|
|
7
|
+
yyy: { sectionType: 'year', contentType: 'digit', maxLength: 4 },
|
|
8
|
+
yyyy: { sectionType: 'year', contentType: 'digit', maxLength: 4 },
|
|
9
|
+
// Month
|
|
10
|
+
M: { sectionType: 'month', contentType: 'digit', maxLength: 2 },
|
|
11
|
+
MM: 'month',
|
|
12
|
+
MMMM: { sectionType: 'month', contentType: 'letter' },
|
|
13
|
+
MMM: { sectionType: 'month', contentType: 'letter' },
|
|
14
|
+
L: { sectionType: 'month', contentType: 'digit', maxLength: 2 },
|
|
15
|
+
LL: 'month',
|
|
16
|
+
LLL: { sectionType: 'month', contentType: 'letter' },
|
|
17
|
+
LLLL: { sectionType: 'month', contentType: 'letter' },
|
|
18
|
+
// Day of the month
|
|
19
|
+
d: { sectionType: 'day', contentType: 'digit', maxLength: 2 },
|
|
20
|
+
dd: 'day',
|
|
21
|
+
do: { sectionType: 'day', contentType: 'digit-with-letter' },
|
|
22
|
+
// Day of the week
|
|
23
|
+
E: { sectionType: 'weekDay', contentType: 'letter' },
|
|
24
|
+
EE: { sectionType: 'weekDay', contentType: 'letter' },
|
|
25
|
+
EEE: { sectionType: 'weekDay', contentType: 'letter' },
|
|
26
|
+
EEEE: { sectionType: 'weekDay', contentType: 'letter' },
|
|
27
|
+
EEEEE: { sectionType: 'weekDay', contentType: 'letter' },
|
|
28
|
+
i: { sectionType: 'weekDay', contentType: 'digit', maxLength: 1 },
|
|
29
|
+
ii: 'weekDay',
|
|
30
|
+
iii: { sectionType: 'weekDay', contentType: 'letter' },
|
|
31
|
+
iiii: { sectionType: 'weekDay', contentType: 'letter' },
|
|
32
|
+
e: { sectionType: 'weekDay', contentType: 'digit', maxLength: 1 },
|
|
33
|
+
ee: 'weekDay',
|
|
34
|
+
eee: { sectionType: 'weekDay', contentType: 'letter' },
|
|
35
|
+
eeee: { sectionType: 'weekDay', contentType: 'letter' },
|
|
36
|
+
eeeee: { sectionType: 'weekDay', contentType: 'letter' },
|
|
37
|
+
eeeeee: { sectionType: 'weekDay', contentType: 'letter' },
|
|
38
|
+
c: { sectionType: 'weekDay', contentType: 'digit', maxLength: 1 },
|
|
39
|
+
cc: 'weekDay',
|
|
40
|
+
ccc: { sectionType: 'weekDay', contentType: 'letter' },
|
|
41
|
+
cccc: { sectionType: 'weekDay', contentType: 'letter' },
|
|
42
|
+
ccccc: { sectionType: 'weekDay', contentType: 'letter' },
|
|
43
|
+
cccccc: { sectionType: 'weekDay', contentType: 'letter' },
|
|
44
|
+
// Meridiem
|
|
45
|
+
a: 'meridiem',
|
|
46
|
+
aa: 'meridiem',
|
|
47
|
+
aaa: 'meridiem',
|
|
48
|
+
// Hours
|
|
49
|
+
H: { sectionType: 'hours', contentType: 'digit', maxLength: 2 },
|
|
50
|
+
HH: 'hours',
|
|
51
|
+
h: { sectionType: 'hours', contentType: 'digit', maxLength: 2 },
|
|
52
|
+
hh: 'hours',
|
|
53
|
+
// Minutes
|
|
54
|
+
m: { sectionType: 'minutes', contentType: 'digit', maxLength: 2 },
|
|
55
|
+
mm: 'minutes',
|
|
56
|
+
// Seconds
|
|
57
|
+
s: { sectionType: 'seconds', contentType: 'digit', maxLength: 2 },
|
|
58
|
+
ss: 'seconds',
|
|
59
|
+
};
|
|
60
|
+
const defaultFormats = {
|
|
61
|
+
dayOfMonth: 'd',
|
|
62
|
+
fullDate: 'PP',
|
|
63
|
+
fullDateWithWeekday: 'PPPP',
|
|
64
|
+
fullDateTime: 'PP p',
|
|
65
|
+
fullDateTime12h: 'PP hh:mm aaa',
|
|
66
|
+
fullDateTime24h: 'PP HH:mm',
|
|
67
|
+
fullTime: 'p',
|
|
68
|
+
fullTime12h: 'hh:mm aaa',
|
|
69
|
+
fullTime24h: 'HH:mm',
|
|
70
|
+
hours12h: 'hh',
|
|
71
|
+
hours24h: 'HH',
|
|
72
|
+
keyboardDate: 'P',
|
|
73
|
+
keyboardDateTime: 'P p',
|
|
74
|
+
keyboardDateTime12h: 'P hh:mm aaa',
|
|
75
|
+
keyboardDateTime24h: 'P HH:mm',
|
|
76
|
+
minutes: 'mm',
|
|
77
|
+
month: 'LLLL',
|
|
78
|
+
monthAndDate: 'MMMM d',
|
|
79
|
+
monthAndYear: 'LLLL yyyy',
|
|
80
|
+
monthShort: 'MMM',
|
|
81
|
+
weekday: 'EEEE',
|
|
82
|
+
weekdayShort: 'EEE',
|
|
83
|
+
normalDate: 'd MMMM',
|
|
84
|
+
normalDateWithWeekday: 'EEE, MMM d',
|
|
85
|
+
seconds: 'ss',
|
|
86
|
+
shortDate: 'MMM d',
|
|
87
|
+
year: 'yyyy',
|
|
88
|
+
};
|
|
89
|
+
export default class AdapterDateFns {
|
|
90
|
+
isMUIAdapter = true;
|
|
91
|
+
isTimezoneCompatible = false;
|
|
92
|
+
lib = 'date-fns-buddhist';
|
|
93
|
+
locale;
|
|
94
|
+
formats;
|
|
95
|
+
formatTokenMap = formatTokenMap;
|
|
96
|
+
escapedCharacters = { start: "'", end: "'" };
|
|
97
|
+
constructor({ locale, formats } = {}) {
|
|
98
|
+
this.locale = locale;
|
|
99
|
+
this.formats = { ...defaultFormats, ...formats, meridiem: '' };
|
|
100
|
+
}
|
|
101
|
+
// Note: date-fns input types are more lenient than this adapter, so we need to expose our more
|
|
102
|
+
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
|
|
103
|
+
is12HourCycleInCurrentLocale = () => {
|
|
104
|
+
if (this.locale) {
|
|
105
|
+
return /a/.test(this.locale.formatLong.time({ width: 'short' }));
|
|
106
|
+
}
|
|
107
|
+
// By default date-fns is using en-US locale with am/pm enabled
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
expandFormat = (format) => {
|
|
111
|
+
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
112
|
+
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
|
|
113
|
+
return format
|
|
114
|
+
.match(longFormatRegexp)
|
|
115
|
+
.map((token) => {
|
|
116
|
+
const firstCharacter = token[0];
|
|
117
|
+
if (firstCharacter === 'p' || firstCharacter === 'P') {
|
|
118
|
+
const locale = this.locale || defaultLocale;
|
|
119
|
+
// Use the locale's format function to expand format strings
|
|
120
|
+
return this.formatByString(new Date(), token);
|
|
121
|
+
}
|
|
122
|
+
return token;
|
|
123
|
+
})
|
|
124
|
+
.join('');
|
|
125
|
+
};
|
|
126
|
+
getFormatHelperText = (format) => {
|
|
127
|
+
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
|
|
128
|
+
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
129
|
+
return format
|
|
130
|
+
.match(longFormatRegexp)
|
|
131
|
+
.map((token) => {
|
|
132
|
+
const firstCharacter = token[0];
|
|
133
|
+
if (firstCharacter === 'p' || firstCharacter === 'P') {
|
|
134
|
+
// Use the format function to expand format strings
|
|
135
|
+
return this.formatByString(new Date(), token);
|
|
136
|
+
}
|
|
137
|
+
return token;
|
|
138
|
+
})
|
|
139
|
+
.join('')
|
|
140
|
+
.replace(/(aaa|aa|a)/g, '(a|p)m')
|
|
141
|
+
.toLocaleLowerCase();
|
|
142
|
+
};
|
|
143
|
+
parseISO = (isoString) => {
|
|
144
|
+
return parseISO(isoString);
|
|
145
|
+
};
|
|
146
|
+
toISO = (value) => {
|
|
147
|
+
return formatISO(value, { format: 'extended' });
|
|
148
|
+
};
|
|
149
|
+
getCurrentLocaleCode = () => {
|
|
150
|
+
return this.locale?.code || 'th-Th';
|
|
151
|
+
};
|
|
152
|
+
addSeconds = (value, count) => {
|
|
153
|
+
return addSeconds(value, count);
|
|
154
|
+
};
|
|
155
|
+
addMinutes = (value, count) => {
|
|
156
|
+
return addMinutes(value, count);
|
|
157
|
+
};
|
|
158
|
+
addHours = (value, count) => {
|
|
159
|
+
return addHours(value, count);
|
|
160
|
+
};
|
|
161
|
+
addDays = (value, count) => {
|
|
162
|
+
return addDays(value, count);
|
|
163
|
+
};
|
|
164
|
+
addWeeks = (value, count) => {
|
|
165
|
+
return addWeeks(value, count);
|
|
166
|
+
};
|
|
167
|
+
addMonths = (value, count) => {
|
|
168
|
+
return addMonths(value, count);
|
|
169
|
+
};
|
|
170
|
+
addYears = (value, amount) => {
|
|
171
|
+
return addYears(value, amount);
|
|
172
|
+
};
|
|
173
|
+
isValid = (value) => {
|
|
174
|
+
return isValid(this.date(value));
|
|
175
|
+
};
|
|
176
|
+
getDiff = (value, comparing, unit) => {
|
|
177
|
+
switch (unit) {
|
|
178
|
+
case 'years':
|
|
179
|
+
return differenceInYears(value, this.date(comparing));
|
|
180
|
+
case 'quarters':
|
|
181
|
+
return differenceInQuarters(value, this.date(comparing));
|
|
182
|
+
case 'months':
|
|
183
|
+
return differenceInMonths(value, this.date(comparing));
|
|
184
|
+
case 'weeks':
|
|
185
|
+
return differenceInWeeks(value, this.date(comparing));
|
|
186
|
+
case 'days':
|
|
187
|
+
return differenceInDays(value, this.date(comparing));
|
|
188
|
+
case 'hours':
|
|
189
|
+
return differenceInHours(value, this.date(comparing));
|
|
190
|
+
case 'minutes':
|
|
191
|
+
return differenceInMinutes(value, this.date(comparing));
|
|
192
|
+
case 'seconds':
|
|
193
|
+
return differenceInSeconds(value, this.date(comparing));
|
|
194
|
+
default: {
|
|
195
|
+
return differenceInMilliseconds(value, this.date(comparing));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
isAfter = (value, comparing) => {
|
|
200
|
+
return isAfter(value, comparing);
|
|
201
|
+
};
|
|
202
|
+
isBefore = (value, comparing) => {
|
|
203
|
+
return isBefore(value, comparing);
|
|
204
|
+
};
|
|
205
|
+
startOfDay = (value) => {
|
|
206
|
+
return startOfDay(value);
|
|
207
|
+
};
|
|
208
|
+
endOfDay = (value) => {
|
|
209
|
+
return endOfDay(value);
|
|
210
|
+
};
|
|
211
|
+
getHours = (value) => {
|
|
212
|
+
return getHours(value);
|
|
213
|
+
};
|
|
214
|
+
setHours = (value, count) => {
|
|
215
|
+
return setHours(value, count);
|
|
216
|
+
};
|
|
217
|
+
setMinutes = (value, count) => {
|
|
218
|
+
return setMinutes(value, count);
|
|
219
|
+
};
|
|
220
|
+
getSeconds = (value) => {
|
|
221
|
+
return getSeconds(value);
|
|
222
|
+
};
|
|
223
|
+
setSeconds = (value, count) => {
|
|
224
|
+
return setSeconds(value, count);
|
|
225
|
+
};
|
|
226
|
+
setMilliseconds = (value, milliseconds) => {
|
|
227
|
+
return setMilliseconds(value, milliseconds);
|
|
228
|
+
};
|
|
229
|
+
getMilliseconds = (value) => {
|
|
230
|
+
return getMilliseconds(value);
|
|
231
|
+
};
|
|
232
|
+
isSameDay = (value, comparing) => {
|
|
233
|
+
return isSameDay(value, comparing);
|
|
234
|
+
};
|
|
235
|
+
isSameMonth = (value, comparing) => {
|
|
236
|
+
return isSameMonth(value, comparing);
|
|
237
|
+
};
|
|
238
|
+
isSameYear = (value, comparing) => {
|
|
239
|
+
return isSameYear(value, comparing);
|
|
240
|
+
};
|
|
241
|
+
isSameHour = (value, comparing) => {
|
|
242
|
+
return isSameHour(value, comparing);
|
|
243
|
+
};
|
|
244
|
+
startOfMonth = (value) => {
|
|
245
|
+
return startOfMonth(value);
|
|
246
|
+
};
|
|
247
|
+
endOfMonth = (value) => {
|
|
248
|
+
return endOfMonth(value);
|
|
249
|
+
};
|
|
250
|
+
startOfWeek = (value) => {
|
|
251
|
+
return startOfWeek(value, { locale: this.locale });
|
|
252
|
+
};
|
|
253
|
+
endOfWeek = (value) => {
|
|
254
|
+
return endOfWeek(value, { locale: this.locale });
|
|
255
|
+
};
|
|
256
|
+
startOfYear = (value) => {
|
|
257
|
+
return startOfYear(value);
|
|
258
|
+
};
|
|
259
|
+
endOfYear = (value) => {
|
|
260
|
+
return endOfYear(value);
|
|
261
|
+
};
|
|
262
|
+
getYear = (value) => {
|
|
263
|
+
return getYear(value);
|
|
264
|
+
};
|
|
265
|
+
setYear = (value, count) => {
|
|
266
|
+
return setYear(value, count);
|
|
267
|
+
};
|
|
268
|
+
date = (value) => {
|
|
269
|
+
//
|
|
270
|
+
if (typeof value === 'undefined') {
|
|
271
|
+
return new Date();
|
|
272
|
+
}
|
|
273
|
+
if (value === null) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
return new Date(value);
|
|
277
|
+
};
|
|
278
|
+
dateWithTimezone = (value) => {
|
|
279
|
+
return this.date(value);
|
|
280
|
+
};
|
|
281
|
+
getTimezone = () => {
|
|
282
|
+
return 'default';
|
|
283
|
+
};
|
|
284
|
+
setTimezone = (value) => {
|
|
285
|
+
return value;
|
|
286
|
+
};
|
|
287
|
+
toJsDate = (value) => {
|
|
288
|
+
return value;
|
|
289
|
+
};
|
|
290
|
+
parse = (value, formatString) => {
|
|
291
|
+
if (value === '') {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
if ((formatString === 'dd/MM/yyyy' || formatString === 'P') &&
|
|
295
|
+
value.length === 10) {
|
|
296
|
+
const year = parseInt(value.substring(6, 10));
|
|
297
|
+
if (year > 543) {
|
|
298
|
+
const newYear = year - 543;
|
|
299
|
+
const res = value.replace(`${year}`, `${newYear}`);
|
|
300
|
+
return dateFnsParse(res, formatString, new Date(), {
|
|
301
|
+
locale: this.locale,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return dateFnsParse(value, formatString, new Date(), {
|
|
306
|
+
locale: this.locale,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (formatString === 'MM/yyyy' && value.length === 7) {
|
|
311
|
+
const year = parseInt(value.substring(3, 7));
|
|
312
|
+
if (year > 543) {
|
|
313
|
+
const newYear = year - 543;
|
|
314
|
+
const res = value.replace(`${year}`, `${newYear}`);
|
|
315
|
+
return dateFnsParse(res, formatString, new Date(), {
|
|
316
|
+
locale: this.locale,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
return dateFnsParse(value, formatString, new Date(), {
|
|
321
|
+
locale: this.locale,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (formatString === 'yyyy' && value.length === 4) {
|
|
326
|
+
const year = parseInt(value);
|
|
327
|
+
if (year > 543) {
|
|
328
|
+
const newYear = year - 543;
|
|
329
|
+
const res = value.replace(`${year}`, `${newYear}`);
|
|
330
|
+
return dateFnsParse(res, formatString, new Date(), {
|
|
331
|
+
locale: this.locale,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
return dateFnsParse(value, formatString, new Date(), {
|
|
336
|
+
locale: this.locale,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (formatString === 'MM' && value.length === 2) {
|
|
341
|
+
return dateFnsParse(value, formatString, new Date(), {
|
|
342
|
+
locale: this.locale,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
// return dateFnsParse(value, formatString, new Date(), { locale: this.locale });
|
|
347
|
+
};
|
|
348
|
+
format = (date, formatKey) => {
|
|
349
|
+
return this.formatByString(date, this.formats[formatKey]);
|
|
350
|
+
};
|
|
351
|
+
formatByString = (date, formatString) => {
|
|
352
|
+
const christianYear = `${getYear(date)}`;
|
|
353
|
+
const buddhishYear = (parseInt(christianYear) + 543).toString();
|
|
354
|
+
const result = format(date, formatString, { locale: this.locale });
|
|
355
|
+
return result.replace(christianYear, buddhishYear);
|
|
356
|
+
};
|
|
357
|
+
isEqual = (date, comparing) => {
|
|
358
|
+
if (date === null && comparing === null) {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
return isEqual(date, comparing);
|
|
362
|
+
};
|
|
363
|
+
isNull = (date) => {
|
|
364
|
+
return date === null;
|
|
365
|
+
};
|
|
366
|
+
isAfterDay = (date, value) => {
|
|
367
|
+
return isAfter(date, endOfDay(value));
|
|
368
|
+
};
|
|
369
|
+
isBeforeDay = (date, value) => {
|
|
370
|
+
return isBefore(date, startOfDay(value));
|
|
371
|
+
};
|
|
372
|
+
isBeforeYear = (date, value) => {
|
|
373
|
+
return isBefore(date, startOfYear(value));
|
|
374
|
+
};
|
|
375
|
+
isAfterYear = (date, value) => {
|
|
376
|
+
return isAfter(date, endOfYear(value));
|
|
377
|
+
};
|
|
378
|
+
isWithinRange = (date, [start, end]) => {
|
|
379
|
+
return isWithinInterval(date, { start, end });
|
|
380
|
+
};
|
|
381
|
+
formatNumber = (numberToFormat) => {
|
|
382
|
+
return numberToFormat;
|
|
383
|
+
};
|
|
384
|
+
getMinutes = (date) => {
|
|
385
|
+
return date.getMinutes();
|
|
386
|
+
};
|
|
387
|
+
getDate = (value) => {
|
|
388
|
+
return getDate(value);
|
|
389
|
+
};
|
|
390
|
+
getMonth = (date) => {
|
|
391
|
+
return date.getMonth();
|
|
392
|
+
};
|
|
393
|
+
getDaysInMonth = (date) => {
|
|
394
|
+
return getDaysInMonth(date);
|
|
395
|
+
};
|
|
396
|
+
setMonth = (date, count) => {
|
|
397
|
+
return setMonth(date, count);
|
|
398
|
+
};
|
|
399
|
+
setDate = (value, date) => {
|
|
400
|
+
return setDate(value, date);
|
|
401
|
+
};
|
|
402
|
+
getMeridiemText = (ampm) => {
|
|
403
|
+
return ampm === 'am' ? 'AM' : 'PM';
|
|
404
|
+
};
|
|
405
|
+
getNextMonth = (date) => {
|
|
406
|
+
return addMonths(date, 1);
|
|
407
|
+
};
|
|
408
|
+
getPreviousMonth = (date) => {
|
|
409
|
+
return addMonths(date, -1);
|
|
410
|
+
};
|
|
411
|
+
getMonthArray = (date) => {
|
|
412
|
+
const firstMonth = startOfYear(date);
|
|
413
|
+
const monthArray = [firstMonth];
|
|
414
|
+
while (monthArray.length < 12) {
|
|
415
|
+
const prevMonth = monthArray[monthArray.length - 1];
|
|
416
|
+
monthArray.push(this.getNextMonth(prevMonth));
|
|
417
|
+
}
|
|
418
|
+
return monthArray;
|
|
419
|
+
};
|
|
420
|
+
mergeDateAndTime = (date, time) => {
|
|
421
|
+
return this.setSeconds(this.setMinutes(this.setHours(date, this.getHours(time)), this.getMinutes(time)), this.getSeconds(time));
|
|
422
|
+
};
|
|
423
|
+
getWeekdays = () => {
|
|
424
|
+
const now = new Date();
|
|
425
|
+
return eachDayOfInterval({
|
|
426
|
+
start: startOfWeek(now, { locale: this.locale }),
|
|
427
|
+
end: endOfWeek(now, { locale: this.locale }),
|
|
428
|
+
}).map((day) => this.formatByString(day, 'EEEEEE'));
|
|
429
|
+
};
|
|
430
|
+
getWeekArray = (date) => {
|
|
431
|
+
const start = startOfWeek(startOfMonth(date), { locale: this.locale });
|
|
432
|
+
const end = endOfWeek(endOfMonth(date), { locale: this.locale });
|
|
433
|
+
let count = 0;
|
|
434
|
+
let current = start;
|
|
435
|
+
const nestedWeeks = [];
|
|
436
|
+
let lastDay = null;
|
|
437
|
+
while (isBefore(current, end)) {
|
|
438
|
+
const weekNumber = Math.floor(count / 7);
|
|
439
|
+
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
|
|
440
|
+
const day = getDay(current);
|
|
441
|
+
if (lastDay !== day) {
|
|
442
|
+
lastDay = day;
|
|
443
|
+
nestedWeeks[weekNumber].push(current);
|
|
444
|
+
count += 1;
|
|
445
|
+
}
|
|
446
|
+
current = addDays(current, 1);
|
|
447
|
+
}
|
|
448
|
+
return nestedWeeks;
|
|
449
|
+
};
|
|
450
|
+
getWeekNumber = (value) => {
|
|
451
|
+
return getWeek(value, { locale: this.locale });
|
|
452
|
+
};
|
|
453
|
+
getYearRange = (start, end) => {
|
|
454
|
+
const startDate = startOfYear(start);
|
|
455
|
+
const endDate = endOfYear(end);
|
|
456
|
+
const years = [];
|
|
457
|
+
let current = startDate;
|
|
458
|
+
while (isBefore(current, endDate)) {
|
|
459
|
+
years.push(current);
|
|
460
|
+
current = addYears(current, 1);
|
|
461
|
+
}
|
|
462
|
+
return years;
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
//# sourceMappingURL=index.js.map
|