@momo-kits/calendar 0.0.71-beta.4 → 0.0.71-beta.40

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import Calendar from './src/Calendar';
2
2
  import CalendarPicker from './src/calendarPicker/index';
3
3
 
4
- export { Calendar, CalendarPicker };
4
+ export {Calendar, CalendarPicker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/calendar",
3
- "version": "0.0.71-beta.4",
3
+ "version": "0.0.71-beta.40",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/publish.sh CHANGED
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- ##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'
29
+ ##curl -X POST 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'
@@ -1,85 +1,83 @@
1
- import React, { useState, forwardRef, useImperativeHandle } from 'react';
2
- import { View, TouchableOpacity, StyleSheet } from 'react-native';
1
+ import React, {useState, forwardRef, useImperativeHandle} from 'react';
2
+ import {View, TouchableOpacity, StyleSheet} from 'react-native';
3
3
  import moment from 'moment';
4
- import { Icon, ScaleSize, Text, Colors, Spacing } from '@momo-kits/core-v2';
4
+ import {Icon, ScaleSize, Text, Colors, Spacing} from '@momo-kits/core-v2';
5
5
 
6
6
  import Util from './Util';
7
7
 
8
8
  const HeaderControl = forwardRef(
9
- ({ onPressBackArrow, onPressNextArrow, selectedDate }, ref) => {
10
- const [info, setInfo] = useState({
11
- date: moment(selectedDate || new Date()),
12
- });
9
+ ({onPressBackArrow, onPressNextArrow, selectedDate}, ref) => {
10
+ const [info, setInfo] = useState({
11
+ date: moment(selectedDate || new Date()),
12
+ });
13
13
 
14
- useImperativeHandle(ref, () => ({
15
- onUpdateInfo,
16
- }));
14
+ useImperativeHandle(ref, () => ({
15
+ onUpdateInfo,
16
+ }));
17
17
 
18
- const onUpdateInfo = (date) => {
19
- setInfo(date);
20
- };
18
+ const onUpdateInfo = date => {
19
+ setInfo(date);
20
+ };
21
21
 
22
- if (info && info.date) {
23
- const headerFormat = `${Util.mapMonth(
24
- info.date.month() + 1,
25
- )}/${info.date.year()}`;
26
- return (
27
- <View style={styles.container}>
28
- <TouchableOpacity
29
- style={styles.btnLeft}
30
- onPress={onPressBackArrow}>
31
- <Icon
32
- name="24_arrow_chevron_left_small"
33
- tintColor={Colors.black_17}
34
- style={styles.icon}
35
- />
36
- </TouchableOpacity>
37
- <Text.HeaderText2
38
- weight="semibold"
39
- style={styles.txtHeader}>
40
- {headerFormat}
41
- </Text.HeaderText2>
42
- <TouchableOpacity
43
- style={styles.btnRight}
44
- onPress={onPressNextArrow}>
45
- <Icon
46
- name="24_arrow_chevron_right_small"
47
- tintColor={Colors.black_17}
48
- style={styles.icon}
49
- />
50
- </TouchableOpacity>
51
- </View>
52
- );
53
- }
54
- return <View />;
55
- },
22
+ if (info && info.date) {
23
+ const headerFormat = `${Util.mapMonth(
24
+ info.date.month() + 1,
25
+ )}/${info.date.year()}`;
26
+ return (
27
+ <View style={styles.container}>
28
+ <TouchableOpacity style={styles.btnLeft} onPress={onPressBackArrow}>
29
+ <Icon
30
+ name="24_arrow_chevron_left_small"
31
+ tintColor={Colors.black_17}
32
+ style={styles.icon}
33
+ />
34
+ </TouchableOpacity>
35
+ <Text.HeaderText2 weight="semibold" style={styles.txtHeader}>
36
+ {headerFormat}
37
+ </Text.HeaderText2>
38
+ <TouchableOpacity style={styles.btnRight} onPress={onPressNextArrow}>
39
+ <Icon
40
+ name="24_arrow_chevron_right_small"
41
+ tintColor={Colors.black_17}
42
+ style={styles.icon}
43
+ />
44
+ </TouchableOpacity>
45
+ </View>
46
+ );
47
+ }
48
+ return <View />;
49
+ },
56
50
  );
57
51
 
58
52
  export default HeaderControl;
59
53
  const styles = StyleSheet.create({
60
- icon: { width: 24, height: 24, resizeMode: 'contain' },
61
- txtHeader: {
62
- // fontSize: 15,
63
- textAlign: 'center',
64
- },
65
- btnRight: {
66
- width: 36,
67
- height: 36,
68
- justifyContent: 'center',
69
- alignItems: 'center',
70
- },
71
- btnLeft: {
72
- width: 36,
73
- height: 36,
74
- justifyContent: 'center',
75
- alignItems: 'center',
76
- },
77
- container: {
78
- height: ScaleSize(44),
79
- flexDirection: 'row',
80
- justifyContent: 'space-between',
81
- backgroundColor: Colors.blue_10,
82
- alignItems: 'center',
83
- borderRadius: 4,
84
- },
54
+ icon: {
55
+ width: 24,
56
+ height: 24,
57
+ resizeMode: 'contain',
58
+ },
59
+ txtHeader: {
60
+ // fontSize: 15,
61
+ textAlign: 'center',
62
+ },
63
+ btnRight: {
64
+ width: 36,
65
+ height: 36,
66
+ justifyContent: 'center',
67
+ alignItems: 'center',
68
+ },
69
+ btnLeft: {
70
+ width: 36,
71
+ height: 36,
72
+ justifyContent: 'center',
73
+ alignItems: 'center',
74
+ },
75
+ container: {
76
+ height: ScaleSize(44),
77
+ flexDirection: 'row',
78
+ justifyContent: 'space-between',
79
+ backgroundColor: Colors.blue_10,
80
+ alignItems: 'center',
81
+ borderRadius: 4,
82
+ },
85
83
  });
@@ -1,191 +1,198 @@
1
1
  /* eslint-disable func-names */
2
+
2
3
  /* eslint-disable no-bitwise */
3
4
  function Lunar() {
4
- this.isleap = false;
5
- this.lunarDay = 0;
6
- this.lunarMonth = 0;
7
- this.lunarYear = 0;
5
+ this.isleap = false;
6
+ this.lunarDay = 0;
7
+ this.lunarMonth = 0;
8
+ this.lunarYear = 0;
8
9
  }
9
10
 
10
11
  function Solar() {
11
- this.solarDay = 0;
12
- this.solarMonth = 0;
13
- this.solarYear = 0;
12
+ this.solarDay = 0;
13
+ this.solarMonth = 0;
14
+ this.solarYear = 0;
14
15
  }
15
16
 
16
17
  function LunarSolarConverter() {
17
- this.lunar_month_days = [1887, 0x1694, 0x16aa, 0x4ad5,
18
- 0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a, 0x1d2a, 0xd54, 0x75aa, 0x156a,
19
- 0x1096d, 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a, 0x8d55, 0xad4,
20
- 0x135a, 0x495d, 0x95c, 0xd49b, 0x149a, 0x1a4a, 0xbaa5, 0x16a8,
21
- 0x1ad4, 0x52da, 0x12b6, 0xe937, 0x92e, 0x1496, 0xb64b, 0xd4a,
22
- 0xda8, 0x95b5, 0x56c, 0x12ae, 0x492f, 0x92e, 0xcc96, 0x1a94,
23
- 0x1d4a, 0xada9, 0xb5a, 0x56c, 0x726e, 0x125c, 0xf92d, 0x192a,
24
- 0x1a94, 0xdb4a, 0x16aa, 0xad4, 0x955b, 0x4ba, 0x125a, 0x592b,
25
- 0x152a, 0xf695, 0xd94, 0x16aa, 0xaab5, 0x9b4, 0x14b6, 0x6a57,
26
- 0xa56, 0x1152a, 0x1d2a, 0xd54, 0xd5aa, 0x156a, 0x96c, 0x94ae,
27
- 0x14ae, 0xa4c, 0x7d26, 0x1b2a, 0xeb55, 0xad4, 0x12da, 0xa95d,
28
- 0x95a, 0x149a, 0x9a4d, 0x1a4a, 0x11aa5, 0x16a8, 0x16d4, 0xd2da,
29
- 0x12b6, 0x936, 0x9497, 0x1496, 0x1564b, 0xd4a, 0xda8, 0xd5b4,
30
- 0x156c, 0x12ae, 0xa92f, 0x92e, 0xc96, 0x6d4a, 0x1d4a, 0x10d65,
31
- 0xb58, 0x156c, 0xb26d, 0x125c, 0x192c, 0x9a95, 0x1a94, 0x1b4a,
32
- 0x4b55, 0xad4, 0xf55b, 0x4ba, 0x125a, 0xb92b, 0x152a, 0x1694,
33
- 0x96aa, 0x15aa, 0x12ab5, 0x974, 0x14b6, 0xca57, 0xa56, 0x1526,
34
- 0x8e95, 0xd54, 0x15aa, 0x49b5, 0x96c, 0xd4ae, 0x149c, 0x1a4c,
35
- 0xbd26, 0x1aa6, 0xb54, 0x6d6a, 0x12da, 0x1695d, 0x95a, 0x149a,
36
- 0xda4b, 0x1a4a, 0x1aa4, 0xbb54, 0x16b4, 0xada, 0x495b, 0x936,
37
- 0xf497, 0x1496, 0x154a, 0xb6a5, 0xda4, 0x15b4, 0x6ab6, 0x126e,
38
- 0x1092f, 0x92e, 0xc96, 0xcd4a, 0x1d4a, 0xd64, 0x956c, 0x155c,
39
- 0x125c, 0x792e, 0x192c, 0xfa95, 0x1a94, 0x1b4a, 0xab55, 0xad4,
40
- 0x14da, 0x8a5d, 0xa5a, 0x1152b, 0x152a, 0x1694, 0xd6aa, 0x15aa,
41
- 0xab4, 0x94ba, 0x14b6, 0xa56, 0x7527, 0xd26, 0xee53, 0xd54, 0x15aa,
42
- 0xa9b5, 0x96c, 0x14ae, 0x8a4e, 0x1a4c, 0x11d26, 0x1aa4, 0x1b54,
43
- 0xcd6a, 0xada, 0x95c, 0x949d, 0x149a, 0x1a2a, 0x5b25, 0x1aa4,
44
- 0xfb52, 0x16b4, 0xaba, 0xa95b, 0x936, 0x1496, 0x9a4b, 0x154a,
45
- 0x136a5, 0xda4, 0x15ac];
46
-
47
- this.solar_1_1 = [1887, 0xec04c, 0xec23f, 0xec435, 0xec649,
48
- 0xec83e, 0xeca51, 0xecc46, 0xece3a, 0xed04d, 0xed242, 0xed436,
49
- 0xed64a, 0xed83f, 0xeda53, 0xedc48, 0xede3d, 0xee050, 0xee244,
50
- 0xee439, 0xee64d, 0xee842, 0xeea36, 0xeec4a, 0xeee3e, 0xef052,
51
- 0xef246, 0xef43a, 0xef64e, 0xef843, 0xefa37, 0xefc4b, 0xefe41,
52
- 0xf0054, 0xf0248, 0xf043c, 0xf0650, 0xf0845, 0xf0a38, 0xf0c4d,
53
- 0xf0e42, 0xf1037, 0xf124a, 0xf143e, 0xf1651, 0xf1846, 0xf1a3a,
54
- 0xf1c4e, 0xf1e44, 0xf2038, 0xf224b, 0xf243f, 0xf2653, 0xf2848,
55
- 0xf2a3b, 0xf2c4f, 0xf2e45, 0xf3039, 0xf324d, 0xf3442, 0xf3636,
56
- 0xf384a, 0xf3a3d, 0xf3c51, 0xf3e46, 0xf403b, 0xf424e, 0xf4443,
57
- 0xf4638, 0xf484c, 0xf4a3f, 0xf4c52, 0xf4e48, 0xf503c, 0xf524f,
58
- 0xf5445, 0xf5639, 0xf584d, 0xf5a42, 0xf5c35, 0xf5e49, 0xf603e,
59
- 0xf6251, 0xf6446, 0xf663b, 0xf684f, 0xf6a43, 0xf6c37, 0xf6e4b,
60
- 0xf703f, 0xf7252, 0xf7447, 0xf763c, 0xf7850, 0xf7a45, 0xf7c39,
61
- 0xf7e4d, 0xf8042, 0xf8254, 0xf8449, 0xf863d, 0xf8851, 0xf8a46,
62
- 0xf8c3b, 0xf8e4f, 0xf9044, 0xf9237, 0xf944a, 0xf963f, 0xf9853,
63
- 0xf9a47, 0xf9c3c, 0xf9e50, 0xfa045, 0xfa238, 0xfa44c, 0xfa641,
64
- 0xfa836, 0xfaa49, 0xfac3d, 0xfae52, 0xfb047, 0xfb23a, 0xfb44e,
65
- 0xfb643, 0xfb837, 0xfba4a, 0xfbc3f, 0xfbe53, 0xfc048, 0xfc23c,
66
- 0xfc450, 0xfc645, 0xfc839, 0xfca4c, 0xfcc41, 0xfce36, 0xfd04a,
67
- 0xfd23d, 0xfd451, 0xfd646, 0xfd83a, 0xfda4d, 0xfdc43, 0xfde37,
68
- 0xfe04b, 0xfe23f, 0xfe453, 0xfe648, 0xfe83c, 0xfea4f, 0xfec44,
69
- 0xfee38, 0xff04c, 0xff241, 0xff436, 0xff64a, 0xff83e, 0xffa51,
70
- 0xffc46, 0xffe3a, 0x10004e, 0x100242, 0x100437, 0x10064b, 0x100841,
71
- 0x100a53, 0x100c48, 0x100e3c, 0x10104f, 0x101244, 0x101438,
72
- 0x10164c, 0x101842, 0x101a35, 0x101c49, 0x101e3d, 0x102051,
73
- 0x102245, 0x10243a, 0x10264e, 0x102843, 0x102a37, 0x102c4b,
74
- 0x102e3f, 0x103053, 0x103247, 0x10343b, 0x10364f, 0x103845,
75
- 0x103a38, 0x103c4c, 0x103e42, 0x104036, 0x104249, 0x10443d,
76
- 0x104651, 0x104846, 0x104a3a, 0x104c4e, 0x104e43, 0x105038,
77
- 0x10524a, 0x10543e, 0x105652, 0x105847, 0x105a3b, 0x105c4f,
78
- 0x105e45, 0x106039, 0x10624c, 0x106441, 0x106635, 0x106849,
79
- 0x106a3d, 0x106c51, 0x106e47, 0x10703c, 0x10724f, 0x107444,
80
- 0x107638, 0x10784c, 0x107a3f, 0x107c53, 0x107e48];
81
-
82
- /**
83
- * @return {number}
84
- */
85
- this.GetBitInt = function (data, length, shift) {
86
- return (data & (((1 << length) - 1) << shift)) >> shift;
87
- };
88
-
89
- // WARNING: Dates before Oct. 1582 are inaccurate
90
- /**
91
- * @return {number}
92
- */
93
- this.SolarToInt = function (y, m, d) {
94
- m = (m + 9) % 12;
95
- y = parseInt(y) - parseInt(m / 10);
96
- return 365 * y + parseInt(y / 4) - parseInt(y / 100) + parseInt(y / 400) + parseInt((m * 306 + 5) / 10)
97
- + (d - 1);
98
- };
99
-
100
- this.SolarFromInt = function (g) {
101
- let y = parseInt((10000 * g + 14780) / 3652425);
102
- let ddd = g - (365 * y + parseInt(y / 4) - parseInt(y / 100) + parseInt(y / 400));
103
- if (ddd < 0) {
104
- y--;
105
- ddd = g - (365 * y + parseInt(y / 4) - parseInt(y / 100) + parseInt(y / 400));
106
- }
107
- const mi = parseInt((100 * ddd + 52) / 3060);
108
- const mm = (mi + 2) % 12 + 1;
109
- y += parseInt((mi + 2) / 12);
110
- const dd = ddd - parseInt((mi * 306 + 5) / 10) + 1;
111
- const solar = new Solar();
112
- solar.solarYear = parseInt(y);
113
- solar.solarMonth = parseInt(mm);
114
- solar.solarDay = parseInt(dd);
115
- return solar;
116
- };
117
-
118
- this.LunarToSolar = function (lunar) {
119
- const days = this.lunar_month_days[lunar.lunarYear - this.lunar_month_days[0]];
120
- const leap = this.GetBitInt(days, 4, 13);
121
- let offset = 0;
122
- let loopend = leap;
123
- if (!lunar.isleap) {
124
- if (lunar.lunarMonth <= leap || leap === 0) {
125
- loopend = lunar.lunarMonth - 1;
126
- } else {
127
- loopend = lunar.lunarMonth;
128
- }
129
- }
130
- for (let i = 0; i < loopend; i++) {
131
- offset += this.GetBitInt(days, 1, 12 - i) === 1 ? 30 : 29;
132
- }
133
- offset += lunar.lunarDay;
134
-
135
- const solar11 = this.solar_1_1[lunar.lunarYear - this.solar_1_1[0]];
136
-
137
- const y = this.GetBitInt(solar11, 12, 9);
138
- const m = this.GetBitInt(solar11, 4, 5);
139
- const d = this.GetBitInt(solar11, 5, 0);
140
-
141
- return this.SolarFromInt(this.SolarToInt(y, m, d) + offset - 1);
142
- };
143
-
144
- this.SolarToLunar = function (solar) {
145
- const lunar = new Lunar();
146
- let index = solar.solarYear - this.solar_1_1[0];
147
- const data = (solar.solarYear << 9) | (solar.solarMonth << 5)
148
- | (solar.solarDay);
149
- if (this.solar_1_1[index] > data) {
150
- index--;
151
- }
152
- const solar11 = this.solar_1_1[index];
153
- const y = this.GetBitInt(solar11, 12, 9);
154
- const m = this.GetBitInt(solar11, 4, 5);
155
- const d = this.GetBitInt(solar11, 5, 0);
156
- let offset = this.SolarToInt(solar.solarYear, solar.solarMonth,
157
- solar.solarDay) - this.SolarToInt(y, m, d);
158
-
159
- const days = this.lunar_month_days[index];
160
- const leap = this.GetBitInt(days, 4, 13);
161
-
162
- const lunarY = index + this.solar_1_1[0];
163
- let lunarM = 1;
164
- offset += 1;
165
-
166
- for (let i = 0; i < 13; i++) {
167
- const dm = this.GetBitInt(days, 1, 12 - i) === 1 ? 30 : 29;
168
- if (offset > dm) {
169
- lunarM++;
170
- offset -= dm;
171
- } else {
172
- break;
173
- }
174
- }
175
- const lunarD = parseInt(offset);
176
- lunar.lunarYear = lunarY;
177
- lunar.lunarMonth = lunarM;
178
- lunar.isleap = false;
179
- if (leap !== 0 && lunarM > leap) {
180
- lunar.lunarMonth = lunarM - 1;
181
- if (lunarM === leap + 1) {
182
- lunar.isleap = true;
183
- }
184
- }
185
-
186
- lunar.lunarDay = lunarD;
187
- return lunar;
188
- };
18
+ this.lunar_month_days = [
19
+ 1887, 0x1694, 0x16aa, 0x4ad5, 0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a, 0x1d2a,
20
+ 0xd54, 0x75aa, 0x156a, 0x1096d, 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a,
21
+ 0x8d55, 0xad4, 0x135a, 0x495d, 0x95c, 0xd49b, 0x149a, 0x1a4a, 0xbaa5,
22
+ 0x16a8, 0x1ad4, 0x52da, 0x12b6, 0xe937, 0x92e, 0x1496, 0xb64b, 0xd4a, 0xda8,
23
+ 0x95b5, 0x56c, 0x12ae, 0x492f, 0x92e, 0xcc96, 0x1a94, 0x1d4a, 0xada9, 0xb5a,
24
+ 0x56c, 0x726e, 0x125c, 0xf92d, 0x192a, 0x1a94, 0xdb4a, 0x16aa, 0xad4,
25
+ 0x955b, 0x4ba, 0x125a, 0x592b, 0x152a, 0xf695, 0xd94, 0x16aa, 0xaab5, 0x9b4,
26
+ 0x14b6, 0x6a57, 0xa56, 0x1152a, 0x1d2a, 0xd54, 0xd5aa, 0x156a, 0x96c,
27
+ 0x94ae, 0x14ae, 0xa4c, 0x7d26, 0x1b2a, 0xeb55, 0xad4, 0x12da, 0xa95d, 0x95a,
28
+ 0x149a, 0x9a4d, 0x1a4a, 0x11aa5, 0x16a8, 0x16d4, 0xd2da, 0x12b6, 0x936,
29
+ 0x9497, 0x1496, 0x1564b, 0xd4a, 0xda8, 0xd5b4, 0x156c, 0x12ae, 0xa92f,
30
+ 0x92e, 0xc96, 0x6d4a, 0x1d4a, 0x10d65, 0xb58, 0x156c, 0xb26d, 0x125c,
31
+ 0x192c, 0x9a95, 0x1a94, 0x1b4a, 0x4b55, 0xad4, 0xf55b, 0x4ba, 0x125a,
32
+ 0xb92b, 0x152a, 0x1694, 0x96aa, 0x15aa, 0x12ab5, 0x974, 0x14b6, 0xca57,
33
+ 0xa56, 0x1526, 0x8e95, 0xd54, 0x15aa, 0x49b5, 0x96c, 0xd4ae, 0x149c, 0x1a4c,
34
+ 0xbd26, 0x1aa6, 0xb54, 0x6d6a, 0x12da, 0x1695d, 0x95a, 0x149a, 0xda4b,
35
+ 0x1a4a, 0x1aa4, 0xbb54, 0x16b4, 0xada, 0x495b, 0x936, 0xf497, 0x1496,
36
+ 0x154a, 0xb6a5, 0xda4, 0x15b4, 0x6ab6, 0x126e, 0x1092f, 0x92e, 0xc96,
37
+ 0xcd4a, 0x1d4a, 0xd64, 0x956c, 0x155c, 0x125c, 0x792e, 0x192c, 0xfa95,
38
+ 0x1a94, 0x1b4a, 0xab55, 0xad4, 0x14da, 0x8a5d, 0xa5a, 0x1152b, 0x152a,
39
+ 0x1694, 0xd6aa, 0x15aa, 0xab4, 0x94ba, 0x14b6, 0xa56, 0x7527, 0xd26, 0xee53,
40
+ 0xd54, 0x15aa, 0xa9b5, 0x96c, 0x14ae, 0x8a4e, 0x1a4c, 0x11d26, 0x1aa4,
41
+ 0x1b54, 0xcd6a, 0xada, 0x95c, 0x949d, 0x149a, 0x1a2a, 0x5b25, 0x1aa4,
42
+ 0xfb52, 0x16b4, 0xaba, 0xa95b, 0x936, 0x1496, 0x9a4b, 0x154a, 0x136a5,
43
+ 0xda4, 0x15ac,
44
+ ];
45
+
46
+ this.solar_1_1 = [
47
+ 1887, 0xec04c, 0xec23f, 0xec435, 0xec649, 0xec83e, 0xeca51, 0xecc46,
48
+ 0xece3a, 0xed04d, 0xed242, 0xed436, 0xed64a, 0xed83f, 0xeda53, 0xedc48,
49
+ 0xede3d, 0xee050, 0xee244, 0xee439, 0xee64d, 0xee842, 0xeea36, 0xeec4a,
50
+ 0xeee3e, 0xef052, 0xef246, 0xef43a, 0xef64e, 0xef843, 0xefa37, 0xefc4b,
51
+ 0xefe41, 0xf0054, 0xf0248, 0xf043c, 0xf0650, 0xf0845, 0xf0a38, 0xf0c4d,
52
+ 0xf0e42, 0xf1037, 0xf124a, 0xf143e, 0xf1651, 0xf1846, 0xf1a3a, 0xf1c4e,
53
+ 0xf1e44, 0xf2038, 0xf224b, 0xf243f, 0xf2653, 0xf2848, 0xf2a3b, 0xf2c4f,
54
+ 0xf2e45, 0xf3039, 0xf324d, 0xf3442, 0xf3636, 0xf384a, 0xf3a3d, 0xf3c51,
55
+ 0xf3e46, 0xf403b, 0xf424e, 0xf4443, 0xf4638, 0xf484c, 0xf4a3f, 0xf4c52,
56
+ 0xf4e48, 0xf503c, 0xf524f, 0xf5445, 0xf5639, 0xf584d, 0xf5a42, 0xf5c35,
57
+ 0xf5e49, 0xf603e, 0xf6251, 0xf6446, 0xf663b, 0xf684f, 0xf6a43, 0xf6c37,
58
+ 0xf6e4b, 0xf703f, 0xf7252, 0xf7447, 0xf763c, 0xf7850, 0xf7a45, 0xf7c39,
59
+ 0xf7e4d, 0xf8042, 0xf8254, 0xf8449, 0xf863d, 0xf8851, 0xf8a46, 0xf8c3b,
60
+ 0xf8e4f, 0xf9044, 0xf9237, 0xf944a, 0xf963f, 0xf9853, 0xf9a47, 0xf9c3c,
61
+ 0xf9e50, 0xfa045, 0xfa238, 0xfa44c, 0xfa641, 0xfa836, 0xfaa49, 0xfac3d,
62
+ 0xfae52, 0xfb047, 0xfb23a, 0xfb44e, 0xfb643, 0xfb837, 0xfba4a, 0xfbc3f,
63
+ 0xfbe53, 0xfc048, 0xfc23c, 0xfc450, 0xfc645, 0xfc839, 0xfca4c, 0xfcc41,
64
+ 0xfce36, 0xfd04a, 0xfd23d, 0xfd451, 0xfd646, 0xfd83a, 0xfda4d, 0xfdc43,
65
+ 0xfde37, 0xfe04b, 0xfe23f, 0xfe453, 0xfe648, 0xfe83c, 0xfea4f, 0xfec44,
66
+ 0xfee38, 0xff04c, 0xff241, 0xff436, 0xff64a, 0xff83e, 0xffa51, 0xffc46,
67
+ 0xffe3a, 0x10004e, 0x100242, 0x100437, 0x10064b, 0x100841, 0x100a53,
68
+ 0x100c48, 0x100e3c, 0x10104f, 0x101244, 0x101438, 0x10164c, 0x101842,
69
+ 0x101a35, 0x101c49, 0x101e3d, 0x102051, 0x102245, 0x10243a, 0x10264e,
70
+ 0x102843, 0x102a37, 0x102c4b, 0x102e3f, 0x103053, 0x103247, 0x10343b,
71
+ 0x10364f, 0x103845, 0x103a38, 0x103c4c, 0x103e42, 0x104036, 0x104249,
72
+ 0x10443d, 0x104651, 0x104846, 0x104a3a, 0x104c4e, 0x104e43, 0x105038,
73
+ 0x10524a, 0x10543e, 0x105652, 0x105847, 0x105a3b, 0x105c4f, 0x105e45,
74
+ 0x106039, 0x10624c, 0x106441, 0x106635, 0x106849, 0x106a3d, 0x106c51,
75
+ 0x106e47, 0x10703c, 0x10724f, 0x107444, 0x107638, 0x10784c, 0x107a3f,
76
+ 0x107c53, 0x107e48,
77
+ ];
78
+
79
+ /**
80
+ * @return {number}
81
+ */
82
+ this.GetBitInt = function (data, length, shift) {
83
+ return (data & (((1 << length) - 1) << shift)) >> shift;
84
+ };
85
+
86
+ // WARNING: Dates before Oct. 1582 are inaccurate
87
+ /**
88
+ * @return {number}
89
+ */
90
+ this.SolarToInt = function (y, m, d) {
91
+ m = (m + 9) % 12;
92
+ y = parseInt(y) - parseInt(m / 10);
93
+ return (
94
+ 365 * y +
95
+ parseInt(y / 4) -
96
+ parseInt(y / 100) +
97
+ parseInt(y / 400) +
98
+ parseInt((m * 306 + 5) / 10) +
99
+ (d - 1)
100
+ );
101
+ };
102
+
103
+ this.SolarFromInt = function (g) {
104
+ let y = parseInt((10000 * g + 14780) / 3652425);
105
+ let ddd =
106
+ g - (365 * y + parseInt(y / 4) - parseInt(y / 100) + parseInt(y / 400));
107
+ if (ddd < 0) {
108
+ y--;
109
+ ddd =
110
+ g - (365 * y + parseInt(y / 4) - parseInt(y / 100) + parseInt(y / 400));
111
+ }
112
+ const mi = parseInt((100 * ddd + 52) / 3060);
113
+ const mm = ((mi + 2) % 12) + 1;
114
+ y += parseInt((mi + 2) / 12);
115
+ const dd = ddd - parseInt((mi * 306 + 5) / 10) + 1;
116
+ const solar = new Solar();
117
+ solar.solarYear = parseInt(y);
118
+ solar.solarMonth = parseInt(mm);
119
+ solar.solarDay = parseInt(dd);
120
+ return solar;
121
+ };
122
+
123
+ this.LunarToSolar = function (lunar) {
124
+ const days =
125
+ this.lunar_month_days[lunar.lunarYear - this.lunar_month_days[0]];
126
+ const leap = this.GetBitInt(days, 4, 13);
127
+ let offset = 0;
128
+ let loopend = leap;
129
+ if (!lunar.isleap) {
130
+ if (lunar.lunarMonth <= leap || leap === 0) {
131
+ loopend = lunar.lunarMonth - 1;
132
+ } else {
133
+ loopend = lunar.lunarMonth;
134
+ }
135
+ }
136
+ for (let i = 0; i < loopend; i++) {
137
+ offset += this.GetBitInt(days, 1, 12 - i) === 1 ? 30 : 29;
138
+ }
139
+ offset += lunar.lunarDay;
140
+
141
+ const solar11 = this.solar_1_1[lunar.lunarYear - this.solar_1_1[0]];
142
+
143
+ const y = this.GetBitInt(solar11, 12, 9);
144
+ const m = this.GetBitInt(solar11, 4, 5);
145
+ const d = this.GetBitInt(solar11, 5, 0);
146
+
147
+ return this.SolarFromInt(this.SolarToInt(y, m, d) + offset - 1);
148
+ };
149
+
150
+ this.SolarToLunar = function (solar) {
151
+ const lunar = new Lunar();
152
+ let index = solar.solarYear - this.solar_1_1[0];
153
+ const data =
154
+ (solar.solarYear << 9) | (solar.solarMonth << 5) | solar.solarDay;
155
+ if (this.solar_1_1[index] > data) {
156
+ index--;
157
+ }
158
+ const solar11 = this.solar_1_1[index];
159
+ const y = this.GetBitInt(solar11, 12, 9);
160
+ const m = this.GetBitInt(solar11, 4, 5);
161
+ const d = this.GetBitInt(solar11, 5, 0);
162
+ let offset =
163
+ this.SolarToInt(solar.solarYear, solar.solarMonth, solar.solarDay) -
164
+ this.SolarToInt(y, m, d);
165
+
166
+ const days = this.lunar_month_days[index];
167
+ const leap = this.GetBitInt(days, 4, 13);
168
+
169
+ const lunarY = index + this.solar_1_1[0];
170
+ let lunarM = 1;
171
+ offset += 1;
172
+
173
+ for (let i = 0; i < 13; i++) {
174
+ const dm = this.GetBitInt(days, 1, 12 - i) === 1 ? 30 : 29;
175
+ if (offset > dm) {
176
+ lunarM++;
177
+ offset -= dm;
178
+ } else {
179
+ break;
180
+ }
181
+ }
182
+ const lunarD = parseInt(offset);
183
+ lunar.lunarYear = lunarY;
184
+ lunar.lunarMonth = lunarM;
185
+ lunar.isleap = false;
186
+ if (leap !== 0 && lunarM > leap) {
187
+ lunar.lunarMonth = lunarM - 1;
188
+ if (lunarM === leap + 1) {
189
+ lunar.isleap = true;
190
+ }
191
+ }
192
+
193
+ lunar.lunarDay = lunarD;
194
+ return lunar;
195
+ };
189
196
  }
190
197
 
191
198
  module.exports = LunarSolarConverter;