@momo-kits/calendar 0.0.74-beta → 0.72.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.
@@ -9,18 +9,30 @@ const jdFromDate = (dd, mm, yy) => {
9
9
  a = removeFractionalPart((14 - mm) / 12);
10
10
  y = yy + 4800 - a;
11
11
  m = mm + 12 * a - 3;
12
- jd = dd + removeFractionalPart((153 * m + 2) / 5) + 365 * y + removeFractionalPart(y / 4) - removeFractionalPart(y / 100) +
13
- removeFractionalPart(y / 400) - 32045;
12
+ jd =
13
+ dd +
14
+ removeFractionalPart((153 * m + 2) / 5) +
15
+ 365 * y +
16
+ removeFractionalPart(y / 4) -
17
+ removeFractionalPart(y / 100) +
18
+ removeFractionalPart(y / 400) -
19
+ 32045;
14
20
  if (jd < 2299161) {
15
- jd = dd + removeFractionalPart((153 * m + 2) / 5) + 365 * y + removeFractionalPart(y / 4) - 32083;
21
+ jd =
22
+ dd +
23
+ removeFractionalPart((153 * m + 2) / 5) +
24
+ 365 * y +
25
+ removeFractionalPart(y / 4) -
26
+ 32083;
16
27
  }
17
28
  return jd;
18
- }
29
+ };
19
30
 
20
31
  /* Convert a Julian day number to day/month/year. Parameter jd is an integer */
