vietnamese-lunar 2.0.0 → 2.1.1-rc.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 +73 -0
- package/lib/cjs/auspiciousHours.d.ts +7 -0
- package/lib/cjs/auspiciousHours.js +57 -0
- package/lib/cjs/compat.d.ts +9 -0
- package/lib/cjs/compat.js +36 -0
- package/lib/{constants.d.ts → cjs/constants.d.ts} +1 -2
- package/lib/{constants.js → cjs/constants.js} +4 -6
- package/lib/cjs/dayStar.d.ts +14 -0
- package/lib/cjs/dayStar.js +64 -0
- package/lib/{heavenly_earthly.d.ts → cjs/heavenly_earthly.d.ts} +3 -1
- package/lib/cjs/heavenly_earthly.js +57 -0
- package/lib/cjs/holidays.d.ts +11 -0
- package/lib/cjs/holidays.js +165 -0
- package/lib/cjs/index.d.ts +9 -0
- package/lib/cjs/index.js +34 -0
- package/lib/cjs/input.d.ts +7 -0
- package/lib/cjs/input.js +60 -0
- package/lib/cjs/lunar.d.ts +15 -0
- package/lib/cjs/lunar.js +126 -0
- package/lib/cjs/lunarConverter.d.ts +9 -0
- package/lib/cjs/lunarConverter.js +101 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/solarTerms.d.ts +12 -0
- package/lib/cjs/solarTerms.js +103 -0
- package/lib/cjs/type.d.ts +167 -0
- package/lib/{utils.d.ts → cjs/utils.d.ts} +6 -0
- package/lib/{utils.js → cjs/utils.js} +18 -2
- package/lib/esm/auspiciousHours.d.ts +7 -0
- package/lib/esm/auspiciousHours.js +50 -0
- package/lib/esm/compat.d.ts +9 -0
- package/lib/esm/compat.js +31 -0
- package/lib/esm/constants.d.ts +14 -0
- package/lib/esm/constants.js +117 -0
- package/lib/esm/dayStar.d.ts +14 -0
- package/lib/esm/dayStar.js +58 -0
- package/lib/esm/heavenly_earthly.d.ts +8 -0
- package/lib/esm/heavenly_earthly.js +48 -0
- package/lib/esm/holidays.d.ts +11 -0
- package/lib/esm/holidays.js +159 -0
- package/lib/esm/index.d.ts +9 -0
- package/lib/esm/index.js +8 -0
- package/lib/esm/input.d.ts +7 -0
- package/lib/esm/input.js +55 -0
- package/lib/esm/lunar.d.ts +15 -0
- package/lib/esm/lunar.js +118 -0
- package/lib/esm/lunarConverter.d.ts +9 -0
- package/lib/esm/lunarConverter.js +94 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/solarTerms.d.ts +12 -0
- package/lib/esm/solarTerms.js +97 -0
- package/lib/esm/type.d.ts +167 -0
- package/lib/esm/type.js +1 -0
- package/lib/esm/utils.d.ts +10 -0
- package/lib/esm/utils.js +51 -0
- package/package.json +22 -8
- package/readme.md +455 -53
- package/lib/auspiciousHours.d.ts +0 -2
- package/lib/auspiciousHours.js +0 -39
- package/lib/dayStar.d.ts +0 -2
- package/lib/dayStar.js +0 -24
- package/lib/heavenly_earthly.js +0 -41
- package/lib/holidays.d.ts +0 -2
- package/lib/holidays.js +0 -64
- package/lib/index.d.ts +0 -7
- package/lib/index.js +0 -22
- package/lib/lunar.d.ts +0 -3
- package/lib/lunar.js +0 -111
- package/lib/lunarConverter.d.ts +0 -3
- package/lib/lunarConverter.js +0 -67
- package/lib/type.d.ts +0 -45
- /package/lib/{type.js → cjs/type.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,79 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
+
## 2.1.1 — Unreleased
|
|
6
|
+
|
|
7
|
+
### ⚠️ Behaviour changes (relative to 2.1.0)
|
|
8
|
+
|
|
9
|
+
Checked by running 2.1.0 and this version side by side on 20,863 dates (every 7th day, 1800–2199): the only differing `dayInfo` / `lunarDay` values are `clash` (below) and the new fields; `getHolidays`, `monthInfo`, `getSolarTerms` (apart from the new `startLocal`) and `nextHolidays` with `{day, month, year}` are identical.
|
|
10
|
+
|
|
11
|
+
- **Invalid dates throw `RangeError`** in `dayInfo`, `lunarDay`, `getHourInfo`, `nextHolidays` and `getLunarDate(date)`, with a message naming the function and the bad value.
|
|
12
|
+
- `dayInfo` / `lunarDay`: returned the string `"Invalid date input."` (also in 2.0.x). **Code that checks `typeof result === "string"` must switch to `try/catch`.** The return types change from `DayInfo | string` / `LunarDayInfo | string` to `DayInfo` / `LunarDayInfo`.
|
|
13
|
+
- `getHourInfo`: returned `null` for a bad date; still returns `null` for an `hour` that is not an integer 0..23.
|
|
14
|
+
- `nextHolidays`: see Fixed.
|
|
15
|
+
- Unchanged and still non-throwing: `getLunarDate(day, month, year)` (zeroed `LunarDate` outside 1800–2199), `getSolarDate`, `getLunarMonthDays`, `getLeapMonth` (`null` / `0`), `monthInfo` (`null`).
|
|
16
|
+
- **`clash.canChi` uses a new rule**: tuổi xung = Can Chi with the opposite Chi whose Nạp âm element *khắc* the day's Nạp âm element (either direction). Always exactly 2 items, sorted by Can. `clash.chi` is unchanged.
|
|
17
|
+
|
|
18
|
+
| Day | 2.1.0 | 2.1.1 |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| Quý Dậu (26/10/2026) | `["Đinh Mão"]` | `["Đinh Mão", "Tân Mão"]` |
|
|
21
|
+
| Kỷ Mão (1/11/2026) | `[]` | `["Ất Dậu", "Tân Dậu"]` |
|
|
22
|
+
| Kỷ Mùi (17/10/2025) | `[]` | `["Ất Sửu", "Đinh Sửu"]` |
|
|
23
|
+
|
|
24
|
+
The values changed for all 20,863 sampled days. Cross-checked against the commonly published almanac listing (e.g. Giáp Tý → Mậu Ngọ, Nhâm Ngọ).
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- `nextHolidays` returned `[]` when `from` was a `Date` or a string; only `{day, month, year}` worked. It now accepts any `DateInput` (`Date`, `{day, month, year}`, `'d/m/yyyy'`, `'dd/mm/yyyy'`) through the same normaliser as every other function.
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- `getSolarTermByIndex(year, index)`.
|
|
33
|
+
- `startLocal: {day, month, year, hour, minute}` (Vietnam time, UTC+7) on `solarTerm.current`, `solarTerm.next` and every item of `getSolarTerms()`.
|
|
34
|
+
- `nextHolidays(from, count, options)`: `groupConsecutive` (merges consecutive same-name days; adds `endDate` and `days`), `types: HolidayType[]`, `dayOffOnly`. Defaults keep the 2.1.0 behaviour (no grouping, no filtering).
|
|
35
|
+
- `getLunarDate(date: DateInput)` overload.
|
|
36
|
+
- `lunarDay()` returns `dateText` (camelCase, same value as `date_text`). **`date_text` is deprecated** but unchanged.
|
|
37
|
+
- New exported types: `LocalDateTime`, `NextHolidaysOptions`.
|
|
38
|
+
- `scripts/readme-examples.mjs`: README examples are generated by running the built code (`node scripts/readme-examples.mjs --write`).
|
|
39
|
+
|
|
40
|
+
### Documented
|
|
41
|
+
|
|
42
|
+
- `getSolarTerms(year)` is ordered by time from Tiểu Hàn; `index` is the `SOLAR_TERMS` numbering (0 = Xuân Phân), the same numbering as `dayInfo().solarTerm.*.index`. `getSolarTerms(2026)[17]` is Thu Phân, `index: 12`.
|
|
43
|
+
- `solarTerm.*.start` is an absolute instant (prints as UTC); Vietnam time is UTC+7 — use `startLocal`.
|
|
44
|
+
- `daysUntil` counts calendar days in UTC+7 and does not depend on the time of day or the machine's time zone (tested under `Asia/Ho_Chi_Minh`, `America/New_York`, `Pacific/Auckland`).
|
|
45
|
+
- README: Interface table now lists every `DayInfo` field; 2.1.0 and 2.1.1 sections separated; corrected the `monthDays` example (17/10/2025 is a 29-day month).
|
|
46
|
+
|
|
47
|
+
### Not in this release
|
|
48
|
+
|
|
49
|
+
- `monthBasis: 'solar-term' | 'lunar-month'` for `dayStar` (optional item C of the request) — deferred to 2.2.0.
|
|
50
|
+
|
|
51
|
+
## 2.1.0 — 2026-11-01
|
|
52
|
+
|
|
53
|
+
Backward compatible with 2.0.x: no existing field changed name or type; everything below is additive.
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- **Input types**: `dayInfo`, `lunarDay`, `getHourInfo` accept `'d/m/yyyy'`, a `Date` (local time) or `{day, month, year}`.
|
|
58
|
+
- **Hoàng Đạo / Hắc Đạo**: `dayStar` gains `index` (1..12), `category` (`'hoang-dao' | 'hac-dao' | null`), `system`, `aliases`. `dayInfo(date, {starSystem: 'hiep-ky' | 'ngoc-hap'})`, default `'hiep-ky'`. `isAuspicious` is kept, but `false` no longer implies hắc đạo — use `category`.
|
|
59
|
+
- `getSolarDate(day, month, lunarYear, isLeap?)` (lunar → solar, `null` when it does not exist), `getLeapMonth(lunarYear)`, `getLunarMonthDays(month, lunarYear, isLeap?)`, and `monthDays` on `getLunarDate()` / `dayInfo().lunarDate`.
|
|
60
|
+
- `dayInfo().hours` (12 structured hours with Can Chi, range, star, category) and `getHourInfo(date, hour)`.
|
|
61
|
+
- `dayInfo().solarTerm` (`current` / `next` with exact start time and `daysUntil`) and `getSolarTerms(year)`.
|
|
62
|
+
- `getHolidays(year)`, `nextHolidays(from, count)`; holidays gain `type` and `isDayOff`.
|
|
63
|
+
- `dayInfo().clash` / `compatible` (tuổi xung, tam hợp, lục hợp).
|
|
64
|
+
- `dayInfo().napAm` and `element`. `dayMaster` is **deprecated** (it always returned Nạp âm); it keeps its value.
|
|
65
|
+
- `dayInfo().canChi` (numeric Can/Chi indexes of day, month, year, first hour) and `getCanChi(lunar)`.
|
|
66
|
+
- `monthInfo(year, month)` — all days of a solar month in one call. Internal caching of decoded lunar years and solar-term times.
|
|
67
|
+
- Dual package: ESM (`lib/esm`) + CJS (`lib/cjs`) with `exports` map and full `.d.ts`.
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
|
|
71
|
+
- `moment` is no longer a dependency (date parsing is built in; same accepted formats).
|
|
72
|
+
- Build output moved from `lib/*.js` to `lib/cjs` and `lib/esm`. `require('vietnamese-lunar')` / `import` keep working; deep imports of `vietnamese-lunar/lib/...` do not.
|
|
73
|
+
|
|
74
|
+
### Not included (item 10 of the request)
|
|
75
|
+
|
|
76
|
+
12 Trực, 28 Sao, ngày kỵ and a composite `rating` are not implemented: they need a chosen authoritative source and weights; see README.
|
|
77
|
+
|
|
5
78
|
## 2.0.0 — 2026-10-26
|
|
6
79
|
|
|
7
80
|
### ⚠️ Breaking changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HourInfo, StarSystem } from "./type.js";
|
|
2
|
+
export declare const getAuspiciousHours: (julianDay: number) => string;
|
|
3
|
+
export declare const getInauspiciousHours: (julianDay: number) => string;
|
|
4
|
+
/** 12 giờ của ngày (Tý → Hợi) kèm thần trực giờ và phân loại theo `system`. */
|
|
5
|
+
export declare const getHours: (julianDay: number, system?: StarSystem) => HourInfo[];
|
|
6
|
+
/** Giờ dương lịch 0..23 → chỉ số giờ Chi (23 và 0 đều là giờ Tý). */
|
|
7
|
+
export declare const hourToBranchIndex: (hour: number) => number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hourToBranchIndex = exports.getHours = exports.getInauspiciousHours = exports.getAuspiciousHours = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
const heavenly_earthly_js_1 = require("./heavenly_earthly.js");
|
|
6
|
+
const dayStar_js_1 = require("./dayStar.js");
|
|
7
|
+
const getHourStemIndex = (julianDay, hour) => {
|
|
8
|
+
const firstHourStemIndex = (julianDay - 1) * 2 % 10;
|
|
9
|
+
return (firstHourStemIndex + hour) % 10;
|
|
10
|
+
};
|
|
11
|
+
const hourText = (julianDay, hour) => {
|
|
12
|
+
const start = (hour * 2 + 23) % 24;
|
|
13
|
+
const end = (hour * 2 + 1) % 24;
|
|
14
|
+
return `${constants_js_1.HEAVENLY_STEMS[getHourStemIndex(julianDay, hour)]} ${constants_js_1.EARTHLY_BRANCHES[hour]} (${start}-${end})`;
|
|
15
|
+
};
|
|
16
|
+
const getAuspiciousHours = (julianDay) => {
|
|
17
|
+
const pattern = constants_js_1.AUSPICIOUS_HOURS[(0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) % 6];
|
|
18
|
+
const list = [];
|
|
19
|
+
for (let hour = 0; hour < 12; hour++) {
|
|
20
|
+
if (pattern.charAt(hour) === '1')
|
|
21
|
+
list.push(hourText(julianDay, hour));
|
|
22
|
+
}
|
|
23
|
+
return list.join(', ');
|
|
24
|
+
};
|
|
25
|
+
exports.getAuspiciousHours = getAuspiciousHours;
|
|
26
|
+
const getInauspiciousHours = (julianDay) => {
|
|
27
|
+
const pattern = constants_js_1.AUSPICIOUS_HOURS[(0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) % 6];
|
|
28
|
+
if (!pattern || pattern.length < 12)
|
|
29
|
+
return '';
|
|
30
|
+
const list = [];
|
|
31
|
+
for (let hour = 0; hour < 12; hour++) {
|
|
32
|
+
if (pattern.charAt(hour) !== '1')
|
|
33
|
+
list.push(hourText(julianDay, hour));
|
|
34
|
+
}
|
|
35
|
+
return list.join(', ');
|
|
36
|
+
};
|
|
37
|
+
exports.getInauspiciousHours = getInauspiciousHours;
|
|
38
|
+
/** 12 giờ của ngày (Tý → Hợi) kèm thần trực giờ và phân loại theo `system`. */
|
|
39
|
+
const getHours = (julianDay, system = 'hiep-ky') => {
|
|
40
|
+
const hours = [];
|
|
41
|
+
for (let hour = 0; hour < 12; hour++) {
|
|
42
|
+
const position = (0, dayStar_js_1.getHourStarPosition)(julianDay, hour);
|
|
43
|
+
hours.push({
|
|
44
|
+
chi: constants_js_1.EARTHLY_BRANCHES[hour],
|
|
45
|
+
canChi: `${constants_js_1.HEAVENLY_STEMS[getHourStemIndex(julianDay, hour)]} ${constants_js_1.EARTHLY_BRANCHES[hour]}`,
|
|
46
|
+
start: (hour * 2 + 23) % 24,
|
|
47
|
+
end: (hour * 2 + 1) % 24,
|
|
48
|
+
star: dayStar_js_1.STAR_DEFINITIONS[position].name,
|
|
49
|
+
category: (0, dayStar_js_1.getStarCategory)(position, system),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return hours;
|
|
53
|
+
};
|
|
54
|
+
exports.getHours = getHours;
|
|
55
|
+
/** Giờ dương lịch 0..23 → chỉ số giờ Chi (23 và 0 đều là giờ Tý). */
|
|
56
|
+
const hourToBranchIndex = (hour) => Math.floor(((hour + 1) % 24) / 2);
|
|
57
|
+
exports.hourToBranchIndex = hourToBranchIndex;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Element } from "./type.js";
|
|
2
|
+
export declare const getClash: (dayElement: Element | null, dayChi: number) => {
|
|
3
|
+
canChi: string[];
|
|
4
|
+
chi: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare const getCompatible: (dayChi: number) => {
|
|
7
|
+
tamHop: string[];
|
|
8
|
+
lucHop: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCompatible = exports.getClash = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
// Quy tắc tuổi xung (khớp cách liệt kê của lịch vạn niên phổ biến):
|
|
6
|
+
// tuổi xung với ngày = tuổi có Chi ĐỐI (lục xung, cách 6) với Chi của ngày
|
|
7
|
+
// VÀ hành Nạp âm của tuổi tương khắc với hành Nạp âm của ngày (khắc một trong hai chiều).
|
|
8
|
+
// Ví dụ: ngày Giáp Tý (Hải Trung Kim) xung Mậu Ngọ (Hỏa khắc Kim) và Nhâm Ngọ (Kim khắc Mộc);
|
|
9
|
+
// ngày Kỷ Mão (Thành Đầu Thổ) xung Tân Dậu (Mộc khắc Thổ) và Ất Dậu (Thổ khắc Thủy).
|
|
10
|
+
// 5 tuổi cùng một Chi mang đủ 5 hành, nên mỗi ngày luôn có đúng 2 tuổi xung.
|
|
11
|
+
// Tam hợp: Thân-Tý-Thìn, Hợi-Mão-Mùi, Dần-Ngọ-Tuất, Tỵ-Dậu-Sửu (Chi cách nhau 4).
|
|
12
|
+
// Lục hợp: Tý-Sửu, Dần-Hợi, Mão-Tuất, Thìn-Dậu, Tỵ-Thân, Ngọ-Mùi (tổng chỉ số ≡ 1 mod 12).
|
|
13
|
+
const KHAC = { 'Kim': 'Mộc', 'Mộc': 'Thổ', 'Thổ': 'Thủy', 'Thủy': 'Hỏa', 'Hỏa': 'Kim' };
|
|
14
|
+
const elementOf = (canChiText) => {
|
|
15
|
+
const napAm = constants_js_1.HEAVENLY_EARTHLY_ELEMENT_MAP[canChiText];
|
|
16
|
+
return napAm ? napAm.split(' ').pop() : null;
|
|
17
|
+
};
|
|
18
|
+
const getClash = (dayElement, dayChi) => {
|
|
19
|
+
const oppositeChi = (dayChi + 6) % 12;
|
|
20
|
+
const canChi = [];
|
|
21
|
+
if (dayElement) {
|
|
22
|
+
for (let can = oppositeChi % 2; can < 10; can += 2) { // Can và Chi cùng chẵn/lẻ mới có trong 60 Hoa Giáp
|
|
23
|
+
const text = `${constants_js_1.HEAVENLY_STEMS[can]} ${constants_js_1.EARTHLY_BRANCHES[oppositeChi]}`;
|
|
24
|
+
const el = elementOf(text);
|
|
25
|
+
if (el && (KHAC[el] === dayElement || KHAC[dayElement] === el))
|
|
26
|
+
canChi.push(text);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { canChi, chi: [constants_js_1.EARTHLY_BRANCHES[oppositeChi]] };
|
|
30
|
+
};
|
|
31
|
+
exports.getClash = getClash;
|
|
32
|
+
const getCompatible = (dayChi) => ({
|
|
33
|
+
tamHop: [constants_js_1.EARTHLY_BRANCHES[(dayChi + 4) % 12], constants_js_1.EARTHLY_BRANCHES[(dayChi + 8) % 12]],
|
|
34
|
+
lucHop: constants_js_1.EARTHLY_BRANCHES[(13 - dayChi) % 12],
|
|
35
|
+
});
|
|
36
|
+
exports.getCompatible = getCompatible;
|
|
@@ -10,6 +10,5 @@ declare const LEAP_TEXT = " (nhu\u1EADn)";
|
|
|
10
10
|
declare const DAY_OF_WEEK: string[];
|
|
11
11
|
declare const FIRST_DAY: number;
|
|
12
12
|
declare const LAST_DAY: number;
|
|
13
|
-
declare const DATE_FORMAT: string[];
|
|
14
13
|
declare const PI: number;
|
|
15
|
-
export { LIST_YEARS, FIRST_DAY, LAST_DAY, PI, HEAVENLY_STEMS, EARTHLY_BRANCHES, AUSPICIOUS_HOURS, SOLAR_TERMS, DAY_OF_WEEK, LEAP_TEXT,
|
|
14
|
+
export { LIST_YEARS, FIRST_DAY, LAST_DAY, PI, HEAVENLY_STEMS, EARTHLY_BRANCHES, AUSPICIOUS_HOURS, SOLAR_TERMS, DAY_OF_WEEK, LEAP_TEXT, HEAVENLY_EARTHLY_ELEMENT_MAP, DAY_STARS, AUSPICIOUS_DAY_STARS };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUSPICIOUS_DAY_STARS = exports.DAY_STARS = exports.HEAVENLY_EARTHLY_ELEMENT_MAP = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.AUSPICIOUS_DAY_STARS = exports.DAY_STARS = exports.HEAVENLY_EARTHLY_ELEMENT_MAP = 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_js_1 = require("./utils.js");
|
|
5
5
|
const LIST_YEARS = [
|
|
6
6
|
0x30baa3, 0x56ab50, 0x422ba0, 0x2cab61, 0x52a370, 0x3c51e8, 0x60d160, 0x4ae4b0, 0x376926, 0x58daa0,
|
|
7
7
|
0x445b50, 0x3116d2, 0x562ae0, 0x3ea2e0, 0x28e2d2, 0x4ec950, 0x38d556, 0x5cb520, 0x46b690, 0x325da4,
|
|
@@ -124,11 +124,9 @@ const LEAP_TEXT = ' (nhuận)';
|
|
|
124
124
|
exports.LEAP_TEXT = LEAP_TEXT;
|
|
125
125
|
const DAY_OF_WEEK = ['Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy'];
|
|
126
126
|
exports.DAY_OF_WEEK = DAY_OF_WEEK;
|
|
127
|
-
const FIRST_DAY = (0,
|
|
127
|
+
const FIRST_DAY = (0, utils_js_1.getJulianDayNumber)(25, 1, 1800);
|
|
128
128
|
exports.FIRST_DAY = FIRST_DAY;
|
|
129
|
-
const LAST_DAY = (0,
|
|
129
|
+
const LAST_DAY = (0, utils_js_1.getJulianDayNumber)(31, 12, 2199);
|
|
130
130
|
exports.LAST_DAY = LAST_DAY;
|
|
131
|
-
const DATE_FORMAT = ["D/M/YYYY", "DD/M/YYYY", "D/MM/YYYY", "DD/MM/YYYY"];
|
|
132
|
-
exports.DATE_FORMAT = DATE_FORMAT;
|
|
133
131
|
const PI = Math.PI;
|
|
134
132
|
exports.PI = PI;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DayStarInfo, LunarDate, StarCategory, StarSystem } from "./type.js";
|
|
2
|
+
type StarDefinition = {
|
|
3
|
+
name: string;
|
|
4
|
+
aliases: string[];
|
|
5
|
+
/** Hiệp Kỷ Biện Phương Thư: 6 hoàng đạo / 6 hắc đạo. */
|
|
6
|
+
hiepKy: StarCategory;
|
|
7
|
+
/** Ngọc Hạp Thông Thư: 4 hoàng đạo / 4 hắc đạo, 4 thần còn lại không thuộc nhóm nào. */
|
|
8
|
+
ngocHap: StarCategory;
|
|
9
|
+
};
|
|
10
|
+
export declare const STAR_DEFINITIONS: StarDefinition[];
|
|
11
|
+
export declare const getStarCategory: (starIndex: number, system: StarSystem) => StarCategory;
|
|
12
|
+
export declare const getHourStarPosition: (julianDay: number, hourBranch: number) => number;
|
|
13
|
+
export declare const getDayStarInfo: (lunarDate: LunarDate, system?: StarSystem) => DayStarInfo;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDayStarInfo = exports.getHourStarPosition = exports.getStarCategory = exports.STAR_DEFINITIONS = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
const heavenly_earthly_js_1 = require("./heavenly_earthly.js");
|
|
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
|
+
// Vị trí giờ của Thanh Long theo Chi ngày (Tý/Ngọ → giờ Thân, Sửu/Mùi → Tuất, Dần/Thân → Tý, ...).
|
|
13
|
+
// Index = Chi ngày % 6. Khớp với bảng AUSPICIOUS_HOURS.
|
|
14
|
+
const THANH_LONG_HOUR_BY_DAY_ZHI = [8, 10, 0, 2, 4, 6];
|
|
15
|
+
// Thứ tự cố định của 12 thần, bắt đầu từ Thanh Long (index 1..12 = vị trí + 1).
|
|
16
|
+
exports.STAR_DEFINITIONS = [
|
|
17
|
+
{ name: constants_js_1.DAY_STARS[0], aliases: [], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
|
|
18
|
+
{ name: constants_js_1.DAY_STARS[1], aliases: [], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
|
|
19
|
+
{ name: constants_js_1.DAY_STARS[2], aliases: [], hiepKy: 'hac-dao', ngocHap: null },
|
|
20
|
+
{ name: constants_js_1.DAY_STARS[3], aliases: [], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
|
|
21
|
+
{ name: constants_js_1.DAY_STARS[4], aliases: [], hiepKy: 'hoang-dao', ngocHap: null },
|
|
22
|
+
{ name: constants_js_1.DAY_STARS[5], aliases: ['Bảo Quang', 'Kim Đường'], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
|
|
23
|
+
{ name: constants_js_1.DAY_STARS[6], aliases: [], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
|
|
24
|
+
{ name: constants_js_1.DAY_STARS[7], aliases: [], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
|
|
25
|
+
{ name: constants_js_1.DAY_STARS[8], aliases: [], hiepKy: 'hac-dao', ngocHap: null },
|
|
26
|
+
{ name: constants_js_1.DAY_STARS[9], aliases: ['Nguyên Vũ'], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
|
|
27
|
+
{ name: constants_js_1.DAY_STARS[10], aliases: [], hiepKy: 'hoang-dao', ngocHap: null },
|
|
28
|
+
{ name: constants_js_1.DAY_STARS[11], aliases: ['Câu Trần'], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
|
|
29
|
+
];
|
|
30
|
+
const getStarCategory = (starIndex, system) => {
|
|
31
|
+
const def = exports.STAR_DEFINITIONS[starIndex];
|
|
32
|
+
if (!def)
|
|
33
|
+
return null;
|
|
34
|
+
return system === 'ngoc-hap' ? def.ngocHap : def.hiepKy;
|
|
35
|
+
};
|
|
36
|
+
exports.getStarCategory = getStarCategory;
|
|
37
|
+
// Vị trí (0..11) của thần trực ngày.
|
|
38
|
+
const getDayStarPosition = (julianDay) => {
|
|
39
|
+
const thanhLongChiIndex = THANH_LONG_OFFSET_BY_MONTH_ZHI[(0, heavenly_earthly_js_1.getMonthBranchIndex)(julianDay)];
|
|
40
|
+
return ((0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) - thanhLongChiIndex + 12) % 12;
|
|
41
|
+
};
|
|
42
|
+
// Vị trí (0..11) của thần trực giờ `hourBranch` (0 = Tý ... 11 = Hợi) của ngày.
|
|
43
|
+
const getHourStarPosition = (julianDay, hourBranch) => {
|
|
44
|
+
const start = THANH_LONG_HOUR_BY_DAY_ZHI[(0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) % 6];
|
|
45
|
+
return (hourBranch - start + 12) % 12;
|
|
46
|
+
};
|
|
47
|
+
exports.getHourStarPosition = getHourStarPosition;
|
|
48
|
+
const getDayStarInfo = (lunarDate, system = 'hiep-ky') => {
|
|
49
|
+
if (lunarDate.date === 0) {
|
|
50
|
+
return { star: '', isAuspicious: false, index: 0, category: null, system, aliases: [] };
|
|
51
|
+
}
|
|
52
|
+
const position = getDayStarPosition(lunarDate.julianDay);
|
|
53
|
+
const def = exports.STAR_DEFINITIONS[position];
|
|
54
|
+
const category = (0, exports.getStarCategory)(position, system);
|
|
55
|
+
return {
|
|
56
|
+
star: def.name,
|
|
57
|
+
isAuspicious: category === 'hoang-dao',
|
|
58
|
+
index: position + 1,
|
|
59
|
+
category,
|
|
60
|
+
system,
|
|
61
|
+
aliases: def.aliases.slice(),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.getDayStarInfo = getDayStarInfo;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { dateFormat, LunarDate } from "./type";
|
|
1
|
+
import { CanChiInfo, dateFormat, LunarDate } from "./type.js";
|
|
2
2
|
export declare const getDayStemIndex: (julianDay: number) => number;
|
|
3
3
|
export declare const getDayBranchIndex: (julianDay: number) => number;
|
|
4
4
|
export declare const getMonthBranchIndex: (julianDay: number) => number;
|
|
5
5
|
export declare const getHeavenlyEarthly: (lunarDate: LunarDate) => dateFormat;
|
|
6
6
|
export declare const getFirstHeavenlyHour: (julianDay: number) => string;
|
|
7
|
+
/** Chỉ số Can (0..9) / Chi (0..11) + chuỗi của ngày, tháng (âm lịch), năm (âm lịch) và giờ Tý đầu ngày. */
|
|
8
|
+
export declare const getCanChi: (lunarDate: LunarDate) => CanChiInfo;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCanChi = exports.getFirstHeavenlyHour = exports.getHeavenlyEarthly = exports.getMonthBranchIndex = exports.getDayBranchIndex = exports.getDayStemIndex = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
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_js_1.getSolarTermIndex)(julianDay);
|
|
15
|
+
return (Math.floor(((termIndex - LAP_XUAN_TERM_INDEX + 24) % 24) / 2) + 2) % 12;
|
|
16
|
+
};
|
|
17
|
+
exports.getMonthBranchIndex = getMonthBranchIndex;
|
|
18
|
+
const getYearHeavenlyEarthly = (year) => {
|
|
19
|
+
return constants_js_1.HEAVENLY_STEMS[(year + 6) % 10] + " " + constants_js_1.EARTHLY_BRANCHES[(year + 8) % 12];
|
|
20
|
+
};
|
|
21
|
+
const getHeavenlyEarthly = (lunarDate) => {
|
|
22
|
+
const { julianDay, month, year, isLeap } = lunarDate;
|
|
23
|
+
const dayHeavenlyEarthly = `${constants_js_1.HEAVENLY_STEMS[(0, exports.getDayStemIndex)(julianDay)]} ${constants_js_1.EARTHLY_BRANCHES[(0, exports.getDayBranchIndex)(julianDay)]}`;
|
|
24
|
+
const monthStemIndex = (year * 12 + month + 3) % 10;
|
|
25
|
+
const monthBranchIndex = (month + 1) % 12;
|
|
26
|
+
let monthHeavenlyEarthly = `${constants_js_1.HEAVENLY_STEMS[monthStemIndex]} ${constants_js_1.EARTHLY_BRANCHES[monthBranchIndex]}`;
|
|
27
|
+
if (isLeap) {
|
|
28
|
+
monthHeavenlyEarthly += constants_js_1.LEAP_TEXT;
|
|
29
|
+
}
|
|
30
|
+
const yearHeavenlyEarthly = getYearHeavenlyEarthly(year);
|
|
31
|
+
return {
|
|
32
|
+
date: dayHeavenlyEarthly,
|
|
33
|
+
month: monthHeavenlyEarthly,
|
|
34
|
+
year: yearHeavenlyEarthly
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.getHeavenlyEarthly = getHeavenlyEarthly;
|
|
38
|
+
const getFirstHeavenlyHour = (julianDay) => {
|
|
39
|
+
return constants_js_1.HEAVENLY_STEMS[(julianDay - 1) * 2 % 10];
|
|
40
|
+
};
|
|
41
|
+
exports.getFirstHeavenlyHour = getFirstHeavenlyHour;
|
|
42
|
+
const canChiPart = (can, chi, text) => ({ can, chi, text });
|
|
43
|
+
/** Chỉ số Can (0..9) / Chi (0..11) + chuỗi của ngày, tháng (âm lịch), năm (âm lịch) và giờ Tý đầu ngày. */
|
|
44
|
+
const getCanChi = (lunarDate) => {
|
|
45
|
+
const { julianDay, month, year, date } = lunarDate;
|
|
46
|
+
const names = (0, exports.getHeavenlyEarthly)(lunarDate);
|
|
47
|
+
const dayCan = (0, exports.getDayStemIndex)(julianDay);
|
|
48
|
+
const hourCan = ((julianDay - 1) * 2) % 10;
|
|
49
|
+
const hasLunar = date !== 0;
|
|
50
|
+
return {
|
|
51
|
+
day: canChiPart(dayCan, (0, exports.getDayBranchIndex)(julianDay), `${constants_js_1.HEAVENLY_STEMS[dayCan]} ${constants_js_1.EARTHLY_BRANCHES[(0, exports.getDayBranchIndex)(julianDay)]}`),
|
|
52
|
+
month: hasLunar ? canChiPart((year * 12 + month + 3) % 10, (month + 1) % 12, String(names.month)) : canChiPart(-1, -1, ''),
|
|
53
|
+
year: hasLunar ? canChiPart((year + 6) % 10, (year + 8) % 12, String(names.year)) : canChiPart(-1, -1, ''),
|
|
54
|
+
hour: canChiPart(hourCan, 0, `${constants_js_1.HEAVENLY_STEMS[hourCan]} ${constants_js_1.EARTHLY_BRANCHES[0]}`),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.getCanChi = getCanChi;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DateInput, Holiday, HolidayEvent, LunarDate, NextHolidaysOptions } from "./type.js";
|
|
2
|
+
export declare const getVietnameseHolidays: (solarDay: number, solarMonth: number, solarYear: number, lunarDate: LunarDate, nextLunarDate: LunarDate) => Holiday[];
|
|
3
|
+
/** Mọi ngày lễ rơi vào năm dương `year`, sắp theo ngày tăng dần (lễ dương trước lễ âm nếu trùng ngày). Rỗng nếu ngoài 1800–2199. */
|
|
4
|
+
export declare const getHolidays: (year: number) => HolidayEvent[];
|
|
5
|
+
/**
|
|
6
|
+
* `count` ngày lễ tiếp theo kể từ `from` (tính cả chính ngày `from`), theo ngày tăng dần.
|
|
7
|
+
* `from` là `DateInput`; throw `RangeError` nếu không hợp lệ. `count` đếm theo phần tử SAU khi lọc và gộp.
|
|
8
|
+
* Với `groupConsecutive`, một chuỗi ngày nghỉ đang diễn ra tại `from` được trả với `date` = ngày đầu thực của chuỗi
|
|
9
|
+
* nếu ngày đó nằm trong cùng năm dương, nên có thể sớm hơn `from`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const nextHolidays: (from: DateInput, count: number, options?: NextHolidaysOptions) => HolidayEvent[];
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextHolidays = exports.getHolidays = exports.getVietnameseHolidays = void 0;
|
|
4
|
+
const input_js_1 = require("./input.js");
|
|
5
|
+
const lunar_js_1 = require("./lunar.js");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
const typeOf = (def, calendar) => { var _a; return def.isPublicHoliday ? 'public' : (_a = def.type) !== null && _a !== void 0 ? _a : (calendar === 'lunar' ? 'traditional' : 'commemorative'); };
|
|
8
|
+
const toHoliday = (def, calendar) => ({
|
|
9
|
+
name: def.name,
|
|
10
|
+
calendar,
|
|
11
|
+
isPublicHoliday: def.isPublicHoliday,
|
|
12
|
+
type: typeOf(def, calendar),
|
|
13
|
+
isDayOff: def.isPublicHoliday,
|
|
14
|
+
});
|
|
15
|
+
const GIAO_THUA = { name: "Giao thừa", isPublicHoliday: false };
|
|
16
|
+
// 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).
|
|
17
|
+
// 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 đó.
|
|
18
|
+
const SOLAR_HOLIDAYS = {
|
|
19
|
+
"1-1": { name: "Tết Dương lịch", isPublicHoliday: true },
|
|
20
|
+
"3-2": { name: "Ngày thành lập Đảng Cộng sản Việt Nam", isPublicHoliday: false, since: 1930 },
|
|
21
|
+
"27-2": { name: "Ngày Thầy thuốc Việt Nam", isPublicHoliday: false, since: 1955 },
|
|
22
|
+
"8-3": { name: "Ngày Quốc tế Phụ nữ", isPublicHoliday: false, since: 1910 },
|
|
23
|
+
"26-3": { name: "Ngày thành lập Đoàn TNCS Hồ Chí Minh", isPublicHoliday: false, since: 1931 },
|
|
24
|
+
"30-4": { name: "Ngày Giải phóng miền Nam, thống nhất đất nước", isPublicHoliday: true, since: 1975 },
|
|
25
|
+
"1-5": { name: "Ngày Quốc tế Lao động", isPublicHoliday: true, since: 1890 },
|
|
26
|
+
"7-5": { name: "Ngày Chiến thắng Điện Biên Phủ", isPublicHoliday: false, since: 1954 },
|
|
27
|
+
"19-5": { name: "Ngày sinh Chủ tịch Hồ Chí Minh", isPublicHoliday: false, since: 1890 },
|
|
28
|
+
"1-6": { name: "Ngày Quốc tế Thiếu nhi", isPublicHoliday: false, since: 1950 },
|
|
29
|
+
"28-6": { name: "Ngày Gia đình Việt Nam", isPublicHoliday: false, since: 2001 },
|
|
30
|
+
"27-7": { name: "Ngày Thương binh Liệt sĩ", isPublicHoliday: false, since: 1947 },
|
|
31
|
+
"19-8": { name: "Ngày Cách mạng tháng Tám", isPublicHoliday: false, since: 1945 },
|
|
32
|
+
"2-9": { name: "Ngày Quốc khánh", isPublicHoliday: true, since: 1945 },
|
|
33
|
+
"10-10": { name: "Ngày Giải phóng Thủ đô", isPublicHoliday: false, since: 1954 },
|
|
34
|
+
"20-10": { name: "Ngày Phụ nữ Việt Nam", isPublicHoliday: false, since: 1930 },
|
|
35
|
+
"20-11": { name: "Ngày Nhà giáo Việt Nam", isPublicHoliday: false, since: 1982 },
|
|
36
|
+
"24-11": { name: "Ngày Văn hóa Việt Nam", isPublicHoliday: true, since: 2026 },
|
|
37
|
+
"22-12": { name: "Ngày thành lập Quân đội Nhân dân Việt Nam", isPublicHoliday: false, since: 1944 },
|
|
38
|
+
"25-12": { name: "Lễ Giáng sinh", isPublicHoliday: false, type: 'traditional' },
|
|
39
|
+
};
|
|
40
|
+
const LUNAR_HOLIDAYS = {
|
|
41
|
+
"1-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
|
|
42
|
+
"2-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
|
|
43
|
+
"3-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
|
|
44
|
+
"15-1": { name: "Tết Nguyên Tiêu", isPublicHoliday: false },
|
|
45
|
+
"3-3": { name: "Tết Hàn Thực", isPublicHoliday: false },
|
|
46
|
+
"10-3": { name: "Giỗ Tổ Hùng Vương", isPublicHoliday: true },
|
|
47
|
+
"15-4": { name: "Lễ Phật Đản", isPublicHoliday: false },
|
|
48
|
+
"5-5": { name: "Tết Đoan Ngọ", isPublicHoliday: false },
|
|
49
|
+
"7-7": { name: "Tết Thất Tịch", isPublicHoliday: false },
|
|
50
|
+
"15-7": { name: "Lễ Vu Lan", isPublicHoliday: false },
|
|
51
|
+
"15-8": { name: "Tết Trung Thu", isPublicHoliday: false },
|
|
52
|
+
"9-9": { name: "Tết Trùng Cửu", isPublicHoliday: false },
|
|
53
|
+
"10-10": { name: "Tết Thường Tân", isPublicHoliday: false },
|
|
54
|
+
"15-10": { name: "Tết Hạ Nguyên", isPublicHoliday: false },
|
|
55
|
+
"23-12": { name: "Lễ cúng Ông Táo", isPublicHoliday: false },
|
|
56
|
+
};
|
|
57
|
+
const getVietnameseHolidays = (solarDay, solarMonth, solarYear, lunarDate, nextLunarDate) => {
|
|
58
|
+
const holidays = [];
|
|
59
|
+
const solarHoliday = SOLAR_HOLIDAYS[`${solarDay}-${solarMonth}`];
|
|
60
|
+
if (solarHoliday && (solarHoliday.since === undefined || solarYear >= solarHoliday.since)) {
|
|
61
|
+
holidays.push(toHoliday(solarHoliday, 'solar'));
|
|
62
|
+
}
|
|
63
|
+
// Lễ âm lịch chỉ tính cho tháng thường, tránh lặp lại ở tháng nhuận.
|
|
64
|
+
if (lunarDate.date !== 0 && !lunarDate.isLeap) {
|
|
65
|
+
const lunarHoliday = LUNAR_HOLIDAYS[`${lunarDate.date}-${lunarDate.month}`];
|
|
66
|
+
if (lunarHoliday) {
|
|
67
|
+
holidays.push(toHoliday(lunarHoliday, 'lunar'));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// 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.
|
|
71
|
+
if (nextLunarDate.date === 1 && nextLunarDate.month === 1 && !nextLunarDate.isLeap) {
|
|
72
|
+
holidays.push(toHoliday(GIAO_THUA, 'lunar'));
|
|
73
|
+
}
|
|
74
|
+
return holidays;
|
|
75
|
+
};
|
|
76
|
+
exports.getVietnameseHolidays = getVietnameseHolidays;
|
|
77
|
+
const eventOf = (def, calendar, jd, lunar) => {
|
|
78
|
+
const h = toHoliday(def, calendar);
|
|
79
|
+
const event = {
|
|
80
|
+
name: h.name, date: (0, utils_js_1.jdToSolarDate)(jd), calendar, type: h.type, isDayOff: h.isDayOff, isPublicHoliday: h.isPublicHoliday,
|
|
81
|
+
};
|
|
82
|
+
if (lunar)
|
|
83
|
+
event.lunarDate = lunar;
|
|
84
|
+
return event;
|
|
85
|
+
};
|
|
86
|
+
const byDate = (a, b) => (a.date.year - b.date.year) || (a.date.month - b.date.month) || (a.date.day - b.date.day);
|
|
87
|
+
/** Mọi ngày lễ rơi vào năm dương `year`, sắp theo ngày tăng dần (lễ dương trước lễ âm nếu trùng ngày). Rỗng nếu ngoài 1800–2199. */
|
|
88
|
+
const getHolidays = (year) => {
|
|
89
|
+
if (!Number.isInteger(year) || year < 1800 || year > 2199)
|
|
90
|
+
return [];
|
|
91
|
+
const events = [];
|
|
92
|
+
for (const [key, def] of Object.entries(SOLAR_HOLIDAYS)) {
|
|
93
|
+
if (def.since !== undefined && year < def.since)
|
|
94
|
+
continue;
|
|
95
|
+
const [day, month] = key.split('-').map(Number);
|
|
96
|
+
events.push(eventOf(def, 'solar', (0, utils_js_1.getJulianDayNumber)(day, month, year)));
|
|
97
|
+
}
|
|
98
|
+
// Năm âm Y-1 và Y đều có thể có ngày rơi vào năm dương Y (Ông Táo 23/12, Giao thừa).
|
|
99
|
+
for (const lunarYear of [year - 1, year, year + 1]) {
|
|
100
|
+
for (const [key, def] of Object.entries(LUNAR_HOLIDAYS)) {
|
|
101
|
+
const [day, month] = key.split('-').map(Number);
|
|
102
|
+
const solar = (0, lunar_js_1.getSolarDate)(day, month, lunarYear, false);
|
|
103
|
+
if (solar && solar.year === year)
|
|
104
|
+
events.push(eventOf(def, 'lunar', solar.jd, { day, month }));
|
|
105
|
+
}
|
|
106
|
+
const tet = (0, lunar_js_1.getSolarDate)(1, 1, lunarYear, false);
|
|
107
|
+
if (tet && tet.jd - 1 >= (0, utils_js_1.getJulianDayNumber)(1, 1, year) && (0, utils_js_1.jdToSolarDate)(tet.jd - 1).year === year) {
|
|
108
|
+
const eve = (0, lunar_js_1.getLunarDate)(...Object.values((0, utils_js_1.jdToSolarDate)(tet.jd - 1)));
|
|
109
|
+
events.push(eventOf(GIAO_THUA, 'lunar', tet.jd - 1, { day: eve.date, month: eve.month }));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return events.sort(byDate);
|
|
113
|
+
};
|
|
114
|
+
exports.getHolidays = getHolidays;
|
|
115
|
+
const dayNumber = (d) => (0, utils_js_1.getJulianDayNumber)(d.day, d.month, d.year);
|
|
116
|
+
const groupConsecutiveEvents = (events) => {
|
|
117
|
+
const grouped = [];
|
|
118
|
+
for (const e of events) {
|
|
119
|
+
const last = grouped[grouped.length - 1];
|
|
120
|
+
if (last && last.name === e.name && last.calendar === e.calendar && dayNumber(last.endDate) + 1 === dayNumber(e.date)) {
|
|
121
|
+
last.endDate = e.date;
|
|
122
|
+
last.days = dayNumber(e.date) - dayNumber(last.date) + 1;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
grouped.push({ ...e, endDate: e.date, days: 1 });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return grouped;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* `count` ngày lễ tiếp theo kể từ `from` (tính cả chính ngày `from`), theo ngày tăng dần.
|
|
132
|
+
* `from` là `DateInput`; throw `RangeError` nếu không hợp lệ. `count` đếm theo phần tử SAU khi lọc và gộp.
|
|
133
|
+
* Với `groupConsecutive`, một chuỗi ngày nghỉ đang diễn ra tại `from` được trả với `date` = ngày đầu thực của chuỗi
|
|
134
|
+
* nếu ngày đó nằm trong cùng năm dương, nên có thể sớm hơn `from`.
|
|
135
|
+
*/
|
|
136
|
+
const nextHolidays = (from, count, options = {}) => {
|
|
137
|
+
const start = (0, input_js_1.requireDateInput)(from, 'nextHolidays');
|
|
138
|
+
if (!Number.isInteger(count) || count <= 0)
|
|
139
|
+
return [];
|
|
140
|
+
const startJd = dayNumber(start);
|
|
141
|
+
const accept = (e) => (!options.types || options.types.indexOf(e.type) !== -1) && (!options.dayOffOnly || e.isDayOff);
|
|
142
|
+
const result = [];
|
|
143
|
+
let pending = []; // các ngày (đã lọc) chưa chắc đã đủ chuỗi liền nhau
|
|
144
|
+
for (let year = start.year; year <= 2199; year++) {
|
|
145
|
+
// Lấy cả năm, kể cả các ngày trước `from`, để chuỗi liền nhau không bị cắt đôi ở `from`.
|
|
146
|
+
const events = (0, exports.getHolidays)(year).filter(accept);
|
|
147
|
+
if (!options.groupConsecutive) {
|
|
148
|
+
for (const e of events)
|
|
149
|
+
if (dayNumber(e.date) >= startJd)
|
|
150
|
+
result.push(e);
|
|
151
|
+
if (result.length >= count)
|
|
152
|
+
break;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
pending = pending.concat(events);
|
|
156
|
+
const groups = groupConsecutiveEvents(pending);
|
|
157
|
+
// Chuỗi cuối có thể kéo sang năm sau (vd Tết cuối tháng 12 dương) — giữ lại đến khi biết chắc.
|
|
158
|
+
const upcoming = groups.filter(g => dayNumber(g.endDate) >= startJd);
|
|
159
|
+
if (upcoming.length >= count + 1 || year === 2199) {
|
|
160
|
+
return upcoming.slice(0, count);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result.slice(0, count);
|
|
164
|
+
};
|
|
165
|
+
exports.nextHolidays = nextHolidays;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { dayInfo, lunarDay, getHourInfo, monthInfo } from './lunarConverter.js';
|
|
2
|
+
export { getLunarDate, getSolarDate, getLeapMonth, getLunarMonthDays } from './lunar.js';
|
|
3
|
+
export { getJulianDayNumber, getSolarTermIndex } from './utils.js';
|
|
4
|
+
export { getHeavenlyEarthly, getDayStemIndex, getDayBranchIndex, getMonthBranchIndex, getCanChi, } from './heavenly_earthly.js';
|
|
5
|
+
export { getDayStarInfo } from './dayStar.js';
|
|
6
|
+
export { getSolarTerms, getSolarTermByIndex } from './solarTerms.js';
|
|
7
|
+
export { getHolidays, nextHolidays } from './holidays.js';
|
|
8
|
+
export { HEAVENLY_STEMS, EARTHLY_BRANCHES, SOLAR_TERMS } from './constants.js';
|
|
9
|
+
export type { LunarDate, DayInfo, LunarDayInfo, DayStarInfo, Holiday, dateFormat, StarSystem, StarCategory, HolidayType, HolidayEvent, HourInfo, SolarTermItem, SolarTermInfo, CanChiInfo, CanChiPart, Element, DayInfoOptions, DateInput, LocalDateTime, NextHolidaysOptions, SolarDateObject, SolarDateResult, } from './type.js';
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOLAR_TERMS = exports.EARTHLY_BRANCHES = exports.HEAVENLY_STEMS = exports.nextHolidays = exports.getHolidays = exports.getSolarTermByIndex = exports.getSolarTerms = exports.getDayStarInfo = exports.getCanChi = exports.getMonthBranchIndex = exports.getDayBranchIndex = exports.getDayStemIndex = exports.getHeavenlyEarthly = exports.getSolarTermIndex = exports.getJulianDayNumber = exports.getLunarMonthDays = exports.getLeapMonth = exports.getSolarDate = exports.getLunarDate = exports.monthInfo = exports.getHourInfo = exports.lunarDay = exports.dayInfo = void 0;
|
|
4
|
+
var lunarConverter_js_1 = require("./lunarConverter.js");
|
|
5
|
+
Object.defineProperty(exports, "dayInfo", { enumerable: true, get: function () { return lunarConverter_js_1.dayInfo; } });
|
|
6
|
+
Object.defineProperty(exports, "lunarDay", { enumerable: true, get: function () { return lunarConverter_js_1.lunarDay; } });
|
|
7
|
+
Object.defineProperty(exports, "getHourInfo", { enumerable: true, get: function () { return lunarConverter_js_1.getHourInfo; } });
|
|
8
|
+
Object.defineProperty(exports, "monthInfo", { enumerable: true, get: function () { return lunarConverter_js_1.monthInfo; } });
|
|
9
|
+
var lunar_js_1 = require("./lunar.js");
|
|
10
|
+
Object.defineProperty(exports, "getLunarDate", { enumerable: true, get: function () { return lunar_js_1.getLunarDate; } });
|
|
11
|
+
Object.defineProperty(exports, "getSolarDate", { enumerable: true, get: function () { return lunar_js_1.getSolarDate; } });
|
|
12
|
+
Object.defineProperty(exports, "getLeapMonth", { enumerable: true, get: function () { return lunar_js_1.getLeapMonth; } });
|
|
13
|
+
Object.defineProperty(exports, "getLunarMonthDays", { enumerable: true, get: function () { return lunar_js_1.getLunarMonthDays; } });
|
|
14
|
+
var utils_js_1 = require("./utils.js");
|
|
15
|
+
Object.defineProperty(exports, "getJulianDayNumber", { enumerable: true, get: function () { return utils_js_1.getJulianDayNumber; } });
|
|
16
|
+
Object.defineProperty(exports, "getSolarTermIndex", { enumerable: true, get: function () { return utils_js_1.getSolarTermIndex; } });
|
|
17
|
+
var heavenly_earthly_js_1 = require("./heavenly_earthly.js");
|
|
18
|
+
Object.defineProperty(exports, "getHeavenlyEarthly", { enumerable: true, get: function () { return heavenly_earthly_js_1.getHeavenlyEarthly; } });
|
|
19
|
+
Object.defineProperty(exports, "getDayStemIndex", { enumerable: true, get: function () { return heavenly_earthly_js_1.getDayStemIndex; } });
|
|
20
|
+
Object.defineProperty(exports, "getDayBranchIndex", { enumerable: true, get: function () { return heavenly_earthly_js_1.getDayBranchIndex; } });
|
|
21
|
+
Object.defineProperty(exports, "getMonthBranchIndex", { enumerable: true, get: function () { return heavenly_earthly_js_1.getMonthBranchIndex; } });
|
|
22
|
+
Object.defineProperty(exports, "getCanChi", { enumerable: true, get: function () { return heavenly_earthly_js_1.getCanChi; } });
|
|
23
|
+
var dayStar_js_1 = require("./dayStar.js");
|
|
24
|
+
Object.defineProperty(exports, "getDayStarInfo", { enumerable: true, get: function () { return dayStar_js_1.getDayStarInfo; } });
|
|
25
|
+
var solarTerms_js_1 = require("./solarTerms.js");
|
|
26
|
+
Object.defineProperty(exports, "getSolarTerms", { enumerable: true, get: function () { return solarTerms_js_1.getSolarTerms; } });
|
|
27
|
+
Object.defineProperty(exports, "getSolarTermByIndex", { enumerable: true, get: function () { return solarTerms_js_1.getSolarTermByIndex; } });
|
|
28
|
+
var holidays_js_1 = require("./holidays.js");
|
|
29
|
+
Object.defineProperty(exports, "getHolidays", { enumerable: true, get: function () { return holidays_js_1.getHolidays; } });
|
|
30
|
+
Object.defineProperty(exports, "nextHolidays", { enumerable: true, get: function () { return holidays_js_1.nextHolidays; } });
|
|
31
|
+
var constants_js_1 = require("./constants.js");
|
|
32
|
+
Object.defineProperty(exports, "HEAVENLY_STEMS", { enumerable: true, get: function () { return constants_js_1.HEAVENLY_STEMS; } });
|
|
33
|
+
Object.defineProperty(exports, "EARTHLY_BRANCHES", { enumerable: true, get: function () { return constants_js_1.EARTHLY_BRANCHES; } });
|
|
34
|
+
Object.defineProperty(exports, "SOLAR_TERMS", { enumerable: true, get: function () { return constants_js_1.SOLAR_TERMS; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SolarDateObject } from "./type.js";
|
|
2
|
+
export declare const MIN_YEAR = 1800;
|
|
3
|
+
export declare const MAX_YEAR = 2199;
|
|
4
|
+
/** Chuẩn hóa mọi dạng đầu vào về `{day, month, year}`; `null` nếu sai định dạng, không tồn tại hoặc ngoài 1800–2199. */
|
|
5
|
+
export declare const parseDateInput: (input: unknown) => SolarDateObject | null;
|
|
6
|
+
/** Như `parseDateInput` nhưng throw `RangeError` (thông báo rõ ràng) khi đầu vào không hợp lệ. Dùng chung cho mọi hàm public nhận ngày dương. */
|
|
7
|
+
export declare const requireDateInput: (input: unknown, fnName: string) => SolarDateObject;
|