vietnamese-lunar 1.0.0 → 2.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/CHANGELOG.md +39 -0
- package/lib/auspiciousHours.d.ts +0 -2
- package/lib/auspiciousHours.js +10 -9
- package/lib/constants.d.ts +3 -4
- package/lib/constants.js +5 -20
- package/lib/dayStar.d.ts +2 -0
- package/lib/dayStar.js +24 -0
- package/lib/heavenly_earthly.d.ts +3 -0
- package/lib/heavenly_earthly.js +15 -4
- package/lib/holidays.d.ts +2 -1
- package/lib/holidays.js +58 -19
- package/lib/index.d.ts +6 -0
- package/lib/index.js +17 -1
- package/lib/lunar.js +1 -1
- package/lib/lunarConverter.d.ts +3 -2
- package/lib/lunarConverter.js +7 -3
- package/lib/type.d.ts +33 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +9 -5
- package/package.json +40 -15
- package/readme.md +127 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this package are documented here. Versions follow [Semantic Versioning](https://semver.org/): a **major** bump (1.x → 2.x) means you may need to change your code.
|
|
4
|
+
|
|
5
|
+
## 2.0.0 — 2026-10-26
|
|
6
|
+
|
|
7
|
+
### ⚠️ Breaking changes
|
|
8
|
+
|
|
9
|
+
- `dayInfo().holiday` (string) is replaced by `dayInfo().holidays` (array). A day can now have several holidays (e.g. 2/9/2020 is both Ngày Quốc khánh and Lễ Vu Lan).
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// v1
|
|
13
|
+
if (info.holiday) show(info.holiday);
|
|
14
|
+
// v2
|
|
15
|
+
info.holidays.forEach(h => show(h.name)); // h: { name, calendar: "solar" | "lunar", isPublicHoliday }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- `auspiciousHours` / `inAuspiciousHours`: the Heavenly Stem (Can) of each hour was wrong in v1 and is now fixed (Ngũ Thử Độn rule). Hour branches and time ranges are unchanged, only the stem text differs — e.g. 7/1/2025: `Giáp Tý (23-1)` → `Mậu Tý (23-1)`.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `dayStar`: Hoàng Đạo / Hắc Đạo day (12-star system, Nguyệt Kiến by solar terms).
|
|
23
|
+
- Solar holidays (Tết Dương lịch, 30/4, 1/5, 2/9, 24/11 from 2026, …), Giao thừa, and `isPublicHoliday` per Labor Code Art. 112.
|
|
24
|
+
- New exports: `getLunarDate`, `getJulianDayNumber`, `getSolarTermIndex`, `getHeavenlyEarthly`, `getDayStemIndex`, `getDayBranchIndex`, `getMonthBranchIndex`, `getDayStarInfo`, `HEAVENLY_STEMS`, `EARTHLY_BRANCHES`, `SOLAR_TERMS`.
|
|
25
|
+
- TypeScript types: `DayInfo`, `LunarDayInfo`, `LunarDate`, `DayStarInfo`, `Holiday`, `dateFormat`.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- Year 1800 was rejected as invalid input.
|
|
30
|
+
- Lunar holidays were repeated in leap months (e.g. Lễ Vu Lan twice in 2006).
|
|
31
|
+
- Importing internal modules in some orders crashed with `ReferenceError` (circular import).
|
|
32
|
+
|
|
33
|
+
### Unchanged
|
|
34
|
+
|
|
35
|
+
- Solar → lunar conversion (`lunarDay()`, `lunarDate`, `lunarDateText`), `firstHour`, `solarTerms`, `dayMaster` — identical output to v1 for 1801–2199.
|
|
36
|
+
|
|
37
|
+
## 1.0.0 — 2025-11-22
|
|
38
|
+
|
|
39
|
+
- Initial release: `dayInfo()`, `lunarDay()`.
|
package/lib/auspiciousHours.d.ts
CHANGED
package/lib/auspiciousHours.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getInauspiciousHours = exports.getAuspiciousHours = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
const heavenly_earthly_1 = require("./heavenly_earthly");
|
|
6
|
+
const getHourStem = (julianDay, hour) => {
|
|
7
|
+
const firstHourStemIndex = (julianDay - 1) * 2 % 10;
|
|
8
|
+
return constants_1.HEAVENLY_STEMS[(firstHourStemIndex + hour) % 10];
|
|
9
|
+
};
|
|
5
10
|
const getAuspiciousHours = (julianDay) => {
|
|
6
|
-
const earthlyOfDay = (
|
|
11
|
+
const earthlyOfDay = (0, heavenly_earthly_1.getDayBranchIndex)(julianDay);
|
|
7
12
|
const auspiciousHour = constants_1.AUSPICIOUS_HOURS[earthlyOfDay % 6];
|
|
8
13
|
const listAuspiciousHours = [];
|
|
9
14
|
for (let hour = 0; hour < 12; hour++) {
|
|
10
15
|
if (auspiciousHour.charAt(hour) === '1') {
|
|
11
16
|
const start = (hour * 2 + 23) % 24;
|
|
12
17
|
const end = (hour * 2 + 1) % 24;
|
|
13
|
-
listAuspiciousHours.push(`${
|
|
18
|
+
listAuspiciousHours.push(`${getHourStem(julianDay, hour)} ${constants_1.EARTHLY_BRANCHES[hour]} (${String(start)}-${String(end)})`);
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
return listAuspiciousHours.join(', ');
|
|
17
22
|
};
|
|
18
23
|
exports.getAuspiciousHours = getAuspiciousHours;
|
|
19
24
|
const getInauspiciousHours = (julianDay) => {
|
|
20
|
-
const earthlyOfDay = (
|
|
25
|
+
const earthlyOfDay = (0, heavenly_earthly_1.getDayBranchIndex)(julianDay);
|
|
21
26
|
const auspiciousHourPattern = constants_1.AUSPICIOUS_HOURS[earthlyOfDay % 6];
|
|
22
27
|
if (!auspiciousHourPattern || auspiciousHourPattern.length < 12)
|
|
23
28
|
return '';
|
|
@@ -26,13 +31,9 @@ const getInauspiciousHours = (julianDay) => {
|
|
|
26
31
|
if (auspiciousHourPattern.charAt(hour) !== '1') {
|
|
27
32
|
const start = (hour * 2 + 23) % 24;
|
|
28
33
|
const end = (hour * 2 + 1) % 24;
|
|
29
|
-
listInAuspiciousHours.push(`${
|
|
34
|
+
listInAuspiciousHours.push(`${getHourStem(julianDay, hour)} ${constants_1.EARTHLY_BRANCHES[hour]} (${String(start)}-${String(end)})`);
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
return listInAuspiciousHours.join(', ');
|
|
33
38
|
};
|
|
34
39
|
exports.getInauspiciousHours = getInauspiciousHours;
|
|
35
|
-
const getLunarDayType = (lunarDate) => {
|
|
36
|
-
return "";
|
|
37
|
-
};
|
|
38
|
-
exports.getLunarDayType = getLunarDayType;
|
package/lib/constants.d.ts
CHANGED
|
@@ -4,13 +4,12 @@ declare const EARTHLY_BRANCHES: string[];
|
|
|
4
4
|
declare const AUSPICIOUS_HOURS: string[];
|
|
5
5
|
declare const SOLAR_TERMS: string[];
|
|
6
6
|
declare const HEAVENLY_EARTHLY_ELEMENT_MAP: Record<string, string>;
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const ZODIAC_SIGNS: Record<string, string[]>;
|
|
7
|
+
declare const DAY_STARS: string[];
|
|
8
|
+
declare const AUSPICIOUS_DAY_STARS: string[];
|
|
10
9
|
declare const LEAP_TEXT = " (nhu\u1EADn)";
|
|
11
10
|
declare const DAY_OF_WEEK: string[];
|
|
12
11
|
declare const FIRST_DAY: number;
|
|
13
12
|
declare const LAST_DAY: number;
|
|
14
13
|
declare const DATE_FORMAT: string[];
|
|
15
14
|
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,
|
|
15
|
+
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, DAY_STARS, AUSPICIOUS_DAY_STARS };
|
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AUSPICIOUS_DAY_STARS = exports.DAY_STARS = 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
4
|
const utils_1 = require("./utils");
|
|
5
5
|
const LIST_YEARS = [
|
|
6
6
|
0x30baa3, 0x56ab50, 0x422ba0, 0x2cab61, 0x52a370, 0x3c51e8, 0x60d160, 0x4ae4b0, 0x376926, 0x58daa0,
|
|
@@ -116,25 +116,10 @@ const HEAVENLY_EARTHLY_ELEMENT_MAP = {
|
|
|
116
116
|
'Quý Hợi': 'Đại Hải Thủy'
|
|
117
117
|
};
|
|
118
118
|
exports.HEAVENLY_EARTHLY_ELEMENT_MAP = HEAVENLY_EARTHLY_ELEMENT_MAP;
|
|
119
|
-
const
|
|
120
|
-
exports.
|
|
121
|
-
const
|
|
122
|
-
exports.
|
|
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;
|
|
119
|
+
const DAY_STARS = ['Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Thiên Đức', 'Bạch Hổ', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận'];
|
|
120
|
+
exports.DAY_STARS = DAY_STARS;
|
|
121
|
+
const AUSPICIOUS_DAY_STARS = ['Thanh Long', 'Minh Đường', 'Kim Quỹ', 'Thiên Đức', 'Ngọc Đường', 'Tư Mệnh'];
|
|
122
|
+
exports.AUSPICIOUS_DAY_STARS = AUSPICIOUS_DAY_STARS;
|
|
138
123
|
const LEAP_TEXT = ' (nhuận)';
|
|
139
124
|
exports.LEAP_TEXT = LEAP_TEXT;
|
|
140
125
|
const DAY_OF_WEEK = ['Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy'];
|
package/lib/dayStar.d.ts
ADDED
package/lib/dayStar.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDayStarInfo = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const heavenly_earthly_1 = require("./heavenly_earthly");
|
|
6
|
+
// Vị trí sao Thanh Long trên Chi ngày, theo Nguyệt Kiến (Chi của tháng tiết khí hiện tại).
|
|
7
|
+
// Suy từ "Thanh Long Hoàng Đạo Ca" (Hiệp Kỷ Biện Phương Thư):
|
|
8
|
+
// Dần/Thân gia Tý, Mão/Dậu khước tại Dần, Thìn/Tuất long vị thượng,
|
|
9
|
+
// Tỵ/Hợi ngọ thượng tồn, Tý/Ngọ lâm Thân địa, Sửu/Mùi Tuất thượng hành.
|
|
10
|
+
// Index = Chi tháng (Tý=0,Sửu=1,Dần=2,...,Hợi=11), value = offset Chi ngày của Thanh Long.
|
|
11
|
+
const THANH_LONG_OFFSET_BY_MONTH_ZHI = [8, 10, 0, 2, 4, 6, 8, 10, 0, 2, 4, 6];
|
|
12
|
+
const getDayStar = (julianDay) => {
|
|
13
|
+
const thanhLongChiIndex = THANH_LONG_OFFSET_BY_MONTH_ZHI[(0, heavenly_earthly_1.getMonthBranchIndex)(julianDay)];
|
|
14
|
+
const starIndex = ((0, heavenly_earthly_1.getDayBranchIndex)(julianDay) - thanhLongChiIndex + 12) % 12;
|
|
15
|
+
return constants_1.DAY_STARS[starIndex];
|
|
16
|
+
};
|
|
17
|
+
const getDayStarInfo = (lunarDate) => {
|
|
18
|
+
if (lunarDate.date === 0) {
|
|
19
|
+
return { star: '', isAuspicious: false };
|
|
20
|
+
}
|
|
21
|
+
const star = getDayStar(lunarDate.julianDay);
|
|
22
|
+
return { star, isAuspicious: constants_1.AUSPICIOUS_DAY_STARS.indexOf(star) !== -1 };
|
|
23
|
+
};
|
|
24
|
+
exports.getDayStarInfo = getDayStarInfo;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { dateFormat, LunarDate } from "./type";
|
|
2
|
+
export declare const getDayStemIndex: (julianDay: number) => number;
|
|
3
|
+
export declare const getDayBranchIndex: (julianDay: number) => number;
|
|
4
|
+
export declare const getMonthBranchIndex: (julianDay: number) => number;
|
|
2
5
|
export declare const getHeavenlyEarthly: (lunarDate: LunarDate) => dateFormat;
|
|
3
6
|
export declare const getFirstHeavenlyHour: (julianDay: number) => string;
|
package/lib/heavenly_earthly.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFirstHeavenlyHour = exports.getHeavenlyEarthly = void 0;
|
|
3
|
+
exports.getFirstHeavenlyHour = exports.getHeavenlyEarthly = exports.getMonthBranchIndex = exports.getDayBranchIndex = exports.getDayStemIndex = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
// Index of "Lập Xuân" in SOLAR_TERMS; the month branch becomes Dần from this term on.
|
|
7
|
+
const LAP_XUAN_TERM_INDEX = 21;
|
|
8
|
+
const getDayStemIndex = (julianDay) => (julianDay + 9) % 10;
|
|
9
|
+
exports.getDayStemIndex = getDayStemIndex;
|
|
10
|
+
const getDayBranchIndex = (julianDay) => (julianDay + 1) % 12;
|
|
11
|
+
exports.getDayBranchIndex = getDayBranchIndex;
|
|
12
|
+
// Month branch (Nguyệt Kiến) by solar term, not by lunar month number: Tý=0 ... Hợi=11.
|
|
13
|
+
const getMonthBranchIndex = (julianDay) => {
|
|
14
|
+
const termIndex = (0, utils_1.getSolarTermIndex)(julianDay);
|
|
15
|
+
return (Math.floor(((termIndex - LAP_XUAN_TERM_INDEX + 24) % 24) / 2) + 2) % 12;
|
|
16
|
+
};
|
|
17
|
+
exports.getMonthBranchIndex = getMonthBranchIndex;
|
|
5
18
|
const getYearHeavenlyEarthly = (year) => {
|
|
6
19
|
return constants_1.HEAVENLY_STEMS[(year + 6) % 10] + " " + constants_1.EARTHLY_BRANCHES[(year + 8) % 12];
|
|
7
20
|
};
|
|
8
21
|
const getHeavenlyEarthly = (lunarDate) => {
|
|
9
22
|
const { julianDay, month, year, isLeap } = lunarDate;
|
|
10
|
-
const
|
|
11
|
-
const dayBranchIndex = (julianDay + 1) % 12;
|
|
12
|
-
const dayHeavenlyEarthly = `${constants_1.HEAVENLY_STEMS[dayStemIndex]} ${constants_1.EARTHLY_BRANCHES[dayBranchIndex]}`;
|
|
23
|
+
const dayHeavenlyEarthly = `${constants_1.HEAVENLY_STEMS[(0, exports.getDayStemIndex)(julianDay)]} ${constants_1.EARTHLY_BRANCHES[(0, exports.getDayBranchIndex)(julianDay)]}`;
|
|
13
24
|
const monthStemIndex = (year * 12 + month + 3) % 10;
|
|
14
25
|
const monthBranchIndex = (month + 1) % 12;
|
|
15
26
|
let monthHeavenlyEarthly = `${constants_1.HEAVENLY_STEMS[monthStemIndex]} ${constants_1.EARTHLY_BRANCHES[monthBranchIndex]}`;
|
package/lib/holidays.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Holiday, LunarDate } from "./type";
|
|
2
|
+
export declare const getVietnameseHolidays: (solarDay: number, solarMonth: number, solarYear: number, lunarDate: LunarDate, nextLunarDate: LunarDate) => Holiday[];
|
package/lib/holidays.js
CHANGED
|
@@ -1,25 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVietnameseHolidays = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
4
|
+
// isPublicHoliday: ngày nghỉ hưởng nguyên lương theo Điều 112 Bộ luật Lao động 2019 (sửa đổi bởi Nghị quyết 28/2026/QH16).
|
|
5
|
+
// since: năm đầu tiên ngày lễ/kỷ niệm tồn tại; không ghi nhận cho các năm trước đó.
|
|
6
|
+
const SOLAR_HOLIDAYS = {
|
|
7
|
+
"1-1": { name: "Tết Dương lịch", isPublicHoliday: true },
|
|
8
|
+
"3-2": { name: "Ngày thành lập Đảng Cộng sản Việt Nam", isPublicHoliday: false, since: 1930 },
|
|
9
|
+
"27-2": { name: "Ngày Thầy thuốc Việt Nam", isPublicHoliday: false, since: 1955 },
|
|
10
|
+
"8-3": { name: "Ngày Quốc tế Phụ nữ", isPublicHoliday: false, since: 1910 },
|
|
11
|
+
"26-3": { name: "Ngày thành lập Đoàn TNCS Hồ Chí Minh", isPublicHoliday: false, since: 1931 },
|
|
12
|
+
"30-4": { name: "Ngày Giải phóng miền Nam, thống nhất đất nước", isPublicHoliday: true, since: 1975 },
|
|
13
|
+
"1-5": { name: "Ngày Quốc tế Lao động", isPublicHoliday: true, since: 1890 },
|
|
14
|
+
"7-5": { name: "Ngày Chiến thắng Điện Biên Phủ", isPublicHoliday: false, since: 1954 },
|
|
15
|
+
"19-5": { name: "Ngày sinh Chủ tịch Hồ Chí Minh", isPublicHoliday: false, since: 1890 },
|
|
16
|
+
"1-6": { name: "Ngày Quốc tế Thiếu nhi", isPublicHoliday: false, since: 1950 },
|
|
17
|
+
"28-6": { name: "Ngày Gia đình Việt Nam", isPublicHoliday: false, since: 2001 },
|
|
18
|
+
"27-7": { name: "Ngày Thương binh Liệt sĩ", isPublicHoliday: false, since: 1947 },
|
|
19
|
+
"19-8": { name: "Ngày Cách mạng tháng Tám", isPublicHoliday: false, since: 1945 },
|
|
20
|
+
"2-9": { name: "Ngày Quốc khánh", isPublicHoliday: true, since: 1945 },
|
|
21
|
+
"10-10": { name: "Ngày Giải phóng Thủ đô", isPublicHoliday: false, since: 1954 },
|
|
22
|
+
"20-10": { name: "Ngày Phụ nữ Việt Nam", isPublicHoliday: false, since: 1930 },
|
|
23
|
+
"20-11": { name: "Ngày Nhà giáo Việt Nam", isPublicHoliday: false, since: 1982 },
|
|
24
|
+
"24-11": { name: "Ngày Văn hóa Việt Nam", isPublicHoliday: true, since: 2026 },
|
|
25
|
+
"22-12": { name: "Ngày thành lập Quân đội Nhân dân Việt Nam", isPublicHoliday: false, since: 1944 },
|
|
26
|
+
"25-12": { name: "Lễ Giáng sinh", isPublicHoliday: false },
|
|
20
27
|
};
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const LUNAR_HOLIDAYS = {
|
|
29
|
+
"1-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
|
|
30
|
+
"2-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
|
|
31
|
+
"3-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
|
|
32
|
+
"15-1": { name: "Tết Nguyên Tiêu", isPublicHoliday: false },
|
|
33
|
+
"3-3": { name: "Tết Hàn Thực", isPublicHoliday: false },
|
|
34
|
+
"10-3": { name: "Giỗ Tổ Hùng Vương", isPublicHoliday: true },
|
|
35
|
+
"15-4": { name: "Lễ Phật Đản", isPublicHoliday: false },
|
|
36
|
+
"5-5": { name: "Tết Đoan Ngọ", isPublicHoliday: false },
|
|
37
|
+
"7-7": { name: "Tết Thất Tịch", isPublicHoliday: false },
|
|
38
|
+
"15-7": { name: "Lễ Vu Lan", isPublicHoliday: false },
|
|
39
|
+
"15-8": { name: "Tết Trung Thu", isPublicHoliday: false },
|
|
40
|
+
"9-9": { name: "Tết Trùng Cửu", isPublicHoliday: false },
|
|
41
|
+
"10-10": { name: "Tết Thường Tân", isPublicHoliday: false },
|
|
42
|
+
"15-10": { name: "Tết Hạ Nguyên", isPublicHoliday: false },
|
|
43
|
+
"23-12": { name: "Lễ cúng Ông Táo", isPublicHoliday: false },
|
|
44
|
+
};
|
|
45
|
+
const getVietnameseHolidays = (solarDay, solarMonth, solarYear, lunarDate, nextLunarDate) => {
|
|
46
|
+
const holidays = [];
|
|
47
|
+
const solarHoliday = SOLAR_HOLIDAYS[`${solarDay}-${solarMonth}`];
|
|
48
|
+
if (solarHoliday && (solarHoliday.since === undefined || solarYear >= solarHoliday.since)) {
|
|
49
|
+
holidays.push({ name: solarHoliday.name, isPublicHoliday: solarHoliday.isPublicHoliday, calendar: 'solar' });
|
|
50
|
+
}
|
|
51
|
+
// Lễ âm lịch chỉ tính cho tháng thường, tránh lặp lại ở tháng nhuận.
|
|
52
|
+
if (lunarDate.date !== 0 && !lunarDate.isLeap) {
|
|
53
|
+
const lunarHoliday = LUNAR_HOLIDAYS[`${lunarDate.date}-${lunarDate.month}`];
|
|
54
|
+
if (lunarHoliday) {
|
|
55
|
+
holidays.push(Object.assign(Object.assign({}, lunarHoliday), { calendar: 'lunar' }));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Tháng Chạp có thể có 29 hoặc 30 ngày, nên Giao thừa là ngày ngay trước mùng 1 Tết.
|
|
59
|
+
if (nextLunarDate.date === 1 && nextLunarDate.month === 1 && !nextLunarDate.isLeap) {
|
|
60
|
+
holidays.push({ name: "Giao thừa", isPublicHoliday: false, calendar: 'lunar' });
|
|
61
|
+
}
|
|
62
|
+
return holidays;
|
|
24
63
|
};
|
|
25
64
|
exports.getVietnameseHolidays = getVietnameseHolidays;
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export { dayInfo, lunarDay } from './lunarConverter';
|
|
2
|
+
export { getLunarDate } from './lunar';
|
|
3
|
+
export { getJulianDayNumber, getSolarTermIndex } from './utils';
|
|
4
|
+
export { getHeavenlyEarthly, getDayStemIndex, getDayBranchIndex, getMonthBranchIndex, } from './heavenly_earthly';
|
|
5
|
+
export { getDayStarInfo } from './dayStar';
|
|
6
|
+
export { HEAVENLY_STEMS, EARTHLY_BRANCHES, SOLAR_TERMS } from './constants';
|
|
7
|
+
export type { LunarDate, DayInfo, LunarDayInfo, DayStarInfo, Holiday, dateFormat } from './type';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lunarDay = exports.dayInfo = void 0;
|
|
3
|
+
exports.SOLAR_TERMS = exports.EARTHLY_BRANCHES = exports.HEAVENLY_STEMS = exports.getDayStarInfo = exports.getMonthBranchIndex = exports.getDayBranchIndex = exports.getDayStemIndex = exports.getHeavenlyEarthly = exports.getSolarTermIndex = exports.getJulianDayNumber = exports.getLunarDate = exports.lunarDay = exports.dayInfo = void 0;
|
|
4
4
|
var lunarConverter_1 = require("./lunarConverter");
|
|
5
5
|
Object.defineProperty(exports, "dayInfo", { enumerable: true, get: function () { return lunarConverter_1.dayInfo; } });
|
|
6
6
|
Object.defineProperty(exports, "lunarDay", { enumerable: true, get: function () { return lunarConverter_1.lunarDay; } });
|
|
7
|
+
var lunar_1 = require("./lunar");
|
|
8
|
+
Object.defineProperty(exports, "getLunarDate", { enumerable: true, get: function () { return lunar_1.getLunarDate; } });
|
|
9
|
+
var utils_1 = require("./utils");
|
|
10
|
+
Object.defineProperty(exports, "getJulianDayNumber", { enumerable: true, get: function () { return utils_1.getJulianDayNumber; } });
|
|
11
|
+
Object.defineProperty(exports, "getSolarTermIndex", { enumerable: true, get: function () { return utils_1.getSolarTermIndex; } });
|
|
12
|
+
var heavenly_earthly_1 = require("./heavenly_earthly");
|
|
13
|
+
Object.defineProperty(exports, "getHeavenlyEarthly", { enumerable: true, get: function () { return heavenly_earthly_1.getHeavenlyEarthly; } });
|
|
14
|
+
Object.defineProperty(exports, "getDayStemIndex", { enumerable: true, get: function () { return heavenly_earthly_1.getDayStemIndex; } });
|
|
15
|
+
Object.defineProperty(exports, "getDayBranchIndex", { enumerable: true, get: function () { return heavenly_earthly_1.getDayBranchIndex; } });
|
|
16
|
+
Object.defineProperty(exports, "getMonthBranchIndex", { enumerable: true, get: function () { return heavenly_earthly_1.getMonthBranchIndex; } });
|
|
17
|
+
var dayStar_1 = require("./dayStar");
|
|
18
|
+
Object.defineProperty(exports, "getDayStarInfo", { enumerable: true, get: function () { return dayStar_1.getDayStarInfo; } });
|
|
19
|
+
var constants_1 = require("./constants");
|
|
20
|
+
Object.defineProperty(exports, "HEAVENLY_STEMS", { enumerable: true, get: function () { return constants_1.HEAVENLY_STEMS; } });
|
|
21
|
+
Object.defineProperty(exports, "EARTHLY_BRANCHES", { enumerable: true, get: function () { return constants_1.EARTHLY_BRANCHES; } });
|
|
22
|
+
Object.defineProperty(exports, "SOLAR_TERMS", { enumerable: true, get: function () { return constants_1.SOLAR_TERMS; } });
|
package/lib/lunar.js
CHANGED
|
@@ -99,7 +99,7 @@ const getLunarDate = (day, month, year) => {
|
|
|
99
99
|
}
|
|
100
100
|
lunarYearData = getYearInfo(year);
|
|
101
101
|
julianDay = (0, utils_1.getJulianDayNumber)(day, month, year);
|
|
102
|
-
if (julianDay < lunarYearData[0].julianDay) {
|
|
102
|
+
if (julianDay < lunarYearData[0].julianDay && year - 1 >= 1800) {
|
|
103
103
|
lunarYearData = getYearInfo(year - 1);
|
|
104
104
|
}
|
|
105
105
|
return findLunarDate(julianDay, lunarYearData);
|
package/lib/lunarConverter.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import { DayInfo, LunarDayInfo } from "./type";
|
|
2
|
+
export declare const dayInfo: (dateString: string) => DayInfo | string;
|
|
3
|
+
export declare const lunarDay: (dateString: string) => LunarDayInfo | string;
|
package/lib/lunarConverter.js
CHANGED
|
@@ -10,6 +10,7 @@ const holidays_1 = require("./holidays");
|
|
|
10
10
|
const heavenly_earthly_1 = require("./heavenly_earthly");
|
|
11
11
|
const lunar_1 = require("./lunar");
|
|
12
12
|
const auspiciousHours_1 = require("./auspiciousHours");
|
|
13
|
+
const dayStar_1 = require("./dayStar");
|
|
13
14
|
const utils_1 = require("./utils");
|
|
14
15
|
const getDayName = (lunarDate) => {
|
|
15
16
|
if (lunarDate.date === 0) {
|
|
@@ -23,7 +24,7 @@ const getDayName = (lunarDate) => {
|
|
|
23
24
|
};
|
|
24
25
|
const isValidDate = (dateString) => {
|
|
25
26
|
const momentDate = (0, moment_1.default)(dateString, constants_1.DATE_FORMAT, true);
|
|
26
|
-
return momentDate.isValid() && momentDate.year()
|
|
27
|
+
return momentDate.isValid() && momentDate.year() >= 1800 && momentDate.year() <= 2199;
|
|
27
28
|
};
|
|
28
29
|
const dayInfo = (dateString) => {
|
|
29
30
|
if (!isValidDate(dateString)) {
|
|
@@ -32,17 +33,20 @@ const dayInfo = (dateString) => {
|
|
|
32
33
|
const momentDate = (0, moment_1.default)(dateString, constants_1.DATE_FORMAT, true);
|
|
33
34
|
const LUNAR_DAY = (0, lunar_1.getLunarDate)(momentDate.date(), momentDate.month() + 1, momentDate.year());
|
|
34
35
|
const LUNAR_DAY_TEXT = getDayName(LUNAR_DAY);
|
|
36
|
+
const nextDay = momentDate.clone().add(1, 'day');
|
|
37
|
+
const NEXT_LUNAR_DAY = (0, lunar_1.getLunarDate)(nextDay.date(), nextDay.month() + 1, nextDay.year());
|
|
35
38
|
return {
|
|
36
39
|
day: constants_1.DAY_OF_WEEK[(LUNAR_DAY.julianDay + 1) % 7],
|
|
37
40
|
solarDate: momentDate.format('D/M/YYYY'),
|
|
38
41
|
lunarDate: { date: LUNAR_DAY.date, month: LUNAR_DAY.month, isLeap: LUNAR_DAY.isLeap },
|
|
39
42
|
lunarDateText: LUNAR_DAY_TEXT,
|
|
40
43
|
firstHour: (0, heavenly_earthly_1.getFirstHeavenlyHour)(LUNAR_DAY.julianDay) + ' ' + constants_1.EARTHLY_BRANCHES[0],
|
|
41
|
-
solarTerms: constants_1.SOLAR_TERMS[(0, utils_1.
|
|
44
|
+
solarTerms: constants_1.SOLAR_TERMS[(0, utils_1.getSolarTermIndex)(LUNAR_DAY.julianDay)],
|
|
42
45
|
auspiciousHours: (0, auspiciousHours_1.getAuspiciousHours)(LUNAR_DAY.julianDay),
|
|
43
46
|
inAuspiciousHours: (0, auspiciousHours_1.getInauspiciousHours)(LUNAR_DAY.julianDay),
|
|
44
47
|
dayMaster: (0, lunar_1.getDayMaster)(LUNAR_DAY_TEXT.date),
|
|
45
|
-
|
|
48
|
+
dayStar: (0, dayStar_1.getDayStarInfo)(LUNAR_DAY),
|
|
49
|
+
holidays: (0, holidays_1.getVietnameseHolidays)(momentDate.date(), momentDate.month() + 1, momentDate.year(), LUNAR_DAY, NEXT_LUNAR_DAY)
|
|
46
50
|
};
|
|
47
51
|
};
|
|
48
52
|
exports.dayInfo = dayInfo;
|
package/lib/type.d.ts
CHANGED
|
@@ -10,4 +10,36 @@ type dateFormat = {
|
|
|
10
10
|
month: string | number;
|
|
11
11
|
year: string | number;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type DayStarInfo = {
|
|
14
|
+
star: string;
|
|
15
|
+
isAuspicious: boolean;
|
|
16
|
+
};
|
|
17
|
+
type Holiday = {
|
|
18
|
+
name: string;
|
|
19
|
+
calendar: 'solar' | 'lunar';
|
|
20
|
+
isPublicHoliday: boolean;
|
|
21
|
+
};
|
|
22
|
+
type DayInfo = {
|
|
23
|
+
day: string;
|
|
24
|
+
solarDate: string;
|
|
25
|
+
lunarDate: {
|
|
26
|
+
date: number;
|
|
27
|
+
month: number;
|
|
28
|
+
isLeap: boolean;
|
|
29
|
+
};
|
|
30
|
+
lunarDateText: dateFormat;
|
|
31
|
+
firstHour: string;
|
|
32
|
+
solarTerms: string;
|
|
33
|
+
auspiciousHours: string;
|
|
34
|
+
inAuspiciousHours: string;
|
|
35
|
+
dayMaster: string;
|
|
36
|
+
dayStar: DayStarInfo;
|
|
37
|
+
holidays: Holiday[];
|
|
38
|
+
};
|
|
39
|
+
type LunarDayInfo = {
|
|
40
|
+
date: number;
|
|
41
|
+
date_text: dateFormat;
|
|
42
|
+
month: number;
|
|
43
|
+
isLeap: boolean;
|
|
44
|
+
};
|
|
45
|
+
export { LunarDate, dateFormat, DayStarInfo, Holiday, DayInfo, LunarDayInfo };
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const INT: (number: number) => number;
|
|
2
2
|
export declare const getJulianDayNumber: (day: number, month: number, year: number) => number;
|
|
3
3
|
export declare const calculateSunLongitudeInTimeZone: (julianDay: number, timeZoneOffset: number) => number;
|
|
4
|
+
export declare const getSolarTermIndex: (julianDay: number) => number;
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateSunLongitudeInTimeZone = exports.getJulianDayNumber = exports.INT = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
3
|
+
exports.getSolarTermIndex = exports.calculateSunLongitudeInTimeZone = exports.getJulianDayNumber = exports.INT = void 0;
|
|
5
4
|
const INT = (number) => {
|
|
6
5
|
return Math.floor(number);
|
|
7
6
|
};
|
|
@@ -16,7 +15,7 @@ exports.getJulianDayNumber = getJulianDayNumber;
|
|
|
16
15
|
const calculateSunLongitude = (julianDay) => {
|
|
17
16
|
const julianCenturies = (julianDay - 2451545.0) / 36525;
|
|
18
17
|
const julianCenturiesSquared = julianCenturies * julianCenturies;
|
|
19
|
-
const degreeToRadian =
|
|
18
|
+
const degreeToRadian = Math.PI / 180;
|
|
20
19
|
const meanAnomaly = 357.52910
|
|
21
20
|
+ 35999.05030 * julianCenturies
|
|
22
21
|
- 0.0001559 * julianCenturiesSquared
|
|
@@ -29,12 +28,17 @@ const calculateSunLongitude = (julianDay) => {
|
|
|
29
28
|
longitudeCorrection += 0.000290 * Math.sin(degreeToRadian * 3 * meanAnomaly);
|
|
30
29
|
let trueLongitude = meanLongitude + longitudeCorrection;
|
|
31
30
|
trueLongitude *= degreeToRadian;
|
|
32
|
-
trueLongitude -=
|
|
31
|
+
trueLongitude -= Math.PI * 2 * (0, exports.INT)(trueLongitude / (Math.PI * 2));
|
|
33
32
|
return trueLongitude;
|
|
34
33
|
};
|
|
35
34
|
const calculateSunLongitudeInTimeZone = (julianDay, timeZoneOffset) => {
|
|
36
35
|
const adjustedDay = julianDay - 0.5 - timeZoneOffset / 24.0;
|
|
37
36
|
const sunLongitude = calculateSunLongitude(adjustedDay);
|
|
38
|
-
return (0, exports.INT)(sunLongitude /
|
|
37
|
+
return (0, exports.INT)(sunLongitude / Math.PI * 12);
|
|
39
38
|
};
|
|
40
39
|
exports.calculateSunLongitudeInTimeZone = calculateSunLongitudeInTimeZone;
|
|
40
|
+
// Index into SOLAR_TERMS for the given day, Vietnam time (UTC+7).
|
|
41
|
+
const getSolarTermIndex = (julianDay) => {
|
|
42
|
+
return (0, exports.calculateSunLongitudeInTimeZone)(julianDay + 1, 7);
|
|
43
|
+
};
|
|
44
|
+
exports.getSolarTermIndex = getSolarTermIndex;
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vietnamese-lunar",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Vietnamese lunar calendar: solar to lunar conversion, Can Chi, solar terms, Hoàng Đạo days and Vietnamese holidays",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"CHANGELOG.md"
|
|
10
|
+
],
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "tsc",
|
|
10
|
-
"test": "bun test
|
|
13
|
+
"test": "bun test",
|
|
14
|
+
"demo": "bun test/test.ts"
|
|
11
15
|
},
|
|
12
16
|
"repository": {
|
|
13
17
|
"type": "git",
|
|
@@ -16,23 +20,44 @@
|
|
|
16
20
|
"keywords": [
|
|
17
21
|
"lunar",
|
|
18
22
|
"calendar",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
23
|
+
"lunar calendar",
|
|
24
|
+
"lunar date",
|
|
21
25
|
"lunisolar",
|
|
22
26
|
"solar to lunar",
|
|
23
|
-
"
|
|
27
|
+
"date",
|
|
28
|
+
"converter",
|
|
29
|
+
"vietnamese",
|
|
24
30
|
"vietnamese calendar",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"astrology",
|
|
29
|
-
"traditional calendar",
|
|
30
|
-
"lunar new year",
|
|
31
|
-
"tết",
|
|
31
|
+
"vietnamese lunar calendar",
|
|
32
|
+
"vietnam",
|
|
33
|
+
"typescript",
|
|
32
34
|
"âm lịch",
|
|
33
35
|
"am lich",
|
|
34
36
|
"lịch âm",
|
|
35
|
-
"lich am"
|
|
37
|
+
"lich am",
|
|
38
|
+
"lịch vạn niên",
|
|
39
|
+
"lich van nien",
|
|
40
|
+
"tết",
|
|
41
|
+
"tet",
|
|
42
|
+
"lunar new year",
|
|
43
|
+
"can chi",
|
|
44
|
+
"ganzhi",
|
|
45
|
+
"sexagenary cycle",
|
|
46
|
+
"hoàng đạo",
|
|
47
|
+
"hoang dao",
|
|
48
|
+
"hắc đạo",
|
|
49
|
+
"hac dao",
|
|
50
|
+
"giờ hoàng đạo",
|
|
51
|
+
"gio hoang dao",
|
|
52
|
+
"tiết khí",
|
|
53
|
+
"tiet khi",
|
|
54
|
+
"solar terms",
|
|
55
|
+
"ngày lễ",
|
|
56
|
+
"ngay le",
|
|
57
|
+
"vietnamese holidays",
|
|
58
|
+
"public holidays",
|
|
59
|
+
"traditional calendar",
|
|
60
|
+
"astrology"
|
|
36
61
|
],
|
|
37
62
|
"author": "TanDD <https://tandd.dev>",
|
|
38
63
|
"license": "MIT",
|
package/readme.md
CHANGED
|
@@ -7,10 +7,13 @@ A lightweight JavaScript utility to convert Gregorian (solar) dates to tradition
|
|
|
7
7
|
## ✨ Features
|
|
8
8
|
|
|
9
9
|
- Convert solar (Gregorian) dates to lunar dates
|
|
10
|
-
-
|
|
11
|
-
- Accurate leap month handling
|
|
12
|
-
-
|
|
13
|
-
-
|
|
10
|
+
- Vietnamese lunar calendar (computed for UTC+7 — may differ from the Chinese calendar on some dates, e.g. Tết 2007)
|
|
11
|
+
- Accurate leap month handling (data range 1800–2199)
|
|
12
|
+
- Can Chi (ganzhi) of day / month / year, solar terms, auspicious hours
|
|
13
|
+
- Hoàng Đạo / Hắc Đạo days (12-star system, Nguyệt Kiến by solar terms)
|
|
14
|
+
- Vietnamese holidays (solar + lunar, statutory days off)
|
|
15
|
+
- Lightweight — only dependency is `moment`
|
|
16
|
+
- Written in TypeScript, ships with type definitions
|
|
14
17
|
|
|
15
18
|
---
|
|
16
19
|
|
|
@@ -81,7 +84,11 @@ outputs:
|
|
|
81
84
|
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
85
|
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
86
|
dayMaster: "Thiên Thượng Hỏa",
|
|
84
|
-
|
|
87
|
+
dayStar: {
|
|
88
|
+
star: "Chu Tước",
|
|
89
|
+
isAuspicious: false,
|
|
90
|
+
},
|
|
91
|
+
holidays: [],
|
|
85
92
|
}
|
|
86
93
|
```
|
|
87
94
|
# Interface
|
|
@@ -105,7 +112,121 @@ outputs:
|
|
|
105
112
|
| dayMaster | the element of the day master |
|
|
106
113
|
| auspiciousHours | list of auspicious hours |
|
|
107
114
|
| inAuspiciousHours | list of inauspicious hours |
|
|
108
|
-
|
|
|
115
|
+
| dayStar | the day's patron star (12-star system) and whether it's auspicious |
|
|
116
|
+
| dayStar.star | name of the day star (e.g. Thanh Long, Bạch Hổ) |
|
|
117
|
+
| dayStar.isAuspicious | true if the day is "Hoàng Đạo" (auspicious), false if "Hắc Đạo" (inauspicious) |
|
|
118
|
+
| holidays | list of Vietnamese holidays on this date (solar and lunar can both apply) |
|
|
119
|
+
| holidays[].name | holiday name |
|
|
120
|
+
| holidays[].calendar | `solar` or `lunar` — which calendar defines the holiday |
|
|
121
|
+
| holidays[].isPublicHoliday | true for statutory days off (Labor Code 2019, Art. 112) |
|
|
122
|
+
|
|
123
|
+
> **Note on `dayStar`:** the 12-star "Nguyệt Kiến" (month-branch) is derived from solar terms (same method used for `solarTerms`), per the classical "Thanh Long Hoàng Đạo Ca" (Hiệp Kỷ Biện Phương Thư). Some popular Vietnamese almanac sites instead key the month-branch off the lunar calendar month number, which can disagree with this result for up to ~15 days around each solar-term boundary.
|
|
124
|
+
|
|
125
|
+
> **Note on `holidays`:** lunar holidays are only reported in regular (non-leap) months, so they occur once per lunar year. A solar and a lunar holiday can fall on the same day (e.g. 2/9/2020 was also Lễ Vu Lan); both are returned. Solar observances are only reported from the year they were established (e.g. Ngày Văn hóa Việt Nam 24/11 from 2026, per Nghị quyết 28/2026/QH16). `isPublicHoliday` reflects the current Labor Code, Art. 112. Movable days off (the extra Quốc khánh day on 1/9 or 3/9, and the 5 Tết days chosen each year by the government) are not included.
|
|
126
|
+
|
|
127
|
+
# 📚 API
|
|
128
|
+
|
|
129
|
+
All functions are exported from the package root:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import {
|
|
133
|
+
dayInfo, lunarDay, // high-level, string input
|
|
134
|
+
getLunarDate, getJulianDayNumber, // low-level conversion
|
|
135
|
+
getHeavenlyEarthly, getDayStemIndex, getDayBranchIndex, getMonthBranchIndex,
|
|
136
|
+
getSolarTermIndex, getDayStarInfo,
|
|
137
|
+
HEAVENLY_STEMS, EARTHLY_BRANCHES, SOLAR_TERMS, // name tables
|
|
138
|
+
} from "vietnamese-lunar";
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### High-level
|
|
142
|
+
|
|
143
|
+
| Function | Returns | |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `dayInfo(date: string)` | `DayInfo \| string` | Full info of a day (see example above). |
|
|
146
|
+
| `lunarDay(date: string)` | `LunarDayInfo \| string` | Lunar date + ganzhi only (lighter). |
|
|
147
|
+
|
|
148
|
+
- `date` format: `D/M/YYYY` (e.g. `"7/1/2025"` or `"07/01/2025"`), year **1800–2199**.
|
|
149
|
+
- Invalid input (wrong format, `31/2`, out of range, extra spaces…) returns the string `"Invalid date input."` — check it before using:
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
const info = dayInfo("2/9/2020");
|
|
153
|
+
if (typeof info === "string") throw new Error(info);
|
|
154
|
+
|
|
155
|
+
info.holidays;
|
|
156
|
+
// [
|
|
157
|
+
// { name: "Ngày Quốc khánh", isPublicHoliday: true, calendar: "solar" },
|
|
158
|
+
// { name: "Lễ Vu Lan", isPublicHoliday: false, calendar: "lunar" },
|
|
159
|
+
// ]
|
|
160
|
+
info.dayStar.isAuspicious; // Hoàng Đạo?
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Low-level
|
|
164
|
+
|
|
165
|
+
Use these when you already have day/month/year as numbers (no string parsing, no validation — you must keep the year in 1800–2199).
|
|
166
|
+
|
|
167
|
+
**`getLunarDate(day, month, year): LunarDate`** — solar → lunar.
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
const lunar = getLunarDate(17, 10, 2025);
|
|
171
|
+
// { date: 26, month: 8, year: 2025, isLeap: false, julianDay: 2460966 }
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`year` is the **lunar** year (may differ from the solar year in Jan/Feb). `julianDay` can be passed to the index helpers below.
|
|
175
|
+
|
|
176
|
+
**`getJulianDayNumber(day, month, year): number`** — Julian Day Number of a solar date.
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
const jd = getJulianDayNumber(17, 10, 2025); // 2460966
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**`getHeavenlyEarthly(lunar: LunarDate): {date, month, year}`** — Can Chi names.
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
getHeavenlyEarthly(lunar); // { date: "Kỷ Mùi", month: "Ất Dậu", year: "Ất Tỵ" }
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Index helpers** (input: Julian Day Number, output: array index):
|
|
189
|
+
|
|
190
|
+
| Function | Lookup table | Example `jd = 2460966` (17/10/2025) |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| `getDayStemIndex(jd)` | `HEAVENLY_STEMS` | `HEAVENLY_STEMS[5]` → `"Kỷ"` |
|
|
193
|
+
| `getDayBranchIndex(jd)` | `EARTHLY_BRANCHES` | `EARTHLY_BRANCHES[7]` → `"Mùi"` |
|
|
194
|
+
| `getMonthBranchIndex(jd)` | `EARTHLY_BRANCHES` | `"Tuất"` — Nguyệt Kiến by **solar term** |
|
|
195
|
+
| `getSolarTermIndex(jd)` | `SOLAR_TERMS` | `"Hàn Lộ"` |
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
EARTHLY_BRANCHES[getMonthBranchIndex(jd)]; // "Tuất"
|
|
199
|
+
SOLAR_TERMS[getSolarTermIndex(jd)]; // "Hàn Lộ"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
> `getMonthBranchIndex` (solar-term month, changes at Lập Xuân, Kinh Trập…) is **not** the same as `lunarDateText.month` (lunar month, changes on mùng 1). E.g. 17/10/2025 is lunar month Ất **Dậu** but Nguyệt Kiến **Tuất**.
|
|
203
|
+
|
|
204
|
+
**`getDayStarInfo(lunar: LunarDate): DayStarInfo`** — 12-star Hoàng Đạo / Hắc Đạo.
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
getDayStarInfo(getLunarDate(17, 10, 2025)); // { star: "Chu Tước", isAuspicious: false }
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Hoàng Đạo stars: Thanh Long, Minh Đường, Kim Quỹ, Thiên Đức, Ngọc Đường, Tư Mệnh. Hắc Đạo: Thiên Hình, Chu Tước, Bạch Hổ, Thiên Lao, Huyền Vũ, Câu Trận.
|
|
211
|
+
|
|
212
|
+
### Types (TypeScript)
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import type { DayInfo, LunarDayInfo, LunarDate, DayStarInfo, Holiday, dateFormat } from "vietnamese-lunar";
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
| Type | Shape |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `LunarDate` | `{ date, month, year, isLeap, julianDay }` |
|
|
221
|
+
| `dateFormat` | `{ date, month, year }` — ganzhi names |
|
|
222
|
+
| `DayStarInfo` | `{ star, isAuspicious }` |
|
|
223
|
+
| `Holiday` | `{ name, calendar: "solar" \| "lunar", isPublicHoliday }` |
|
|
224
|
+
| `DayInfo` | return type of `dayInfo` |
|
|
225
|
+
| `LunarDayInfo` | return type of `lunarDay` |
|
|
226
|
+
|
|
227
|
+
# Changelog
|
|
228
|
+
|
|
229
|
+
See [CHANGELOG.md](https://gitlab.com/tandd.packages/vietnamese-lunar-calendar/-/blob/main/CHANGELOG.md). **Upgrading from v1?** `holiday` was renamed to `holidays` (array) — see the 2.0.0 notes.
|
|
109
230
|
|
|
110
231
|
# Thanks
|
|
111
232
|
|