21
- const jdToDate = (jd) => {
32
+ const jdToDate = jd => {
22
33
  let a, b, c, d, e, m, day, month, year;
23
- if (jd > 2299160) { // After 5/10/1582, Gregorian calendar
34
+ if (jd > 2299160) {
35
+ // After 5/10/1582, Gregorian calendar
24
36
  a = jd + 32044;
25
37
  b = removeFractionalPart((4 * a + 3) / 146097);
26
38
  c = a - removeFractionalPart((b * 146097) / 4);
@@ -35,66 +47,76 @@ const jdToDate = (jd) => {
35
47
  month = m + 3 - 12 * removeFractionalPart(m / 10);
36
48
  year = b * 100 + d - 4800 + removeFractionalPart(m / 10);
37
49
  return [day, month, year];
38
- }
50
+ };
39
51
 
40
52
  /* Compute the time of the k-th new moon after the new moon of 1/1/1900 13:52 UCT
41
53
  * (measured as the number of days since 1/1/4713 BC noon UCT, e.g., 2451545.125 is 1/1/2000 15:00 UTC).
42
54
  * Returns a floating number, e.g., 2415079.9758617813 for k=2 or 2414961.935157746 for k=-2
43
55
  * Algorithm from: "Astronomical Algorithms" by Jean Meeus, 1998
44
56
  */
45
- const NewMoon = (k) => {
57
+ const NewMoon = k => {
46
58
  let T, T2, T3, dr, Jd1, M, Mpr, F, C1, deltat, JdNew;
47
59
  T = k / 1236.85; // Time in Julian centuries from 1900 January 0.5
48
60
  T2 = T * T;
49
61
  T3 = T2 * T;
50
62
  dr = Math.PI / 180;
51
63
  Jd1 = 2415020.75933 + 29.53058868 * k + 0.0001178 * T2 - 0.000000155 * T3;
52
- Jd1 = Jd1 + 0.00033 *
53
- Math.sin((166.56 + 132.87 * T - 0.009173 * T2) * dr); // Mean new moon
54
- M = 359.2242 + 29.10535608 * k - 0.0000333 * T2 -
55
- 0.00000347 * T3; // Sun's mean anomaly
56
- Mpr = 306.0253 + 385.81691806 * k + 0.0107306 * T2 +
57
- 0.00001236 * T3; // Moon's mean anomaly
58
- F = 21.2964 + 390.67050646 * k - 0.0016528 * T2 -
59
- 0.00000239 * T3; // Moon's argument of latitude
60
- C1 = (0.1734 - 0.000393 * T) * Math.sin(M * dr) + 0.0021 * Math.sin(2 * dr * M);
64
+ Jd1 = Jd1 + 0.00033 * Math.sin((166.56 + 132.87 * T - 0.009173 * T2) * dr); // Mean new moon
65
+ M = 359.2242 + 29.10535608 * k - 0.0000333 * T2 - 0.00000347 * T3; // Sun's mean anomaly
66
+ Mpr = 306.0253 + 385.81691806 * k + 0.0107306 * T2 + 0.00001236 * T3; // Moon's mean anomaly
67
+ F = 21.2964 + 390.67050646 * k - 0.0016528 * T2 - 0.00000239 * T3; // Moon's argument of latitude
68
+ C1 =
69
+ (0.1734 - 0.000393 * T) * Math.sin(M * dr) + 0.0021 * Math.sin(2 * dr * M);
61
70
  C1 = C1 - 0.4068 * Math.sin(Mpr * dr) + 0.0161 * Math.sin(dr * 2 * Mpr);
62
71
  C1 = C1 - 0.0004 * Math.sin(dr * 3 * Mpr);
63
72
  C1 = C1 + 0.0104 * Math.sin(dr * 2 * F) - 0.0051 * Math.sin(dr * (M + Mpr));
64
- C1 = C1 - 0.0074 * Math.sin(dr * (M - Mpr)) + 0.0004 * Math.sin(dr * (2 * F + M));
65
- C1 = C1 - 0.0004 * Math.sin(dr * (2 * F - M)) - 0.0006 * Math.sin(dr * (2 * F + Mpr));
66
- C1 = C1 + 0.0010 * Math.sin(dr * (2 * F - Mpr)) + 0.0005 * Math.sin(dr * (2 * Mpr + M));
73
+ C1 =
74
+ C1 -
75
+ 0.0074 * Math.sin(dr * (M - Mpr)) +
76
+ 0.0004 * Math.sin(dr * (2 * F + M));
77
+ C1 =
78
+ C1 -
79
+ 0.0004 * Math.sin(dr * (2 * F - M)) -
80
+ 0.0006 * Math.sin(dr * (2 * F + Mpr));
81
+ C1 =
82
+ C1 +
83
+ 0.001 * Math.sin(dr * (2 * F - Mpr)) +
84
+ 0.0005 * Math.sin(dr * (2 * Mpr + M));
67
85
  if (T < -11) {
68
- deltat = 0.001 + 0.000839 * T + 0.0002261 * T2 - 0.00000845 * T3 -
86
+ deltat =
87
+ 0.001 +
88
+ 0.000839 * T +
89
+ 0.0002261 * T2 -
90
+ 0.00000845 * T3 -
69
91
  0.000000081 * T * T3;
70
92
  } else {
71
93
  deltat = -0.000278 + 0.000265 * T + 0.000262 * T2;
72
94
  }
73
95
  JdNew = Jd1 + C1 - deltat;
74
96
  return JdNew;
75
- }
97
+ };
76
98
 
77
99
  /* Compute the longitude of the sun at any time.
78
100
  * Parameter: floating number jdn, the number of days since 1/1/4713 BC noon
79
101
  * Algorithm from: "Astronomical Algorithms" by Jean Meeus, 1998
80
102
  */
81
- const SunLongitude = (jdn) => {
103
+ const SunLongitude = jdn => {
82
104
  let T, T2, dr, M, L0, DL, L;
83
- T = (jdn - 2451545.0) /
84
- 36525; // Time in Julian centuries from 2000-01-01 12:00:00 GMT
105
+ T = (jdn - 2451545.0) / 36525; // Time in Julian centuries from 2000-01-01 12:00:00 GMT
85
106
  T2 = T * T;
86
107
  dr = Math.PI / 180; // degree to radian
87
- M = 357.52910 + 35999.05030 * T - 0.0001559 * T2 -
88
- 0.00000048 * T * T2; // mean anomaly, degree
108
+ M = 357.5291 + 35999.0503 * T - 0.0001559 * T2 - 0.00000048 * T * T2; // mean anomaly, degree
89
109
  L0 = 280.46645 + 36000.76983 * T + 0.0003032 * T2; // mean longitude, degree
90
- DL = (1.914600 - 0.004817 * T - 0.000014 * T2) * Math.sin(dr * M);
91
- DL = DL + (0.019993 - 0.000101 * T) * Math.sin(dr * 2 * M) +
92
- 0.000290 * Math.sin(dr * 3 * M);
110
+ DL = (1.9146 - 0.004817 * T - 0.000014 * T2) * Math.sin(dr * M);
111
+ DL =
112
+ DL +
113
+ (0.019993 - 0.000101 * T) * Math.sin(dr * 2 * M) +
114
+ 0.00029 * Math.sin(dr * 3 * M);
93
115
  L = L0 + DL; // true longitude, degree
94
116
  L = L * dr;
95
- L = L - Math.PI * 2 * (Math.sin(L / (Math.PI * 2))); // Normalize to (0, 2*PI)
117
+ L = L - Math.PI * 2 * Math.sin(L / (Math.PI * 2)); // Normalize to (0, 2*PI)
96
118
  return L;
97
- }
119
+ };
98
120
 
99
121
  /* Compute sun position at midnight of the day with the given Julian day number.
100
122
  * The time zone if the time difference between local time and UTC: 7.0 for UTC+7:00.
@@ -103,15 +125,17 @@ const SunLongitude = (jdn) => {
103
125
  * After that, return 1, 2, 3 ...
104
126
  */
105
127
  const getSunLongitude = (dayNumber, timeZone) => {
106
- return removeFractionalPart(SunLongitude(dayNumber - 0.5 - timeZone / 24) / Math.PI * 6);
107
- }
128
+ return removeFractionalPart(
129
+ (SunLongitude(dayNumber - 0.5 - timeZone / 24) / Math.PI) * 6,
130
+ );
131
+ };
108
132
 
109
133
  /* Compute the day of the k-th new moon in the given time zone.
110
134
  * The time zone if the time difference between local time and UTC: 7.0 for UTC+7:00
111
135
  */
112
136
  const getNewMoonDay = (k, timeZone) => {
113
137
  return removeFractionalPart(NewMoon(k) + 0.5 + timeZone / 24);
114
- }
138
+ };
115
139
 
116
140
  /* Find the day that starts the luner month 11 of the given year for the given time zone */
117
141
  const getLunarMonth11 = (yy, timeZone) => {
@@ -125,7 +149,7 @@ const getLunarMonth11 = (yy, timeZone) => {
125
149
  nm = getNewMoonDay(k - 1, timeZone);
126
150
  }
127
151
  return nm;
128
- }
152
+ };
129
153
 
