@momo-kits/calendar 0.80.9 → 0.81.1
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/CalendarPro.tsx +15 -11
- package/Day.tsx +1 -24
- package/HeaderControl.tsx +2 -2
- package/LunarDateConverter.ts +43 -27
- package/LunarService.ts +16 -10
- package/MonthList.tsx +7 -6
- package/TabHeader.tsx +4 -4
- package/Util.ts +31 -24
- package/holidayData.ts +3 -1
- package/index.tsx +11 -17
- package/package.json +1 -1
- package/styles.ts +1 -1
- package/types.ts +21 -18
package/CalendarPro.tsx
CHANGED
|
@@ -13,12 +13,15 @@ import MonthList from './MonthList';
|
|
|
13
13
|
import HeaderControl from './HeaderControl';
|
|
14
14
|
import LunarDateConverter from './LunarDateConverter';
|
|
15
15
|
import Util from './Util';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
CalendarProProps,
|
|
18
|
+
CalendarProState,
|
|
19
|
+
HeaderControlRef,
|
|
20
|
+
Holidays,
|
|
21
|
+
} from './types';
|
|
17
22
|
import {ContainerContext} from './index';
|
|
18
23
|
import styles from './styles';
|
|
19
24
|
|
|
20
|
-
const widthScreen = Dimensions.get('window').width;
|
|
21
|
-
|
|
22
25
|
export default class CalendarPro extends Component<
|
|
23
26
|
CalendarProProps,
|
|
24
27
|
CalendarProState
|
|
@@ -50,6 +53,7 @@ export default class CalendarPro extends Component<
|
|
|
50
53
|
holidays: [],
|
|
51
54
|
ownUpdate: false,
|
|
52
55
|
};
|
|
56
|
+
// @ts-ignore
|
|
53
57
|
this.converter = new LunarDateConverter();
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -117,16 +121,16 @@ export default class CalendarPro extends Component<
|
|
|
117
121
|
this.maxDate = max;
|
|
118
122
|
};
|
|
119
123
|
|
|
120
|
-
onChoose = (day:
|
|
124
|
+
onChoose = (day: Moment.Moment) => {
|
|
121
125
|
const {startDate, tabSelected} = this.state;
|
|
122
126
|
const {isDoubleDateMode, onDateChange} = this.props;
|
|
123
127
|
if (isDoubleDateMode) {
|
|
124
128
|
if (tabSelected === 1) {
|
|
125
|
-
if (startDate && day >= startDate) {
|
|
129
|
+
if (startDate && day >= Moment(startDate)) {
|
|
126
130
|
this.ownSetState({
|
|
127
131
|
endDate: day,
|
|
128
132
|
});
|
|
129
|
-
} else if (startDate && day < startDate) {
|
|
133
|
+
} else if (startDate && day < Moment(startDate)) {
|
|
130
134
|
this.ownSetState({
|
|
131
135
|
startDate: day,
|
|
132
136
|
endDate: null,
|
|
@@ -149,7 +153,7 @@ export default class CalendarPro extends Component<
|
|
|
149
153
|
};
|
|
150
154
|
|
|
151
155
|
executeProcessAfterScrollCalendar = (date: Moment.Moment, key: any) => {
|
|
152
|
-
const holidays:
|
|
156
|
+
const holidays: any[] = Object.values(
|
|
153
157
|
Util.getHolidaysInMonth(Moment(date)),
|
|
154
158
|
);
|
|
155
159
|
const {showLunar} = this.state;
|
|
@@ -180,9 +184,9 @@ export default class CalendarPro extends Component<
|
|
|
180
184
|
};
|
|
181
185
|
|
|
182
186
|
setDoubleDateAndTabIndex = (
|
|
183
|
-
firstDate: Moment.Moment | undefined,
|
|
184
|
-
secondDate
|
|
185
|
-
tabSelected
|
|
187
|
+
firstDate: Moment.Moment | Date | undefined,
|
|
188
|
+
secondDate?: Moment.Moment | Date | undefined | null,
|
|
189
|
+
tabSelected?: any,
|
|
186
190
|
) => {
|
|
187
191
|
this.ownSetState({
|
|
188
192
|
startDate: firstDate ? Moment(firstDate) : null,
|
|
@@ -194,7 +198,7 @@ export default class CalendarPro extends Component<
|
|
|
194
198
|
toggleLunarDate = () => {
|
|
195
199
|
const {showLunar, holidays} = this.state;
|
|
196
200
|
const {onCallbackCalendar} = this.props;
|
|
197
|
-
let data:
|
|
201
|
+
let data: Holidays[] = [];
|
|
198
202
|
const nextStateShowLunar = !showLunar;
|
|
199
203
|
if (!nextStateShowLunar) {
|
|
200
204
|
data = holidays?.filter(item => !item.lunar || item.mixedLabel);
|
package/Day.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import {ContainerContext} from './index';
|
|
|
13
13
|
import styles from './styles';
|
|
14
14
|
|
|
15
15
|
class Day extends Component<DayProps> {
|
|
16
|
-
isFocus
|
|
16
|
+
isFocus?: boolean;
|
|
17
17
|
isValid?: boolean;
|
|
18
18
|
isMid?: boolean;
|
|
19
19
|
isStart?: boolean;
|
|
@@ -40,29 +40,6 @@ class Day extends Component<DayProps> {
|
|
|
40
40
|
onChoose && onChoose(date);
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
findHoliday = (
|
|
44
|
-
date: {date: () => any; month: () => number},
|
|
45
|
-
holidays: any[],
|
|
46
|
-
) => {
|
|
47
|
-
if (date && holidays && holidays.length > 0) {
|
|
48
|
-
const day = date.date();
|
|
49
|
-
const month = date.month() + 1;
|
|
50
|
-
return holidays.find(item => item.day === day && item.month === month);
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
checkHoliday = (
|
|
56
|
-
date: {date: () => any; month: () => number},
|
|
57
|
-
holidays: any[],
|
|
58
|
-
) => {
|
|
59
|
-
const holiday = this.findHoliday(date, holidays);
|
|
60
|
-
return {
|
|
61
|
-
solarHoliday: !!(holiday && !holiday.lunar),
|
|
62
|
-
lunarHoliday: !!(holiday && holiday.lunar),
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
43
|
statusCheck = (props?: DayProps) => {
|
|
67
44
|
const {
|
|
68
45
|
startDate,
|
package/HeaderControl.tsx
CHANGED
|
@@ -32,8 +32,8 @@ const HeaderControl: ForwardRefRenderFunction<
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
if (info && info.date) {
|
|
35
|
-
const headerFormat = `${translate(
|
|
36
|
-
Util.mapMonth(info.date.month() + 1),
|
|
35
|
+
const headerFormat = `${translate?.(
|
|
36
|
+
Util.mapMonth(info.date.month() + 1) || '',
|
|
37
37
|
)}/${info.date.year()}`;
|
|
38
38
|
return (
|
|
39
39
|
<View style={styles.headerControlContainer}>
|
package/LunarDateConverter.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-bitwise */
|
|
4
|
-
function Lunar() {
|
|
1
|
+
function Lunar(this: any) {
|
|
5
2
|
this.isleap = false;
|
|
6
3
|
this.lunarDay = 0;
|
|
7
4
|
this.lunarMonth = 0;
|
|
8
5
|
this.lunarYear = 0;
|
|
9
6
|
}
|
|
10
7
|
|
|
11
|
-
function Solar() {
|
|
8
|
+
function Solar(this: any) {
|
|
12
9
|
this.solarDay = 0;
|
|
13
10
|
this.solarMonth = 0;
|
|
14
11
|
this.solarYear = 0;
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
function LunarSolarConverter() {
|
|
14
|
+
function LunarSolarConverter(this: any) {
|
|
18
15
|
this.lunar_month_days = [
|
|
19
16
|
1887, 0x1694, 0x16aa, 0x4ad5, 0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a, 0x1d2a,
|
|
20
17
|
0xd54, 0x75aa, 0x156a, 0x1096d, 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a,
|
|
@@ -79,7 +76,7 @@ function LunarSolarConverter() {
|
|
|
79
76
|
/**
|
|
80
77
|
* @return {number}
|
|
81
78
|
*/
|
|
82
|
-
this.GetBitInt = function (data, length, shift) {
|
|
79
|
+
this.GetBitInt = function (data: number, length: number, shift: number) {
|
|
83
80
|
return (data & (((1 << length) - 1) << shift)) >> shift;
|
|
84
81
|
};
|
|
85
82
|
|
|
@@ -87,40 +84,54 @@ function LunarSolarConverter() {
|
|
|
87
84
|
/**
|
|
88
85
|
* @return {number}
|
|
89
86
|
*/
|
|
90
|
-
this.SolarToInt = function (y, m, d) {
|
|
87
|
+
this.SolarToInt = function (y: number, m: number, d: number) {
|
|
91
88
|
m = (m + 9) % 12;
|
|
92
|
-
y = parseInt(y) - parseInt(m / 10);
|
|
89
|
+
y = parseInt(String(y)) - parseInt(String(m / 10));
|
|
93
90
|
return (
|
|
94
91
|
365 * y +
|
|
95
|
-
parseInt(y / 4) -
|
|
96
|
-
parseInt(y / 100) +
|
|
97
|
-
parseInt(y / 400) +
|
|
98
|
-
parseInt((m * 306 + 5) / 10) +
|
|
92
|
+
parseInt(String(y / 4)) -
|
|
93
|
+
parseInt(String(y / 100)) +
|
|
94
|
+
parseInt(String(y / 400)) +
|
|
95
|
+
parseInt(String((m * 306 + 5) / 10)) +
|
|
99
96
|
(d - 1)
|
|
100
97
|
);
|
|
101
98
|
};
|
|
102
99
|
|
|
103
|
-
this.SolarFromInt = function (g) {
|
|
104
|
-
let y = parseInt((10000 * g + 14780) / 3652425);
|
|
100
|
+
this.SolarFromInt = function (g: number) {
|
|
101
|
+
let y = parseInt(String((10000 * g + 14780) / 3652425));
|
|
105
102
|
let ddd =
|
|
106
|
-
g -
|
|
103
|
+
g -
|
|
104
|
+
(365 * y +
|
|
105
|
+
parseInt(String(y / 4)) -
|
|
106
|
+
parseInt(String(y / 100)) +
|
|
107
|
+
parseInt(String(y / 400)));
|
|
107
108
|
if (ddd < 0) {
|
|
108
109
|
y--;
|
|
109
110
|
ddd =
|
|
110
|
-
g -
|
|
111
|
+
g -
|
|
112
|
+
(365 * y +
|
|
113
|
+
parseInt(String(y / 4)) -
|
|
114
|
+
parseInt(String(y / 100)) +
|
|
115
|
+
parseInt(String(y / 400)));
|
|
111
116
|
}
|
|
112
|
-
const mi = parseInt((100 * ddd + 52) / 3060);
|
|
117
|
+
const mi = parseInt(String((100 * ddd + 52) / 3060));
|
|
113
118
|
const mm = ((mi + 2) % 12) + 1;
|
|
114
|
-
y += parseInt((mi + 2) / 12);
|
|
115
|
-
const dd = ddd - parseInt((mi * 306 + 5) / 10) + 1;
|
|
119
|
+
y += parseInt(String((mi + 2) / 12));
|
|
120
|
+
const dd = ddd - parseInt(String((mi * 306 + 5) / 10)) + 1;
|
|
121
|
+
// @ts-ignore
|
|
116
122
|
const solar = new Solar();
|
|
117
|
-
solar.solarYear = parseInt(y);
|
|
118
|
-
solar.solarMonth = parseInt(mm);
|
|
119
|
-
solar.solarDay = parseInt(dd);
|
|
123
|
+
solar.solarYear = parseInt(String(y));
|
|
124
|
+
solar.solarMonth = parseInt(String(mm));
|
|
125
|
+
solar.solarDay = parseInt(String(dd));
|
|
120
126
|
return solar;
|
|
121
127
|
};
|
|
122
128
|
|
|
123
|
-
this.LunarToSolar = function (lunar
|
|
129
|
+
this.LunarToSolar = function (lunar: {
|
|
130
|
+
lunarYear: number;
|
|
131
|
+
isleap: any;
|
|
132
|
+
lunarMonth: number;
|
|
133
|
+
lunarDay: number;
|
|
134
|
+
}) {
|
|
124
135
|
const days =
|
|
125
136
|
this.lunar_month_days[lunar.lunarYear - this.lunar_month_days[0]];
|
|
126
137
|
const leap = this.GetBitInt(days, 4, 13);
|
|
@@ -147,7 +158,12 @@ function LunarSolarConverter() {
|
|
|
147
158
|
return this.SolarFromInt(this.SolarToInt(y, m, d) + offset - 1);
|
|
148
159
|
};
|
|
149
160
|
|
|
150
|
-
this.SolarToLunar = function (solar
|
|
161
|
+
this.SolarToLunar = function (solar: {
|
|
162
|
+
solarYear: number;
|
|
163
|
+
solarMonth: number;
|
|
164
|
+
solarDay: number;
|
|
165
|
+
}) {
|
|
166
|
+
// @ts-ignore
|
|
151
167
|
const lunar = new Lunar();
|
|
152
168
|
let index = solar.solarYear - this.solar_1_1[0];
|
|
153
169
|
const data =
|
|
@@ -179,7 +195,7 @@ function LunarSolarConverter() {
|
|
|
179
195
|
break;
|
|
180
196
|
}
|
|
181
197
|
}
|
|
182
|
-
const lunarD = parseInt(offset);
|
|
198
|
+
const lunarD = parseInt(String(offset));
|
|
183
199
|
lunar.lunarYear = lunarY;
|
|
184
200
|
lunar.lunarMonth = lunarM;
|
|
185
201
|
lunar.isleap = false;
|
|
@@ -195,4 +211,4 @@ function LunarSolarConverter() {
|
|
|
195
211
|
};
|
|
196
212
|
}
|
|
197
213
|
|
|
198
|
-
|
|
214
|
+
export default LunarSolarConverter;
|
package/LunarService.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const removeFractionalPart = number
|
|
1
|
+
const removeFractionalPart = (number: string | number) =>
|
|
2
|
+
parseInt(String(number));
|
|
2
3
|
|
|
3
4
|
/* Compute the (integral) Julian day number of day dd/mm/yyyy, i.e., the number
|
|
4
5
|
* of days between 1/1/4713 BC (Julian calendar) and dd/mm/yyyy.
|
|
5
6
|
* Formula from http://www.tondering.dk/claus/calendar.html
|
|
6
7
|
*/
|
|
7
|
-
const jdFromDate = (dd, mm, yy) => {
|
|
8
|
+
const jdFromDate = (dd: number, mm: number, yy: number) => {
|
|
8
9
|
let a, y, m, jd;
|
|
9
10
|
a = removeFractionalPart((14 - mm) / 12);
|
|
10
11
|
y = yy + 4800 - a;
|
|
@@ -29,7 +30,7 @@ const jdFromDate = (dd, mm, yy) => {
|
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
/* Convert a Julian day number to day/month/year. Parameter jd is an integer */
|
|
32
|
-
const jdToDate = jd => {
|
|
33
|
+
const jdToDate = (jd: number) => {
|
|
33
34
|
let a, b, c, d, e, m, day, month, year;
|
|
34
35
|
if (jd > 2299160) {
|
|
35
36
|
// After 5/10/1582, Gregorian calendar
|
|
@@ -54,7 +55,7 @@ const jdToDate = jd => {
|
|
|
54
55
|
* Returns a floating number, e.g., 2415079.9758617813 for k=2 or 2414961.935157746 for k=-2
|
|
55
56
|
* Algorithm from: "Astronomical Algorithms" by Jean Meeus, 1998
|
|
56
57
|
*/
|
|
57
|
-
const NewMoon = k => {
|
|
58
|
+
const NewMoon = (k: number) => {
|
|
58
59
|
let T, T2, T3, dr, Jd1, M, Mpr, F, C1, deltat, JdNew;
|
|
59
60
|
T = k / 1236.85; // Time in Julian centuries from 1900 January 0.5
|
|
60
61
|
T2 = T * T;
|
|
@@ -100,7 +101,7 @@ const NewMoon = k => {
|
|
|
100
101
|
* Parameter: floating number jdn, the number of days since 1/1/4713 BC noon
|
|
101
102
|
* Algorithm from: "Astronomical Algorithms" by Jean Meeus, 1998
|
|
102
103
|
*/
|
|
103
|
-
const SunLongitude = jdn => {
|
|
104
|
+
const SunLongitude = (jdn: number) => {
|
|
104
105
|
let T, T2, dr, M, L0, DL, L;
|
|
105
106
|
T = (jdn - 2451545.0) / 36525; // Time in Julian centuries from 2000-01-01 12:00:00 GMT
|
|
106
107
|
T2 = T * T;
|
|
@@ -124,7 +125,7 @@ const SunLongitude = jdn => {
|
|
|
124
125
|
* From the day after March equinox and the 1st major term after March equinox, 0 is returned.
|
|
125
126
|
* After that, return 1, 2, 3 ...
|
|
126
127
|
*/
|
|
127
|
-
const getSunLongitude = (dayNumber, timeZone) => {
|
|
128
|
+
const getSunLongitude = (dayNumber: number, timeZone: number) => {
|
|
128
129
|
return removeFractionalPart(
|
|
129
130
|
(SunLongitude(dayNumber - 0.5 - timeZone / 24) / Math.PI) * 6,
|
|
130
131
|
);
|
|
@@ -133,12 +134,12 @@ const getSunLongitude = (dayNumber, timeZone) => {
|
|
|
133
134
|
/* Compute the day of the k-th new moon in the given time zone.
|
|
134
135
|
* The time zone if the time difference between local time and UTC: 7.0 for UTC+7:00
|
|
135
136
|
*/
|
|
136
|
-
const getNewMoonDay = (k, timeZone) => {
|
|
137
|
+
const getNewMoonDay = (k: number, timeZone: number) => {
|
|
137
138
|
return removeFractionalPart(NewMoon(k) + 0.5 + timeZone / 24);
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
/* Find the day that starts the luner month 11 of the given year for the given time zone */
|
|
141
|
-
const getLunarMonth11 = (yy, timeZone) => {
|
|
142
|
+
const getLunarMonth11 = (yy: number, timeZone: number) => {
|
|
142
143
|
let k, off, nm, sunLong;
|
|
143
144
|
//off = jdFromDate(31, 12, yy) - 2415021.076998695;
|
|
144
145
|
off = jdFromDate(31, 12, yy) - 2415021;
|
|
@@ -152,7 +153,7 @@ const getLunarMonth11 = (yy, timeZone) => {
|
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
/* Find the index of the leap month after the month starting on the day a11. */
|
|
155
|
-
const getLeapMonthOffset = (a11, timeZone) => {
|
|
156
|
+
const getLeapMonthOffset = (a11: number, timeZone: number) => {
|
|
156
157
|
let k, last, arc, i;
|
|
157
158
|
k = removeFractionalPart((a11 - 2415021.076998695) / 29.530588853 + 0.5);
|
|
158
159
|
last = 0;
|
|
@@ -167,7 +168,12 @@ const getLeapMonthOffset = (a11, timeZone) => {
|
|
|
167
168
|
};
|
|
168
169
|
|
|
169
170
|
/* Comvert solar date dd/mm/yyyy to the corresponding lunar date */
|
|
170
|
-
export const convertSolar2Lunar = (
|
|
171
|
+
export const convertSolar2Lunar = (
|
|
172
|
+
dd: number,
|
|
173
|
+
mm: number,
|
|
174
|
+
yy: number,
|
|
175
|
+
timeZone: number,
|
|
176
|
+
) => {
|
|
171
177
|
let k,
|
|
172
178
|
dayNumber,
|
|
173
179
|
monthStart,
|
package/MonthList.tsx
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import React, {Component
|
|
1
|
+
import React, {Component} from 'react';
|
|
2
2
|
import {FlatList, Platform} from 'react-native';
|
|
3
3
|
import moment from 'moment';
|
|
4
4
|
import Moment from 'moment';
|
|
5
5
|
import Month from './Month';
|
|
6
6
|
import LunarDateConverter from './LunarDateConverter';
|
|
7
|
-
import {MonthListProps, MonthListState} from './types';
|
|
7
|
+
import {Holidays, MonthListProps, MonthListState} from './types';
|
|
8
8
|
import {ContainerContext} from './index';
|
|
9
9
|
import {scaleSize, Spacing} from '@momo-kits/foundation';
|
|
10
10
|
|
|
11
11
|
const MAX_RENDER_PER_BATCH = Platform.OS === 'android' ? 1 : 12;
|
|
12
12
|
|
|
13
|
+
// @ts-ignore
|
|
13
14
|
const converter = new LunarDateConverter();
|
|
14
15
|
export default class MonthList extends Component<
|
|
15
16
|
MonthListProps,
|
|
@@ -20,7 +21,7 @@ export default class MonthList extends Component<
|
|
|
20
21
|
currentScrollIndex;
|
|
21
22
|
list;
|
|
22
23
|
heightStyle;
|
|
23
|
-
holidays;
|
|
24
|
+
holidays?: Holidays[] = [];
|
|
24
25
|
currentKey: any;
|
|
25
26
|
|
|
26
27
|
constructor(props: MonthListProps) {
|
|
@@ -61,9 +62,9 @@ export default class MonthList extends Component<
|
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
checkRange = (
|
|
64
|
-
date
|
|
65
|
-
start
|
|
66
|
-
end
|
|
65
|
+
date?: moment.Moment | null,
|
|
66
|
+
start?: moment.Moment | null,
|
|
67
|
+
end?: moment.Moment | null,
|
|
67
68
|
) => {
|
|
68
69
|
if (!date || !start) return false;
|
|
69
70
|
if (!end) {
|
package/TabHeader.tsx
CHANGED
|
@@ -16,7 +16,7 @@ export default class TabHeader extends React.Component<
|
|
|
16
16
|
TabHeaderState
|
|
17
17
|
> {
|
|
18
18
|
label;
|
|
19
|
-
defaultDate;
|
|
19
|
+
defaultDate: Moment.Moment;
|
|
20
20
|
|
|
21
21
|
static contextType = ApplicationContext;
|
|
22
22
|
constructor(props: TabHeaderProps) {
|
|
@@ -25,7 +25,7 @@ export default class TabHeader extends React.Component<
|
|
|
25
25
|
active: props.activeTab,
|
|
26
26
|
};
|
|
27
27
|
this.label = props.label;
|
|
28
|
-
this.defaultDate = props.date ? Moment(props.date) :
|
|
28
|
+
this.defaultDate = props.date ? Moment(props.date) : Moment();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
onChangeTab = () => {
|
|
@@ -33,9 +33,9 @@ export default class TabHeader extends React.Component<
|
|
|
33
33
|
onChangeTab?.(id);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
updateView = (date
|
|
36
|
+
updateView = (date?: Moment.Moment | Date | null, activeTab?: boolean) => {
|
|
37
37
|
this.setState({
|
|
38
|
-
date: date ? Moment(date) :
|
|
38
|
+
date: date ? Moment(date) : Moment(),
|
|
39
39
|
active: activeTab,
|
|
40
40
|
});
|
|
41
41
|
};
|
package/Util.ts
CHANGED
|
@@ -47,20 +47,20 @@ const I18N_MAP = {
|
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const Solar = momentDate => ({
|
|
50
|
+
const Solar = (momentDate: moment.Moment) => ({
|
|
51
51
|
solarDay: momentDate.date(),
|
|
52
52
|
solarMonth: momentDate.month() + 1,
|
|
53
53
|
solarYear: momentDate.year(),
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
const formatYYYYMMDD = (dd, mm, yyyy) =>
|
|
56
|
+
const formatYYYYMMDD = (dd: number, mm: number, yyyy: any) =>
|
|
57
57
|
`${yyyy}-${mm < 10 ? `0${mm}` : mm}-${dd < 10 ? `0${dd}` : dd}`;
|
|
58
58
|
|
|
59
|
-
const formatDDMM = (dd, mm) =>
|
|
59
|
+
const formatDDMM = (dd: number, mm: number) =>
|
|
60
60
|
`${dd < 10 ? `0${dd}` : dd}/${mm < 10 ? `0${mm}` : mm}`;
|
|
61
61
|
|
|
62
|
-
const groupHolidaysByDate = holidays => {
|
|
63
|
-
const groupedHolidays = {};
|
|
62
|
+
const groupHolidaysByDate = (holidays: any[]) => {
|
|
63
|
+
const groupedHolidays: {[key: string]: string[]} = {};
|
|
64
64
|
if (holidays && holidays.length > 0) {
|
|
65
65
|
holidays.forEach(item => {
|
|
66
66
|
const {day, month, lunar, label} = item;
|
|
@@ -90,7 +90,7 @@ const groupHolidaysByDate = holidays => {
|
|
|
90
90
|
return groupedHolidays;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const sortByDate = arr => {
|
|
93
|
+
const sortByDate = (arr: any[]) => {
|
|
94
94
|
if (arr && arr.length > 1) {
|
|
95
95
|
arr.sort((a, b) => {
|
|
96
96
|
if (a.month > b.month || (a.month === b.month && a.day > b.day)) {
|
|
@@ -103,7 +103,7 @@ const sortByDate = arr => {
|
|
|
103
103
|
return groupHolidaysByDate(arr);
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
const Utils = {
|
|
107
107
|
WEEKDAYS: ['T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'CN'],
|
|
108
108
|
|
|
109
109
|
WEEKDAYSFROMMOMENT: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
|
|
@@ -137,12 +137,12 @@ module.exports = {
|
|
|
137
137
|
|
|
138
138
|
MAX_COLUMNS: 7,
|
|
139
139
|
|
|
140
|
-
mapWeeKDate(i) {
|
|
140
|
+
mapWeeKDate(i: number) {
|
|
141
141
|
const date = ['', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
142
142
|
return date[i];
|
|
143
143
|
},
|
|
144
144
|
|
|
145
|
-
mapMonth(i) {
|
|
145
|
+
mapMonth(i: number) {
|
|
146
146
|
const month = new Map([
|
|
147
147
|
[1, 'jan'],
|
|
148
148
|
[2, 'feb'],
|
|
@@ -160,7 +160,7 @@ module.exports = {
|
|
|
160
160
|
return month.get(i);
|
|
161
161
|
},
|
|
162
162
|
|
|
163
|
-
mapMonthShorten(i) {
|
|
163
|
+
mapMonthShorten(i: number) {
|
|
164
164
|
const month = new Map([
|
|
165
165
|
[1, 'Jan'],
|
|
166
166
|
[2, 'Feb'],
|
|
@@ -178,40 +178,45 @@ module.exports = {
|
|
|
178
178
|
return month.get(i);
|
|
179
179
|
},
|
|
180
180
|
|
|
181
|
-
getDaysInMonth(month, year) {
|
|
181
|
+
getDaysInMonth(month: number, year: number) {
|
|
182
182
|
const lastDayOfMonth = new Date(year, month + 1, 0);
|
|
183
183
|
return lastDayOfMonth.getDate();
|
|
184
184
|
},
|
|
185
185
|
|
|
186
|
-
getHolidaysInMonth(headerInfo) {
|
|
186
|
+
getHolidaysInMonth(headerInfo: moment.Moment) {
|
|
187
187
|
if (headerInfo) {
|
|
188
188
|
const today = moment();
|
|
189
|
+
// @ts-ignore
|
|
189
190
|
const converter = new LunarDateConverter();
|
|
190
191
|
const startDate = moment(headerInfo).startOf('month');
|
|
191
192
|
const endDate = moment(headerInfo).endOf('month');
|
|
192
193
|
const minLunarDate = converter.SolarToLunar(Solar(startDate));
|
|
193
194
|
const maxLunarDate = converter.SolarToLunar(Solar(endDate));
|
|
194
|
-
const holidays = [];
|
|
195
|
+
const holidays: any[] = [];
|
|
195
196
|
const currentYear =
|
|
196
197
|
minLunarDate.lunarYear !== maxLunarDate.lunarYear
|
|
197
198
|
? [minLunarDate.lunarYear, maxLunarDate.lunarYear]
|
|
198
199
|
: minLunarDate.lunarYear;
|
|
199
200
|
|
|
200
201
|
// Handle Solar holidays
|
|
202
|
+
// @ts-ignore
|
|
201
203
|
if (holiday.solar[headerInfo.month() + 1]) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
holiday.solar[headerInfo.month() + 1].forEach(
|
|
206
|
+
(date: {month: number; day: any}) => {
|
|
207
|
+
const dateAsMoment = moment({
|
|
208
|
+
year: headerInfo.year(),
|
|
209
|
+
month: date.month - 1,
|
|
210
|
+
date: date.day,
|
|
211
|
+
});
|
|
212
|
+
if (dateAsMoment.isSameOrAfter(today, 'date')) {
|
|
213
|
+
holidays.push(date);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
);
|
|
212
217
|
}
|
|
213
218
|
|
|
214
|
-
holiday.lunar.forEach(item => {
|
|
219
|
+
holiday.lunar.forEach((item: {lunarDay: any; lunarMonth: any}) => {
|
|
215
220
|
if (currentYear instanceof Array) {
|
|
216
221
|
const solar1 = converter.LunarToSolar({
|
|
217
222
|
lunarDay: item.lunarDay,
|
|
@@ -284,3 +289,5 @@ module.exports = {
|
|
|
284
289
|
},
|
|
285
290
|
I18N_MAP,
|
|
286
291
|
};
|
|
292
|
+
|
|
293
|
+
export default Utils;
|
package/holidayData.ts
CHANGED
package/index.tsx
CHANGED
|
@@ -11,28 +11,22 @@ import {
|
|
|
11
11
|
} from '@momo-kits/foundation';
|
|
12
12
|
import CalendarPro from './CalendarPro';
|
|
13
13
|
import TabHeader from './TabHeader';
|
|
14
|
-
import {
|
|
15
|
-
CalendarProps,
|
|
16
|
-
CalendarProRef,
|
|
17
|
-
CalendarState,
|
|
18
|
-
TabHeaderRef,
|
|
19
|
-
} from './types';
|
|
14
|
+
import {CalendarProps, CalendarState} from './types';
|
|
20
15
|
import styles from './styles';
|
|
21
16
|
|
|
22
17
|
const DOUBLE = 'doubleDate';
|
|
23
|
-
const SINGLE = 'singleDate';
|
|
24
18
|
|
|
25
19
|
export const ContainerContext = createContext({width: 0, height: 0});
|
|
26
20
|
|
|
27
21
|
class Calendar extends Component<CalendarProps, CalendarState> {
|
|
28
22
|
static contextType = ApplicationContext;
|
|
29
|
-
doubleDate;
|
|
23
|
+
doubleDate: any;
|
|
30
24
|
tabSelected;
|
|
31
|
-
selectedDate;
|
|
32
|
-
calendarPicker: RefObject<
|
|
33
|
-
cellHeader1: RefObject<
|
|
34
|
-
cellHeader2: RefObject<
|
|
35
|
-
cellHeaderSingle: RefObject<
|
|
25
|
+
selectedDate: moment.Moment;
|
|
26
|
+
calendarPicker: RefObject<CalendarPro>;
|
|
27
|
+
cellHeader1: RefObject<TabHeader>;
|
|
28
|
+
cellHeader2: RefObject<TabHeader>;
|
|
29
|
+
cellHeaderSingle: RefObject<TabHeader>;
|
|
36
30
|
constructor(props: CalendarProps) {
|
|
37
31
|
super(props);
|
|
38
32
|
this.doubleDate = props.doubleDate
|
|
@@ -53,10 +47,10 @@ class Calendar extends Component<CalendarProps, CalendarState> {
|
|
|
53
47
|
isDoubleDateMode: props.mode === DOUBLE,
|
|
54
48
|
containerWidth: Dimensions.get('window').width,
|
|
55
49
|
};
|
|
56
|
-
this.calendarPicker = React.createRef<
|
|
57
|
-
this.cellHeader1 = React.createRef();
|
|
58
|
-
this.cellHeader2 = React.createRef();
|
|
59
|
-
this.cellHeaderSingle = React.createRef();
|
|
50
|
+
this.calendarPicker = React.createRef<CalendarPro>();
|
|
51
|
+
this.cellHeader1 = React.createRef<TabHeader>();
|
|
52
|
+
this.cellHeader2 = React.createRef<TabHeader>();
|
|
53
|
+
this.cellHeaderSingle = React.createRef<TabHeader>();
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
componentDidMount() {
|
package/package.json
CHANGED
package/styles.ts
CHANGED
package/types.ts
CHANGED
|
@@ -4,6 +4,9 @@ import {ViewStyle} from 'react-native';
|
|
|
4
4
|
export type Holidays = {
|
|
5
5
|
solar: object;
|
|
6
6
|
lunar: any[];
|
|
7
|
+
mixedLabel?: string;
|
|
8
|
+
day?: number;
|
|
9
|
+
month?: number;
|
|
7
10
|
};
|
|
8
11
|
|
|
9
12
|
export type PriceInfo = {
|
|
@@ -25,15 +28,15 @@ export type PriceListData = {
|
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
export type CalendarProProps = {
|
|
28
|
-
startDate:
|
|
29
|
-
endDate:
|
|
30
|
-
maxDate
|
|
31
|
-
minDate
|
|
31
|
+
startDate: Moment.Moment;
|
|
32
|
+
endDate: Moment.Moment;
|
|
33
|
+
maxDate?: Date;
|
|
34
|
+
minDate?: Date;
|
|
32
35
|
isShowLunar?: boolean;
|
|
33
36
|
selectedDate: Moment.Moment;
|
|
34
37
|
isDoubleDateMode: boolean;
|
|
35
38
|
onDateChange: (day: Moment.Moment) => void;
|
|
36
|
-
priceList
|
|
39
|
+
priceList?: PriceListData;
|
|
37
40
|
labelFrom?: string;
|
|
38
41
|
labelTo?: string;
|
|
39
42
|
isHideLabel?: boolean;
|
|
@@ -44,23 +47,23 @@ export type CalendarProProps = {
|
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
export type CalendarProState = {
|
|
47
|
-
startDate:
|
|
48
|
-
endDate:
|
|
50
|
+
startDate: Moment.Moment;
|
|
51
|
+
endDate: Moment.Moment;
|
|
49
52
|
showLunar?: boolean;
|
|
50
53
|
tabSelected?: number;
|
|
51
|
-
holidays:
|
|
54
|
+
holidays: Holidays[];
|
|
52
55
|
ownUpdate?: boolean;
|
|
53
56
|
temp?: any;
|
|
54
57
|
headerKey?: string;
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
export type DoubleDate = {
|
|
58
|
-
first:
|
|
59
|
-
second:
|
|
61
|
+
first: Moment.Moment;
|
|
62
|
+
second: Moment.Moment;
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
export type CalendarProps = {
|
|
63
|
-
doubleDate
|
|
66
|
+
doubleDate: DoubleDate;
|
|
64
67
|
selectedDate?: Moment.Moment;
|
|
65
68
|
mode?: 'doubleDate' | 'singleDate';
|
|
66
69
|
id?: number;
|
|
@@ -114,16 +117,16 @@ export type HeaderControlProps = {
|
|
|
114
117
|
export type MonthListProps = {
|
|
115
118
|
isDoubleDateMode: boolean;
|
|
116
119
|
selectedDate: Moment.Moment;
|
|
117
|
-
holidays?:
|
|
120
|
+
holidays?: Holidays[];
|
|
118
121
|
priceList?: Record<string, any>;
|
|
119
122
|
minDate: Moment.Moment;
|
|
120
123
|
maxDate: Moment.Moment;
|
|
121
|
-
startDate:
|
|
122
|
-
endDate:
|
|
124
|
+
startDate: Moment.Moment;
|
|
125
|
+
endDate: Moment.Moment;
|
|
123
126
|
isShowLunar: boolean;
|
|
124
127
|
tabSelected?: number;
|
|
125
128
|
today: Moment.Moment;
|
|
126
|
-
onChoose: (day:
|
|
129
|
+
onChoose: (day: Moment.Moment) => void;
|
|
127
130
|
onScrollCalendar?: (info: {
|
|
128
131
|
date: Moment.Moment;
|
|
129
132
|
key: string;
|
|
@@ -144,7 +147,7 @@ export type MonthListRef = {
|
|
|
144
147
|
|
|
145
148
|
export type MonthProps = {
|
|
146
149
|
dateList: any[];
|
|
147
|
-
holidays
|
|
150
|
+
holidays?: Holidays[];
|
|
148
151
|
priceListDate?: Record<string, PriceInfo>;
|
|
149
152
|
month?: any;
|
|
150
153
|
minDate: Moment.Moment;
|
|
@@ -174,11 +177,11 @@ export type DayProps = {
|
|
|
174
177
|
price?: string;
|
|
175
178
|
isBestPrice?: boolean;
|
|
176
179
|
havePriceList: boolean;
|
|
177
|
-
isDisabled
|
|
180
|
+
isDisabled?: boolean;
|
|
178
181
|
};
|
|
179
182
|
|
|
180
183
|
export type TabHeaderState = {
|
|
181
|
-
active
|
|
184
|
+
active?: boolean;
|
|
182
185
|
date?: Moment.Moment;
|
|
183
186
|
};
|
|
184
187
|
|