vietnamese-lunar 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/LICENSE +8 -0
- package/lib/auspiciousHours.d.ts +4 -0
- package/lib/auspiciousHours.js +38 -0
- package/lib/constants.d.ts +16 -0
- package/lib/constants.js +149 -0
- package/lib/heavenly_earthly.d.ts +3 -0
- package/lib/heavenly_earthly.js +30 -0
- package/lib/holidays.d.ts +1 -0
- package/lib/holidays.js +25 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -0
- package/lib/lunar.d.ts +3 -0
- package/lib/lunar.js +111 -0
- package/lib/lunarConverter.d.ts +2 -0
- package/lib/lunarConverter.js +63 -0
- package/lib/type.d.ts +13 -0
- package/lib/type.js +2 -0
- package/lib/utils.d.ts +3 -0
- package/lib/utils.js +40 -0
- package/package.json +49 -0
- package/readme.md +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
Copyright 2017 Sampath Sitinamaluwa
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLunarDayType = exports.getInauspiciousHours = exports.getAuspiciousHours = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const getAuspiciousHours = (julianDay) => {
|
|
6
|
+
const earthlyOfDay = (julianDay + 1) % 12;
|
|
7
|
+
const auspiciousHour = constants_1.AUSPICIOUS_HOURS[earthlyOfDay % 6];
|
|
8
|
+
const listAuspiciousHours = [];
|
|
9
|
+
for (let hour = 0; hour < 12; hour++) {
|
|
10
|
+
if (auspiciousHour.charAt(hour) === '1') {
|
|
11
|
+
const start = (hour * 2 + 23) % 24;
|
|
12
|
+
const end = (hour * 2 + 1) % 24;
|
|
13
|
+
listAuspiciousHours.push(`${constants_1.HEAVENLY_STEMS[hour % 10]} ${constants_1.EARTHLY_BRANCHES[hour]} (${String(start)}-${String(end)})`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return listAuspiciousHours.join(', ');
|
|
17
|
+
};
|
|
18
|
+
exports.getAuspiciousHours = getAuspiciousHours;
|
|
19
|
+
const getInauspiciousHours = (julianDay) => {
|
|
20
|
+
const earthlyOfDay = (julianDay + 1) % 12;
|
|
21
|
+
const auspiciousHourPattern = constants_1.AUSPICIOUS_HOURS[earthlyOfDay % 6];
|
|
22
|
+
if (!auspiciousHourPattern || auspiciousHourPattern.length < 12)
|
|
23
|
+
return '';
|
|
24
|
+
const listInAuspiciousHours = [];
|
|
25
|
+
for (let hour = 0; hour < 12; hour++) {
|
|
26
|
+
if (auspiciousHourPattern.charAt(hour) !== '1') {
|
|
27
|
+
const start = (hour * 2 + 23) % 24;
|
|
28
|
+
const end = (hour * 2 + 1) % 24;
|
|
29
|
+
listInAuspiciousHours.push(`${constants_1.HEAVENLY_STEMS[hour % 10]} ${constants_1.EARTHLY_BRANCHES[hour]} (${String(start)}-${String(end)})`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return listInAuspiciousHours.join(', ');
|
|
33
|
+
};
|
|
34
|
+
exports.getInauspiciousHours = getInauspiciousHours;
|
|
35
|
+
const getLunarDayType = (lunarDate) => {
|
|
36
|
+
return "";
|
|
37
|
+
};
|
|
38
|
+
exports.getLunarDayType = getLunarDayType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const LIST_YEARS: number[];
|
|
2
|
+
declare const HEAVENLY_STEMS: string[];
|
|
3
|
+
declare const EARTHLY_BRANCHES: string[];
|
|
4
|
+
declare const AUSPICIOUS_HOURS: string[];
|
|
5
|
+
declare const SOLAR_TERMS: string[];
|
|
6
|
+
declare const HEAVENLY_EARTHLY_ELEMENT_MAP: Record<string, string>;
|
|
7
|
+
declare const AUSPICIOUS: string[];
|
|
8
|
+
declare const INAUSPICIOUS: string[];
|
|
9
|
+
declare const ZODIAC_SIGNS: Record<string, string[]>;
|
|
10
|
+
declare const LEAP_TEXT = " (nhu\u1EADn)";
|
|
11
|
+
declare const DAY_OF_WEEK: string[];
|
|
12
|
+
declare const FIRST_DAY: number;
|
|
13
|
+
declare const LAST_DAY: number;
|
|
14
|
+
declare const DATE_FORMAT: string[];
|
|
15
|
+
declare const PI: number;
|
|
16
|
+
export { LIST_YEARS, FIRST_DAY, LAST_DAY, PI, HEAVENLY_STEMS, EARTHLY_BRANCHES, AUSPICIOUS_HOURS, SOLAR_TERMS, DAY_OF_WEEK, LEAP_TEXT, DATE_FORMAT, HEAVENLY_EARTHLY_ELEMENT_MAP, AUSPICIOUS, INAUSPICIOUS, ZODIAC_SIGNS };
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZODIAC_SIGNS = exports.INAUSPICIOUS = exports.AUSPICIOUS = exports.HEAVENLY_EARTHLY_ELEMENT_MAP = exports.DATE_FORMAT = exports.LEAP_TEXT = exports.DAY_OF_WEEK = exports.SOLAR_TERMS = exports.AUSPICIOUS_HOURS = exports.EARTHLY_BRANCHES = exports.HEAVENLY_STEMS = exports.PI = exports.LAST_DAY = exports.FIRST_DAY = exports.LIST_YEARS = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const LIST_YEARS = [
|
|
6
|
+
0x30baa3, 0x56ab50, 0x422ba0, 0x2cab61, 0x52a370, 0x3c51e8, 0x60d160, 0x4ae4b0, 0x376926, 0x58daa0,
|
|
7
|
+
0x445b50, 0x3116d2, 0x562ae0, 0x3ea2e0, 0x28e2d2, 0x4ec950, 0x38d556, 0x5cb520, 0x46b690, 0x325da4,
|
|
8
|
+
0x5855d0, 0x4225d0, 0x2ca5b3, 0x52a2b0, 0x3da8b7, 0x60a950, 0x4ab4a0, 0x35b2a5, 0x5aad50, 0x4455b0,
|
|
9
|
+
0x302b74, 0x562570, 0x4052f9, 0x6452b0, 0x4e6950, 0x386d56, 0x5e5aa0, 0x46ab50, 0x3256d4, 0x584ae0,
|
|
10
|
+
0x42a570, 0x2d4553, 0x50d2a0, 0x3be8a7, 0x60d550, 0x4a5aa0, 0x34ada5, 0x5a95d0, 0x464ae0, 0x2eaab4,
|
|
11
|
+
0x54a4d0, 0x3ed2b8, 0x64b290, 0x4cb550, 0x385757, 0x5e2da0, 0x4895d0, 0x324d75, 0x5849b0, 0x42a4b0,
|
|
12
|
+
0x2da4b3, 0x506a90, 0x3aad98, 0x606b50, 0x4c2b60, 0x359365, 0x5a9370, 0x464970, 0x306964, 0x52e4a0,
|
|
13
|
+
0x3cea6a, 0x62da90, 0x4e5ad0, 0x392ad6, 0x5e2ae0, 0x4892e0, 0x32cad5, 0x56c950, 0x40d4a0, 0x2bd4a3,
|
|
14
|
+
0x50b690, 0x3a57a7, 0x6055b0, 0x4c25d0, 0x3695b5, 0x5a92b0, 0x44a950, 0x2ed954, 0x54b4a0, 0x3cb550,
|
|
15
|
+
0x286b52, 0x4e55b0, 0x3a2776, 0x5e2570, 0x4852b0, 0x32aaa5, 0x56e950, 0x406aa0, 0x2abaa3, 0x50ab50,
|
|
16
|
+
0x3c4bd8, 0x624ae0, 0x4ca570, 0x3854d5, 0x5cd260, 0x44d950, 0x315554, 0x5656a0, 0x409ad0, 0x2a55d2,
|
|
17
|
+
0x504ae0, 0x3aa5b6, 0x60a4d0, 0x48d250, 0x33d255, 0x58b540, 0x42d6a0, 0x2cada2, 0x5295b0, 0x3f4977,
|
|
18
|
+
0x644970, 0x4ca4b0, 0x36b4b5, 0x5c6a50, 0x466d50, 0x312b54, 0x562b60, 0x409570, 0x2c52f2, 0x504970,
|
|
19
|
+
0x3a6566, 0x5ed4a0, 0x48ea50, 0x336a95, 0x585ad0, 0x442b60, 0x2f86e3, 0x5292e0, 0x3dc8d7, 0x62c950,
|
|
20
|
+
0x4cd4a0, 0x35d8a6, 0x5ab550, 0x4656a0, 0x31a5b4, 0x5625d0, 0x4092d0, 0x2ad2b2, 0x50a950, 0x38b557,
|
|
21
|
+
0x5e6ca0, 0x48b550, 0x355355, 0x584da0, 0x42a5b0, 0x2f4573, 0x5452b0, 0x3ca9a8, 0x60e950, 0x4c6aa0,
|
|
22
|
+
0x36aea6, 0x5aab50, 0x464b60, 0x30aae4, 0x56a570, 0x405260, 0x28f263, 0x4ed940, 0x38db47, 0x5cd6a0,
|
|
23
|
+
0x4896d0, 0x344dd5, 0x5a4ad0, 0x42a4d0, 0x2cd4b4, 0x52b250, 0x3cd558, 0x60b540, 0x4ab5a0, 0x3755a6,
|
|
24
|
+
0x5c95b0, 0x4649b0, 0x30a974, 0x56a4b0, 0x40aa50, 0x29aa52, 0x4e6d20, 0x39ad47, 0x5eab60, 0x489370,
|
|
25
|
+
0x344af5, 0x5a4970, 0x4464b0, 0x2c74a3, 0x50ea50, 0x3d6a58, 0x6256a0, 0x4aaad0, 0x3696d5, 0x5c92e0,
|
|
26
|
+
0x46c960, 0x2ed954, 0x54d4a0, 0x3eda50, 0x2a7552, 0x4e56a0, 0x38a7a7, 0x5ea5d0, 0x4a92b0, 0x32aab5,
|
|
27
|
+
0x58a950, 0x42b4a0, 0x2cbaa4, 0x50ad50, 0x3c55d9, 0x624ba0, 0x4ca5b0, 0x375176, 0x5c5270, 0x466930,
|
|
28
|
+
0x307934, 0x546aa0, 0x3ead50, 0x2a5b52, 0x504b60, 0x38a6e6, 0x5ea4e0, 0x48d260, 0x32ea65, 0x56d520,
|
|
29
|
+
0x40daa0, 0x2d56a3, 0x5256d0, 0x3c4afb, 0x6249d0, 0x4ca4d0, 0x37d0b6, 0x5ab250, 0x44b520, 0x2edd25,
|
|
30
|
+
0x54b5a0, 0x3e55d0, 0x2a55b2, 0x5049b0, 0x3aa577, 0x5ea4b0, 0x48aa50, 0x33b255, 0x586d20, 0x40ad60,
|
|
31
|
+
0x2d4b63, 0x525370, 0x3e49e8, 0x60c970, 0x4c54b0, 0x3768a6, 0x5ada50, 0x445aa0, 0x2fa6a4, 0x54aad0,
|
|
32
|
+
0x4052e0, 0x28d2e3, 0x4ec950, 0x38d557, 0x5ed4a0, 0x46d950, 0x325d55, 0x5856a0, 0x42a6d0, 0x2c55d4,
|
|
33
|
+
0x5252b0, 0x3ca9b8, 0x62a930, 0x4ab490, 0x34b6a6, 0x5aad50, 0x4655a0, 0x2eab64, 0x54a570, 0x4052b0,
|
|
34
|
+
0x2ab173, 0x4e6930, 0x386b37, 0x5e6aa0, 0x48ad50, 0x332ad5, 0x582b60, 0x42a570, 0x2e52e4, 0x50d160,
|
|
35
|
+
0x3ae958, 0x60d520, 0x4ada90, 0x355aa6, 0x5a56d0, 0x462ae0, 0x30a9d4, 0x54a2d0, 0x3ed150, 0x28e952,
|
|
36
|
+
0x4eb520, 0x38d727, 0x5eada0, 0x4a55b0, 0x362db5, 0x5a45b0, 0x44a2b0, 0x2eb2b4, 0x54a950, 0x3cb559,
|
|
37
|
+
0x626b20, 0x4cad50, 0x385766, 0x5c5370, 0x484570, 0x326574, 0x5852b0, 0x406950, 0x2a7953, 0x505aa0,
|
|
38
|
+
0x3baaa7, 0x5ea6d0, 0x4a4ae0, 0x35a2e5, 0x5aa550, 0x42d2a0, 0x2de2a4, 0x52d550, 0x3e5abb, 0x6256a0,
|
|
39
|
+
0x4c96d0, 0x3949b6, 0x5e4ab0, 0x46a8d0, 0x30d4b5, 0x56b290, 0x40b550, 0x2a6d52, 0x504da0, 0x3b9567,
|
|
40
|
+
0x609570, 0x4a49b0, 0x34a975, 0x5a64b0, 0x446a90, 0x2cba94, 0x526b50, 0x3e2b60, 0x28ab61, 0x4c9570,
|
|
41
|
+
0x384ae6, 0x5cd160, 0x46e4a0, 0x2eed25, 0x54da90, 0x405b50, 0x2c36d3, 0x502ae0, 0x3a93d7, 0x6092d0,
|
|
42
|
+
0x4ac950, 0x32d556, 0x58b4a0, 0x42b690, 0x2e5d94, 0x5255b0, 0x3e25fa, 0x6425b0, 0x4e92b0, 0x36aab6,
|
|
43
|
+
0x5c6950, 0x4674a0, 0x31b2a5, 0x54ad50, 0x4055a0, 0x2aab73, 0x522570, 0x3a5377, 0x6052b0, 0x4a6950,
|
|
44
|
+
0x346d56, 0x585aa0, 0x42ab50, 0x2e56d4, 0x544ae0, 0x3ca570, 0x2864d2, 0x4cd260, 0x36eaa6, 0x5ad550,
|
|
45
|
+
0x465aa0, 0x30ada5, 0x5695d0, 0x404ad0, 0x2aa9b3, 0x50a4d0, 0x3ad2b7, 0x5eb250, 0x48b540, 0x33d556
|
|
46
|
+
];
|
|
47
|
+
exports.LIST_YEARS = LIST_YEARS;
|
|
48
|
+
const HEAVENLY_STEMS = ['Giáp', 'Ất', 'Bính', 'Đinh', 'Mậu', 'Kỷ', 'Canh', 'Tân', 'Nhâm', 'Quý'];
|
|
49
|
+
exports.HEAVENLY_STEMS = HEAVENLY_STEMS;
|
|
50
|
+
const EARTHLY_BRANCHES = ['Tý', 'Sửu', 'Dần', 'Mão', 'Thìn', 'Tỵ', 'Ngọ', 'Mùi', 'Thân', 'Dậu', 'Tuất', 'Hợi'];
|
|
51
|
+
exports.EARTHLY_BRANCHES = EARTHLY_BRANCHES;
|
|
52
|
+
const AUSPICIOUS_HOURS = ['110100101100', '001101001011', '110011010010', '101100110100', '001011001101', '010010110011'];
|
|
53
|
+
exports.AUSPICIOUS_HOURS = AUSPICIOUS_HOURS;
|
|
54
|
+
const SOLAR_TERMS = ['Xuân Phân', 'Thanh Minh', 'Cốc Vũ', 'Lập Hạ', 'Tiểu Mãn', 'Mang Chủng', 'Hạ Chí', 'Tiểu Thử', 'Đại Thử', 'Lập Thu', 'Xử Thử', 'Bạch Lộ', 'Thu Phân', 'Hàn Lộ', 'Sương Giáng', 'Lập Đông', 'Tiểu Tuyết', 'Đại Tuyết', 'Đông Chí', 'Tiểu Hàn', 'Đại Hàn', 'Lập Xuân', 'Vũ Thủy', 'Kinh Trập'];
|
|
55
|
+
exports.SOLAR_TERMS = SOLAR_TERMS;
|
|
56
|
+
const HEAVENLY_EARTHLY_ELEMENT_MAP = {
|
|
57
|
+
'Giáp Tý': 'Hải Trung Kim',
|
|
58
|
+
'Ất Sửu': 'Hải Trung Kim',
|
|
59
|
+
'Bính Dần': 'Lư Trung Hỏa',
|
|
60
|
+
'Đinh Mão': 'Lư Trung Hỏa',
|
|
61
|
+
'Mậu Thìn': 'Đại Lâm Mộc',
|
|
62
|
+
'Kỷ Tỵ': 'Đại Lâm Mộc',
|
|
63
|
+
'Canh Ngọ': 'Lộ Bàng Thổ',
|
|
64
|
+
'Tân Mùi': 'Lộ Bàng Thổ',
|
|
65
|
+
'Nhâm Thân': 'Kiếm Phong Kim',
|
|
66
|
+
'Quý Dậu': 'Kiếm Phong Kim',
|
|
67
|
+
'Giáp Tuất': 'Sơn Đầu Hỏa',
|
|
68
|
+
'Ất Hợi': 'Sơn Đầu Hỏa',
|
|
69
|
+
'Bính Tý': 'Giản Hạ Thủy',
|
|
70
|
+
'Đinh Sửu': 'Giản Hạ Thủy',
|
|
71
|
+
'Mậu Dần': 'Thành Đầu Thổ',
|
|
72
|
+
'Kỷ Mão': 'Thành Đầu Thổ',
|
|
73
|
+
'Canh Thìn': 'Bạch Lạp Kim',
|
|
74
|
+
'Tân Tỵ': 'Bạch Lạp Kim',
|
|
75
|
+
'Nhâm Ngọ': 'Dương Liễu Mộc',
|
|
76
|
+
'Quý Mùi': 'Dương Liễu Mộc',
|
|
77
|
+
'Giáp Thân': 'Tuyền Trung Thủy',
|
|
78
|
+
'Ất Dậu': 'Tuyền Trung Thủy',
|
|
79
|
+
'Bính Tuất': 'Ốc Thượng Thổ',
|
|
80
|
+
'Đinh Hợi': 'Ốc Thượng Thổ',
|
|
81
|
+
'Mậu Tý': 'Tích Lịch Hỏa',
|
|
82
|
+
'Kỷ Sửu': 'Tích Lịch Hỏa',
|
|
83
|
+
'Canh Dần': 'Tùng Bách Mộc',
|
|
84
|
+
'Tân Mão': 'Tùng Bách Mộc',
|
|
85
|
+
'Nhâm Thìn': 'Trường Lưu Thủy',
|
|
86
|
+
'Quý Tỵ': 'Trường Lưu Thủy',
|
|
87
|
+
'Giáp Ngọ': 'Sa Trung Kim',
|
|
88
|
+
'Ất Mùi': 'Sa Trung Kim',
|
|
89
|
+
'Bính Thân': 'Sơn Hạ Hỏa',
|
|
90
|
+
'Đinh Dậu': 'Sơn Hạ Hỏa',
|
|
91
|
+
'Mậu Tuất': 'Bình Địa Mộc',
|
|
92
|
+
'Kỷ Hợi': 'Bình Địa Mộc',
|
|
93
|
+
'Canh Tý': 'Bích Lư Trung Thổ',
|
|
94
|
+
'Tân Sửu': 'Bích Lư Trung Thổ',
|
|
95
|
+
'Nhâm Dần': 'Kim Bạch Kim',
|
|
96
|
+
'Quý Mão': 'Kim Bạch Kim',
|
|
97
|
+
'Giáp Thìn': 'Phúc Đăng Hỏa',
|
|
98
|
+
'Ất Tỵ': 'Phúc Đăng Hỏa',
|
|
99
|
+
'Bính Ngọ': 'Thiên Hà Thủy',
|
|
100
|
+
'Đinh Mùi': 'Thiên Hà Thủy',
|
|
101
|
+
'Mậu Thân': 'Đại Trạch Thổ',
|
|
102
|
+
'Kỷ Dậu': 'Đại Trạch Thổ',
|
|
103
|
+
'Canh Tuất': 'Thoa Xuyến Kim',
|
|
104
|
+
'Tân Hợi': 'Thoa Xuyến Kim',
|
|
105
|
+
'Nhâm Tý': 'Tang Đố Mộc',
|
|
106
|
+
'Quý Sửu': 'Tang Đố Mộc',
|
|
107
|
+
'Giáp Dần': 'Đại Khê Thủy',
|
|
108
|
+
'Ất Mão': 'Đại Khê Thủy',
|
|
109
|
+
'Bính Thìn': 'Sa Trung Thổ',
|
|
110
|
+
'Đinh Tỵ': 'Sa Trung Thổ',
|
|
111
|
+
'Mậu Ngọ': 'Thiên Thượng Hỏa',
|
|
112
|
+
'Kỷ Mùi': 'Thiên Thượng Hỏa',
|
|
113
|
+
'Canh Thân': 'Thạch Lựu Mộc',
|
|
114
|
+
'Tân Dậu': 'Thạch Lựu Mộc',
|
|
115
|
+
'Nhâm Tuất': 'Đại Hải Thủy',
|
|
116
|
+
'Quý Hợi': 'Đại Hải Thủy'
|
|
117
|
+
};
|
|
118
|
+
exports.HEAVENLY_EARTHLY_ELEMENT_MAP = HEAVENLY_EARTHLY_ELEMENT_MAP;
|
|
119
|
+
const AUSPICIOUS = ['Thanh Long', 'Minh Đường', 'Kim Quỹ', 'Thiên Đức', 'Ngọc Đường', 'Tư Mệnh'];
|
|
120
|
+
exports.AUSPICIOUS = AUSPICIOUS;
|
|
121
|
+
const INAUSPICIOUS = ['Thiên Hình', 'Chu Tước', 'Bạch Hổ', 'Câu Trận', 'Thiên Lao', 'Huyền Vũ'];
|
|
122
|
+
exports.INAUSPICIOUS = INAUSPICIOUS;
|
|
123
|
+
const ZODIAC_SIGNS = {
|
|
124
|
+
'Dần': ['Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh'],
|
|
125
|
+
'Thân': ['Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh'],
|
|
126
|
+
'Mão': ['Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận'],
|
|
127
|
+
'Dậu': ['Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận'],
|
|
128
|
+
'Thìn': ['Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long'],
|
|
129
|
+
'Tuất': ['Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long'],
|
|
130
|
+
'Tỵ': ['Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường'],
|
|
131
|
+
'Hợi': ['Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường'],
|
|
132
|
+
'Ngọ': ['Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình'],
|
|
133
|
+
'Tý': ['Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình'],
|
|
134
|
+
'Mùi': ['Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước'],
|
|
135
|
+
'Sửu': ['Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước']
|
|
136
|
+
};
|
|
137
|
+
exports.ZODIAC_SIGNS = ZODIAC_SIGNS;
|
|
138
|
+
const LEAP_TEXT = ' (nhuận)';
|
|
139
|
+
exports.LEAP_TEXT = LEAP_TEXT;
|
|
140
|
+
const DAY_OF_WEEK = ['Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy'];
|
|
141
|
+
exports.DAY_OF_WEEK = DAY_OF_WEEK;
|
|
142
|
+
const FIRST_DAY = (0, utils_1.getJulianDayNumber)(25, 1, 1800);
|
|
143
|
+
exports.FIRST_DAY = FIRST_DAY;
|
|
144
|
+
const LAST_DAY = (0, utils_1.getJulianDayNumber)(31, 12, 2199);
|
|
145
|
+
exports.LAST_DAY = LAST_DAY;
|
|
146
|
+
const DATE_FORMAT = ["D/M/YYYY", "DD/M/YYYY", "D/MM/YYYY", "DD/MM/YYYY"];
|
|
147
|
+
exports.DATE_FORMAT = DATE_FORMAT;
|
|
148
|
+
const PI = Math.PI;
|
|
149
|
+
exports.PI = PI;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFirstHeavenlyHour = exports.getHeavenlyEarthly = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const getYearHeavenlyEarthly = (year) => {
|
|
6
|
+
return constants_1.HEAVENLY_STEMS[(year + 6) % 10] + " " + constants_1.EARTHLY_BRANCHES[(year + 8) % 12];
|
|
7
|
+
};
|
|
8
|
+
const getHeavenlyEarthly = (lunarDate) => {
|
|
9
|
+
const { julianDay, month, year, isLeap } = lunarDate;
|
|
10
|
+
const dayStemIndex = (julianDay + 9) % 10;
|
|
11
|
+
const dayBranchIndex = (julianDay + 1) % 12;
|
|
12
|
+
const dayHeavenlyEarthly = `${constants_1.HEAVENLY_STEMS[dayStemIndex]} ${constants_1.EARTHLY_BRANCHES[dayBranchIndex]}`;
|
|
13
|
+
const monthStemIndex = (year * 12 + month + 3) % 10;
|
|
14
|
+
const monthBranchIndex = (month + 1) % 12;
|
|
15
|
+
let monthHeavenlyEarthly = `${constants_1.HEAVENLY_STEMS[monthStemIndex]} ${constants_1.EARTHLY_BRANCHES[monthBranchIndex]}`;
|
|
16
|
+
if (isLeap) {
|
|
17
|
+
monthHeavenlyEarthly += constants_1.LEAP_TEXT;
|
|
18
|
+
}
|
|
19
|
+
const yearHeavenlyEarthly = getYearHeavenlyEarthly(year);
|
|
20
|
+
return {
|
|
21
|
+
date: dayHeavenlyEarthly,
|
|
22
|
+
month: monthHeavenlyEarthly,
|
|
23
|
+
year: yearHeavenlyEarthly
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.getHeavenlyEarthly = getHeavenlyEarthly;
|
|
27
|
+
const getFirstHeavenlyHour = (julianDay) => {
|
|
28
|
+
return constants_1.HEAVENLY_STEMS[(julianDay - 1) * 2 % 10];
|
|
29
|
+
};
|
|
30
|
+
exports.getFirstHeavenlyHour = getFirstHeavenlyHour;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getVietnameseHolidays: (lunarDay: number, lunarMonth: number) => string;
|
package/lib/holidays.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVietnameseHolidays = void 0;
|
|
4
|
+
const HOLIDAYS = {
|
|
5
|
+
"1-1": "Tết Nguyên Đán",
|
|
6
|
+
"2-1": "Tết Nguyên Đán",
|
|
7
|
+
"3-1": "Tết Nguyên Đán",
|
|
8
|
+
"15-1": "Tết Nguyên Tiêu",
|
|
9
|
+
"3-3": "Tết Hàn Thực",
|
|
10
|
+
"10-3": "Giỗ Tổ Hùng Vương",
|
|
11
|
+
"15-4": "Lễ Phật Đản",
|
|
12
|
+
"5-5": "Tết Đoan Ngọ",
|
|
13
|
+
"7-7": "Tết Thất Tịch",
|
|
14
|
+
"15-7": "Lễ Vu Lan",
|
|
15
|
+
"15-8": "Tết Trung Thu",
|
|
16
|
+
"9-9": "Tết Trùng Cửu",
|
|
17
|
+
"10-10": "Tết Thường Tân",
|
|
18
|
+
"15-10": "Tết Hạ Nguyên",
|
|
19
|
+
"23-12": "Lễ cúng Ông Táo",
|
|
20
|
+
};
|
|
21
|
+
const getVietnameseHolidays = (lunarDay, lunarMonth) => {
|
|
22
|
+
const key = `${lunarDay}-${lunarMonth}`;
|
|
23
|
+
return HOLIDAYS[key] ? HOLIDAYS[key] : '';
|
|
24
|
+
};
|
|
25
|
+
exports.getVietnameseHolidays = getVietnameseHolidays;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { dayInfo, lunarDay } from './lunarConverter';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lunarDay = exports.dayInfo = void 0;
|
|
4
|
+
var lunarConverter_1 = require("./lunarConverter");
|
|
5
|
+
Object.defineProperty(exports, "dayInfo", { enumerable: true, get: function () { return lunarConverter_1.dayInfo; } });
|
|
6
|
+
Object.defineProperty(exports, "lunarDay", { enumerable: true, get: function () { return lunarConverter_1.lunarDay; } });
|
package/lib/lunar.d.ts
ADDED
package/lib/lunar.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDayMaster = exports.getLunarDate = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const decodeLunarYear = (year, lunarInfo) => {
|
|
7
|
+
const monthDayLengths = [29, 30];
|
|
8
|
+
const monthDays = new Array(12);
|
|
9
|
+
let offsetOfTet, leapMonth, leapMonthLength, solarNY, currentJulianDay, julian, month;
|
|
10
|
+
let listYears = [];
|
|
11
|
+
offsetOfTet = lunarInfo >> 17;
|
|
12
|
+
leapMonth = lunarInfo & 0xf;
|
|
13
|
+
leapMonthLength = monthDayLengths[lunarInfo >> 16 & 0x1];
|
|
14
|
+
solarNY = (0, utils_1.getJulianDayNumber)(1, 1, year);
|
|
15
|
+
currentJulianDay = solarNY + offsetOfTet;
|
|
16
|
+
julian = lunarInfo >> 4;
|
|
17
|
+
for (let monthIndex = 0; monthIndex < 12; monthIndex++) {
|
|
18
|
+
monthDays[12 - monthIndex - 1] = monthDayLengths[julian & 0x1];
|
|
19
|
+
julian >>= 1;
|
|
20
|
+
}
|
|
21
|
+
if (leapMonth === 0) {
|
|
22
|
+
for (month = 1; month <= 12; month++) {
|
|
23
|
+
listYears.push({
|
|
24
|
+
date: 1,
|
|
25
|
+
month: month,
|
|
26
|
+
year: year,
|
|
27
|
+
isLeap: false,
|
|
28
|
+
julianDay: currentJulianDay
|
|
29
|
+
});
|
|
30
|
+
currentJulianDay += monthDays[month - 1];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
for (month = 1; month <= leapMonth; month++) {
|
|
35
|
+
listYears.push({
|
|
36
|
+
date: 1,
|
|
37
|
+
month: month,
|
|
38
|
+
year: year,
|
|
39
|
+
isLeap: false,
|
|
40
|
+
julianDay: currentJulianDay
|
|
41
|
+
});
|
|
42
|
+
currentJulianDay += monthDays[month - 1];
|
|
43
|
+
}
|
|
44
|
+
listYears.push({
|
|
45
|
+
date: 1,
|
|
46
|
+
month: leapMonth,
|
|
47
|
+
year: year,
|
|
48
|
+
isLeap: true,
|
|
49
|
+
julianDay: currentJulianDay
|
|
50
|
+
});
|
|
51
|
+
currentJulianDay += leapMonthLength;
|
|
52
|
+
for (month = leapMonth + 1; month <= 12; month++) {
|
|
53
|
+
listYears.push({
|
|
54
|
+
date: 1,
|
|
55
|
+
month: month,
|
|
56
|
+
year: year,
|
|
57
|
+
isLeap: false,
|
|
58
|
+
julianDay: currentJulianDay
|
|
59
|
+
});
|
|
60
|
+
currentJulianDay += monthDays[month - 1];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return listYears;
|
|
64
|
+
};
|
|
65
|
+
const getYearInfo = (year) => {
|
|
66
|
+
let yearCode;
|
|
67
|
+
if (year >= 1800 && year < 2200) {
|
|
68
|
+
const index = year - 1800;
|
|
69
|
+
yearCode = constants_1.LIST_YEARS[index];
|
|
70
|
+
return decodeLunarYear(year, yearCode);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error("Year out of supported range (1800–2199)");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const findLunarDate = (julianDay, lunarYear) => {
|
|
77
|
+
if (julianDay > constants_1.LAST_DAY ||
|
|
78
|
+
julianDay < constants_1.FIRST_DAY ||
|
|
79
|
+
lunarYear[0].julianDay > julianDay) {
|
|
80
|
+
return { date: 0, month: 0, year: 0, isLeap: false, julianDay };
|
|
81
|
+
}
|
|
82
|
+
let index = lunarYear.length - 1;
|
|
83
|
+
while (julianDay < lunarYear[index].julianDay) {
|
|
84
|
+
index--;
|
|
85
|
+
}
|
|
86
|
+
const offset = julianDay - lunarYear[index].julianDay;
|
|
87
|
+
return {
|
|
88
|
+
date: lunarYear[index].date + offset,
|
|
89
|
+
month: lunarYear[index].month,
|
|
90
|
+
year: lunarYear[index].year,
|
|
91
|
+
isLeap: lunarYear[index].isLeap,
|
|
92
|
+
julianDay
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const getLunarDate = (day, month, year) => {
|
|
96
|
+
let lunarYearData, julianDay;
|
|
97
|
+
if (year < 1800 || year > 2199) {
|
|
98
|
+
return { date: 0, month: 0, year: 0, isLeap: false, julianDay: 0 };
|
|
99
|
+
}
|
|
100
|
+
lunarYearData = getYearInfo(year);
|
|
101
|
+
julianDay = (0, utils_1.getJulianDayNumber)(day, month, year);
|
|
102
|
+
if (julianDay < lunarYearData[0].julianDay) {
|
|
103
|
+
lunarYearData = getYearInfo(year - 1);
|
|
104
|
+
}
|
|
105
|
+
return findLunarDate(julianDay, lunarYearData);
|
|
106
|
+
};
|
|
107
|
+
exports.getLunarDate = getLunarDate;
|
|
108
|
+
const getDayMaster = (date) => {
|
|
109
|
+
return constants_1.HEAVENLY_EARTHLY_ELEMENT_MAP[date] || 'Không rõ';
|
|
110
|
+
};
|
|
111
|
+
exports.getDayMaster = getDayMaster;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.lunarDay = exports.dayInfo = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const holidays_1 = require("./holidays");
|
|
10
|
+
const heavenly_earthly_1 = require("./heavenly_earthly");
|
|
11
|
+
const lunar_1 = require("./lunar");
|
|
12
|
+
const auspiciousHours_1 = require("./auspiciousHours");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const getDayName = (lunarDate) => {
|
|
15
|
+
if (lunarDate.date === 0) {
|
|
16
|
+
return {
|
|
17
|
+
date: '',
|
|
18
|
+
month: '',
|
|
19
|
+
year: ''
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return (0, heavenly_earthly_1.getHeavenlyEarthly)(lunarDate);
|
|
23
|
+
};
|
|
24
|
+
const isValidDate = (dateString) => {
|
|
25
|
+
const momentDate = (0, moment_1.default)(dateString, constants_1.DATE_FORMAT, true);
|
|
26
|
+
return momentDate.isValid() && momentDate.year() > 1800 && momentDate.year() < 2200;
|
|
27
|
+
};
|
|
28
|
+
const dayInfo = (dateString) => {
|
|
29
|
+
if (!isValidDate(dateString)) {
|
|
30
|
+
return 'Invalid date input.';
|
|
31
|
+
}
|
|
32
|
+
const momentDate = (0, moment_1.default)(dateString, constants_1.DATE_FORMAT, true);
|
|
33
|
+
const LUNAR_DAY = (0, lunar_1.getLunarDate)(momentDate.date(), momentDate.month() + 1, momentDate.year());
|
|
34
|
+
const LUNAR_DAY_TEXT = getDayName(LUNAR_DAY);
|
|
35
|
+
return {
|
|
36
|
+
day: constants_1.DAY_OF_WEEK[(LUNAR_DAY.julianDay + 1) % 7],
|
|
37
|
+
solarDate: momentDate.format('D/M/YYYY'),
|
|
38
|
+
lunarDate: { date: LUNAR_DAY.date, month: LUNAR_DAY.month, isLeap: LUNAR_DAY.isLeap },
|
|
39
|
+
lunarDateText: LUNAR_DAY_TEXT,
|
|
40
|
+
firstHour: (0, heavenly_earthly_1.getFirstHeavenlyHour)(LUNAR_DAY.julianDay) + ' ' + constants_1.EARTHLY_BRANCHES[0],
|
|
41
|
+
solarTerms: constants_1.SOLAR_TERMS[(0, utils_1.calculateSunLongitudeInTimeZone)(LUNAR_DAY.julianDay + 1, 7)],
|
|
42
|
+
auspiciousHours: (0, auspiciousHours_1.getAuspiciousHours)(LUNAR_DAY.julianDay),
|
|
43
|
+
inAuspiciousHours: (0, auspiciousHours_1.getInauspiciousHours)(LUNAR_DAY.julianDay),
|
|
44
|
+
dayMaster: (0, lunar_1.getDayMaster)(LUNAR_DAY_TEXT.date),
|
|
45
|
+
holiday: (0, holidays_1.getVietnameseHolidays)(LUNAR_DAY.date, LUNAR_DAY.month)
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.dayInfo = dayInfo;
|
|
49
|
+
const lunarDay = (dateString) => {
|
|
50
|
+
if (!isValidDate(dateString)) {
|
|
51
|
+
return 'Invalid date input.';
|
|
52
|
+
}
|
|
53
|
+
const momentDate = (0, moment_1.default)(dateString, constants_1.DATE_FORMAT, true);
|
|
54
|
+
const LUNAR_DAY = (0, lunar_1.getLunarDate)(momentDate.date(), momentDate.month() + 1, momentDate.year());
|
|
55
|
+
const LUNAR_DAY_TEXT = getDayName(LUNAR_DAY);
|
|
56
|
+
return {
|
|
57
|
+
date: LUNAR_DAY.date,
|
|
58
|
+
date_text: LUNAR_DAY_TEXT,
|
|
59
|
+
month: LUNAR_DAY.month,
|
|
60
|
+
isLeap: LUNAR_DAY.isLeap
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.lunarDay = lunarDay;
|
package/lib/type.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type LunarDate = {
|
|
2
|
+
date: number;
|
|
3
|
+
month: number;
|
|
4
|
+
year: number;
|
|
5
|
+
isLeap: boolean;
|
|
6
|
+
julianDay: number;
|
|
7
|
+
};
|
|
8
|
+
type dateFormat = {
|
|
9
|
+
date: string | number;
|
|
10
|
+
month: string | number;
|
|
11
|
+
year: string | number;
|
|
12
|
+
};
|
|
13
|
+
export { LunarDate, dateFormat };
|
package/lib/type.js
ADDED
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateSunLongitudeInTimeZone = exports.getJulianDayNumber = exports.INT = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const INT = (number) => {
|
|
6
|
+
return Math.floor(number);
|
|
7
|
+
};
|
|
8
|
+
exports.INT = INT;
|
|
9
|
+
const getJulianDayNumber = (day, month, year) => {
|
|
10
|
+
const adjustment = (0, exports.INT)((14 - month) / 12);
|
|
11
|
+
const adjustedYear = year + 4800 - adjustment;
|
|
12
|
+
const adjustedMonth = month + 12 * adjustment - 3;
|
|
13
|
+
return day + (0, exports.INT)((153 * adjustedMonth + 2) / 5) + 365 * adjustedYear + (0, exports.INT)(adjustedYear / 4) - (0, exports.INT)(adjustedYear / 100) + (0, exports.INT)(adjustedYear / 400) - 32045;
|
|
14
|
+
};
|
|
15
|
+
exports.getJulianDayNumber = getJulianDayNumber;
|
|
16
|
+
const calculateSunLongitude = (julianDay) => {
|
|
17
|
+
const julianCenturies = (julianDay - 2451545.0) / 36525;
|
|
18
|
+
const julianCenturiesSquared = julianCenturies * julianCenturies;
|
|
19
|
+
const degreeToRadian = constants_1.PI / 180;
|
|
20
|
+
const meanAnomaly = 357.52910
|
|
21
|
+
+ 35999.05030 * julianCenturies
|
|
22
|
+
- 0.0001559 * julianCenturiesSquared
|
|
23
|
+
- 0.00000048 * julianCenturies * julianCenturiesSquared;
|
|
24
|
+
const meanLongitude = 280.46645
|
|
25
|
+
+ 36000.76983 * julianCenturies
|
|
26
|
+
+ 0.0003032 * julianCenturiesSquared;
|
|
27
|
+
let longitudeCorrection = (1.914600 - 0.004817 * julianCenturies - 0.000014 * julianCenturiesSquared) * Math.sin(degreeToRadian * meanAnomaly);
|
|
28
|
+
longitudeCorrection += (0.019993 - 0.000101 * julianCenturies) * Math.sin(degreeToRadian * 2 * meanAnomaly);
|
|
29
|
+
longitudeCorrection += 0.000290 * Math.sin(degreeToRadian * 3 * meanAnomaly);
|
|
30
|
+
let trueLongitude = meanLongitude + longitudeCorrection;
|
|
31
|
+
trueLongitude *= degreeToRadian;
|
|
32
|
+
trueLongitude -= constants_1.PI * 2 * (0, exports.INT)(trueLongitude / (constants_1.PI * 2));
|
|
33
|
+
return trueLongitude;
|
|
34
|
+
};
|
|
35
|
+
const calculateSunLongitudeInTimeZone = (julianDay, timeZoneOffset) => {
|
|
36
|
+
const adjustedDay = julianDay - 0.5 - timeZoneOffset / 24.0;
|
|
37
|
+
const sunLongitude = calculateSunLongitude(adjustedDay);
|
|
38
|
+
return (0, exports.INT)(sunLongitude / constants_1.PI * 12);
|
|
39
|
+
};
|
|
40
|
+
exports.calculateSunLongitudeInTimeZone = calculateSunLongitudeInTimeZone;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vietnamese-lunar",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Convert Sonar to Lunar",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": ["lib"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "bun test/test.ts"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://gitlab.com/tandd.packages/vietnamese-lunar-calendar.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"lunar",
|
|
18
|
+
"calendar",
|
|
19
|
+
"date",
|
|
20
|
+
"converter",
|
|
21
|
+
"lunisolar",
|
|
22
|
+
"solar to lunar",
|
|
23
|
+
"lunar calendar",
|
|
24
|
+
"vietnamese calendar",
|
|
25
|
+
"chinese calendar",
|
|
26
|
+
"moon phase",
|
|
27
|
+
"lunar date",
|
|
28
|
+
"astrology",
|
|
29
|
+
"traditional calendar",
|
|
30
|
+
"lunar new year",
|
|
31
|
+
"tết",
|
|
32
|
+
"âm lịch",
|
|
33
|
+
"am lich",
|
|
34
|
+
"lịch âm",
|
|
35
|
+
"lich am"
|
|
36
|
+
],
|
|
37
|
+
"author": "TanDD <https://tandd.dev>",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://gitlab.com/tandd.packages/vietnamese-lunar-calendar/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://gitlab.com/tandd.packages/vietnamese-lunar-calendar#readme",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"moment": "^2.30.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"typescript": "^5.9.3"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# 🌕 Vietnamese Lunar Calendar
|
|
2
|
+
|
|
3
|
+
A lightweight JavaScript utility to convert Gregorian (solar) dates to traditional lunar calendar dates — perfect for apps with cultural, astrological, or calendrical features.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
- Convert solar (Gregorian) dates to lunar dates
|
|
10
|
+
- Support for Vietnamese and Chinese lunar calendars
|
|
11
|
+
- Accurate leap month handling
|
|
12
|
+
- Lightweight and fast
|
|
13
|
+
- No external dependencies
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 📦 Installation
|
|
18
|
+
|
|
19
|
+
npm install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install vietnamese-lunar
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
yarn install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
yarn add vietnamese-lunar
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
bun install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
bun add vietnamese-lunar
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 🚀 Usage
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import {dayInfo, lunarDay} from "vietnamese-lunar";
|
|
41
|
+
|
|
42
|
+
const lunarDate = lunarDay("17/10/2025") // Convert a Gregorian date to lunar date
|
|
43
|
+
console.log(lunarDate);
|
|
44
|
+
```
|
|
45
|
+
outputs:
|
|
46
|
+
|
|
47
|
+
```object
|
|
48
|
+
{
|
|
49
|
+
date: 26,
|
|
50
|
+
date_text: {
|
|
51
|
+
date: "Kỷ Mùi",
|
|
52
|
+
month: "Ất Dậu",
|
|
53
|
+
year: "Ất Tỵ",
|
|
54
|
+
},
|
|
55
|
+
month: 8,
|
|
56
|
+
isLeap: false,
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
const dateInfo = dayInfo("17/10/2025"); // Get detailed info about a specific date
|
|
62
|
+
console.log(dateInfo);
|
|
63
|
+
```
|
|
64
|
+
outputs:
|
|
65
|
+
```object
|
|
66
|
+
{
|
|
67
|
+
day: "Thứ Sáu",
|
|
68
|
+
solarDate: "17/10/2025",
|
|
69
|
+
lunarDate: {
|
|
70
|
+
date: 26,
|
|
71
|
+
month: 8,
|
|
72
|
+
isLeap: false,
|
|
73
|
+
},
|
|
74
|
+
lunarDateText: {
|
|
75
|
+
date: "Kỷ Mùi",
|
|
76
|
+
month: "Ất Dậu",
|
|
77
|
+
year: "Ất Tỵ",
|
|
78
|
+
},
|
|
79
|
+
firstHour: "Giáp Tý",
|
|
80
|
+
solarTerms: "Hàn Lộ",
|
|
81
|
+
auspiciousHours: "Bính Dần (3-5), Đinh Mão (5-7), Kỷ Tỵ (9-11), Nhâm Thân (15-17), Giáp Tuất (19-21), Ất Hợi (21-23)",
|
|
82
|
+
inAuspiciousHours: "Giáp Tý (23-1), Ất Sửu (1-3), Mậu Thìn (7-9), Canh Ngọ (11-13), Tân Mùi (13-15), Quý Dậu (17-19)",
|
|
83
|
+
dayMaster: "Thiên Thượng Hỏa",
|
|
84
|
+
holiday: "",
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
# Interface
|
|
88
|
+
|
|
89
|
+
| Property | |
|
|
90
|
+
|----------------------|-----------------------------------------|
|
|
91
|
+
| day | the day of week, Sunday to Saturday |
|
|
92
|
+
| month | lunar month in number |
|
|
93
|
+
| date | lunar date in number |
|
|
94
|
+
| solarDate | Solar date |
|
|
95
|
+
| lunarDate | lunar date object (date, month, isLeap) |
|
|
96
|
+
| lunarDate.date | the lunar date in number |
|
|
97
|
+
| lunarDate.month | the lunar month in number |
|
|
98
|
+
| lunarDate.isLeap | whether lunar motnh is a leap month |
|
|
99
|
+
| lunarDateText | lunar date object (date, month, year) |
|
|
100
|
+
| lunarDateText.date | the lunar date in ganzhi |
|
|
101
|
+
| lunarDateText.month | the lunar month in ganzhi |
|
|
102
|
+
| lunarDateText.year | the lunar year in ganzhi |
|
|
103
|
+
| firstHour | the ganzhi of first hour of the day |
|
|
104
|
+
| solarTerms | solar terms of the day |
|
|
105
|
+
| dayMaster | the element of the day master |
|
|
106
|
+
| auspiciousHours | list of auspicious hours |
|
|
107
|
+
| inAuspiciousHours | list of inauspicious hours |
|
|
108
|
+
| holiday | public holidays in Vietnam |
|
|
109
|
+
|
|
110
|
+
# Thanks
|
|
111
|
+
|
|
112
|
+
[Hồ Ngọc Đức](https://www.informatik.uni-leipzig.de/~duc/amlich/)
|