130
154
  /* Find the index of the leap month after the month starting on the day a11. */
131
155
  const getLeapMonthOffset = (a11, timeZone) => {
@@ -140,11 +164,18 @@ const getLeapMonthOffset = (a11, timeZone) => {
140
164
  arc = getSunLongitude(getNewMoonDay(k + i, timeZone), timeZone);
141
165
  } while (arc !== last && i < 14);
142
166
  return i - 1;
143
- }
167
+ };
144
168
 
145
169
  /* Comvert solar date dd/mm/yyyy to the corresponding lunar date */
146
170
  export const convertSolar2Lunar = (dd, mm, yy, timeZone) => {
147
- let k, dayNumber, monthStart, a11, b11, lunarDay, lunarMonth, lunarYear,
171
+ let k,
172
+ dayNumber,
173
+ monthStart,
174
+ a11,
175
+ b11,
176
+ lunarDay,
177
+ lunarMonth,
178
+ lunarYear,
148
179
  lunarLeap;
149
180
  dayNumber = jdFromDate(dd, mm, yy);
150
181
  k = removeFractionalPart((dayNumber - 2415021.076998695) / 29.530588853);
@@ -181,5 +212,10 @@ export const convertSolar2Lunar = (dd, mm, yy, timeZone) => {
181
212
  if (lunarMonth >= 11 && diff < 4) {
182
213
  lunarYear -= 1;
183
214
  }
184
- return { lunarDay, lunarMonth: lunarMonth, lunarYear, isleap: lunarLeap};
185
- }
215
+ return {
216
+ lunarDay,
217
+ lunarMonth: lunarMonth,
218
+ lunarYear,
219
+ isleap: lunarLeap,
220
+ };
221
+ };
@@ -1,80 +1,89 @@
1
- import React, { PureComponent } from 'react';
1
+ import React, {PureComponent} from 'react';
2
2
 
3
- import {
4
- View
5
- } from 'react-native';
3
+ import {View, Dimensions} from 'react-native';
6
4
  import moment from 'moment';
7
5
  import Day from '../Day';
6
+ import {Spacing, ScaleSize} from '@momo-kits/core-v2';
7
+
8
+ const {width} = Dimensions.get('window');
8
9
 
9
10
  export default class Month extends PureComponent {
10
- constructor(props) {
11
- super(props);
12
- const { dateList } = props;
13
- this.rowArray = new Array(dateList.length / 7).fill('');
14
- this.temp = this.rowArray.map((item, i) => dateList.slice(i * 7, i * 7 + 7));
11
+ constructor(props) {
12
+ super(props);
13
+ const {dateList} = props;
14
+ this.rowArray = new Array(dateList.length / 7).fill('');
15
+ this.temp = this.rowArray.map((item, i) =>
16
+ dateList.slice(i * 7, i * 7 + 7),
17
+ );
18
+ }
19
+
20
+ findHoliday = date => {
21
+ const {holidays} = this.props;
22
+ if (date && holidays && holidays.length > 0) {
23
+ const day = date.date();
24
+ const month = date.month() + 1;
25
+ return holidays.find(item => item.day === day && item.month === month);
15
26
  }
27
+ return null;
28
+ };
16
29
 
17
- findHoliday = (date) => {
18
- const { holidays } = this.props;
19
- if (date && holidays && holidays.length > 0) {
20
- const day = date.date();
21
- const month = date.month() + 1;
22
- return holidays.find((item) => item.day === day && item.month === month);
23
- }
24
- return null;
30
+ checkHoliday = date => {
31
+ const holiday = this.findHoliday(date);
32
+ return {
33
+ isSolarHoliday: !!(holiday && !holiday.lunar),
34
+ isLunarHoliday: !!(holiday && holiday.lunar),
25
35
  };
36
+ };
26
37
 
27
- checkHoliday = (date) => {
28
- const holiday = this.findHoliday(date);
29
- return {
30
- isSolarHoliday: !!(holiday && !holiday.lunar),
31
- isLunarHoliday: !!(holiday && holiday.lunar)
32
- };
33
- };
38
+ renderDayRow = (dayList, index, disabledWeekend) => (
39
+ <View
40
+ style={{
41
+ flexDirection: 'row',
42
+ justifyContent: 'space-between',
43
+ }}
44
+ key={`row${index}`}>
45
+ {dayList.map((item, i) => {
46
+ const keyDay = moment(item.date).format('YYYY-MM-DD');
47
+ const priceInfo = this.props?.priceListDate?.[keyDay];
34
48
 
35
- renderDayRow = (dayList, index) => (
36
- <View
49
+ return (
50
+ <Day
51
+ {...this.props}
52
+ {...this.checkHoliday(item.date)}
53
+ disabledWeekend={disabledWeekend}
54
+ date={item.date}
55
+ havePriceList={!!this.props.priceListDate}
56
+ lunarDate={item.lunarDate}
57
+ empty={item.empty}
58
+ key={`day${i.toString()}`}
59
+ index={i}
60
+ price={priceInfo?.priceAsString}
61
+ isBestPrice={priceInfo?.isBestPrice}
62
+ />
63
+ );
64
+ })}
65
+ </View>
66
+ );
67
+
68
+ render() {
69
+ const {month, disabledWeekend} = this.props;
70
+
71
+ if (month) {
72
+ return (
73
+ <View>
74
+ <View
37
75
  style={{
38
- flexDirection: 'row',
39
- justifyContent: 'space-between'
40
- }}
41
- key={`row${index}`}
42
- >
43
- {dayList.map((item, i) => {
44
- const keyDay = moment(item.date).format('YYYY-MM-DD');
45
- const priceInfo = this.props?.priceListDate?.[keyDay];
46
- return (
47
- <Day
48
- {...this.props}
49
- {...this.checkHoliday(item.date)}
50
- date={item.date}
51
- lunarDate={item.lunarDate}
52
- empty={item.empty}
53
- key={`day${i.toString()}`}
54
- index={i}
55
- price={priceInfo?.priceAsString}
56
- isBestPrice={priceInfo?.isBestPrice}
57
- />
58
- );
59
- }
76
+ paddingHorizontal: Spacing.S,
77
+ paddingVertical: 5,
78
+ width: width - ScaleSize(24),
79
+ }}>
80
+ {this.temp.map((item, i) =>
81
+ this.renderDayRow(item, i, disabledWeekend),
60
82
  )}
83
+ </View>
61
84
  </View>
62
- );
63
-
64
- render() {
65
- const {
66
- month
67
- } = this.props;
68
- if (month) {
69
- return (
70
- <View>
71
- <View style={{ paddingHorizontal: 7, paddingVertical: 5 }}>
72
- {this.temp.map((item, i) => this.renderDayRow(item, i)
73
- )}
74
- </View>
75
- </View>
76
- );
77
- }
78
- return (<View />);
85
+ );
79
86
  }
87
+ return <View />;
88
+ }
80
89
  }