@lichta/core 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zeforc Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @lichta/core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@lichta/core.svg)](https://www.npmjs.com/package/@lichta/core)
4
+
5
+ Thư viện lõi tính toán chuyển đổi **Dương lịch ↔ Âm lịch Việt Nam** cho JavaScript/TypeScript. Thuần TypeScript, **0 dependency**, không phụ thuộc framework nào — dùng được ở Node.js, trình duyệt, hoặc làm nền cho các binding framework khác ([`@lichta/react`](https://www.npmjs.com/package/@lichta/react), [`@lichta/vue`](https://www.npmjs.com/package/@lichta/vue), [`@lichta/svelte`](https://www.npmjs.com/package/@lichta/svelte)).
6
+
7
+ ## Cài đặt
8
+
9
+ ```bash
10
+ pnpm add @lichta/core
11
+ # hoặc: npm install @lichta/core / yarn add @lichta/core / bun add @lichta/core
12
+ ```
13
+
14
+ ## Sử dụng cơ bản
15
+
16
+ ```typescript
17
+ import { LichTa } from '@lichta/core';
18
+
19
+ // Dương lịch → Âm lịch
20
+ const lunar = LichTa.toLunar(10, 2, 2024);
21
+ // → { day: 1, month: 1, year: 2024, isLeap: false, jd: 2460351,
22
+ // dayCanChi: 'Giáp Thìn', monthCanChi: 'Bính Dần', yearCanChi: 'Giáp Thìn' }
23
+
24
+ // Âm lịch → Dương lịch (isLeap bắt buộc truyền đúng nếu là tháng nhuận)
25
+ const solar = LichTa.toSolar(1, 1, 2024, false);
26
+ // → { day: 10, month: 2, year: 2024 }
27
+
28
+ // Múi giờ tùy chỉnh (mặc định GMT+7 Việt Nam)
29
+ const lunarGmt8 = LichTa.toLunar(10, 2, 2024, 8);
30
+ ```
31
+
32
+ `toLunar`/`toSolar` throw `RangeError` nếu ngày/tháng/năm ngoài phạm vi hợp lệ (năm **1800–2199**) — nên bọc trong `try/catch` khi nhận input từ người dùng.
33
+
34
+ ## Can Chi & Phong Thủy
35
+
36
+ ```typescript
37
+ import { LichTa, getYearDetails, getDayCanChi, getMonthCanChi, getHourCanChi, getAuspiciousHours } from '@lichta/core';
38
+
39
+ getYearDetails(2024);
40
+ // → { can: 'Giáp', chi: 'Thìn', menh: 'Thủy', fullString: 'Giáp Thìn - Mệnh Thủy' }
41
+
42
+ const lunar = LichTa.toLunar(10, 2, 2024);
43
+ getDayCanChi(lunar.jd); // 'Giáp Thìn'
44
+ getMonthCanChi(lunar.month, lunar.year); // 'Bính Dần'
45
+ getHourCanChi(8, lunar.jd); // giờ Thìn (7h-9h)
46
+ getAuspiciousHours(lunar.jd); // 6 giờ Hoàng Đạo trong ngày
47
+ ```
48
+
49
+ ## Format & Hiển thị
50
+
51
+ ```typescript
52
+ import { formatTraditional, formatLunarDate, getMonthName, getDayName } from '@lichta/core';
53
+
54
+ formatTraditional(lunar); // 'Mùng Một tháng Giêng năm Giáp Thìn'
55
+ formatLunarDate(lunar, 'dd/MM/yyyy'); // '01/01/2024'
56
+ formatLunarDate(lunar, 'Ngày d tháng M năm CC'); // 'Ngày 1 tháng 1 năm Giáp Thìn'
57
+
58
+ getMonthName(1); // 'Giêng'
59
+ getDayName(15); // 'Rằm'
60
+ ```
61
+
62
+ **Format tokens:** `dd`/`d` (ngày), `MM`/`M` (tháng), `yyyy`/`yy` (năm), `CC`/`MC`/`DC` (Can Chi năm/tháng/ngày), `L` ("Nhuận" nếu là tháng nhuận).
63
+
64
+ ## i18n
65
+
66
+ Hỗ trợ 4 ngôn ngữ cho tên Can Chi, Ngũ Hành, con giáp, tên tháng, thứ trong tuần: `vi`, `en`, `ja`, `ko`.
67
+
68
+ ```typescript
69
+ import { t, getZodiacAnimal } from '@lichta/core';
70
+
71
+ t('en').fiveElements; // ['Metal', 'Wood', 'Water', 'Fire', 'Earth']
72
+ t('ja').weekDays; // ['日', '月', '火', '水', '木', '金', '土']
73
+ getZodiacAnimal(0, 'vi'); // 'Chuột'
74
+ ```
75
+
76
+ ## API đầy đủ
77
+
78
+ | Nhóm | Hàm/Class |
79
+ |---|---|
80
+ | Solar ↔ Lunar | `LichTa.toLunar()`, `LichTa.toSolar()` |
81
+ | Julian Day Number | `jdFromDate()`, `jdToDate()` |
82
+ | Can Chi & Phong Thủy | `getYearDetails()`, `getDayCanChi()`, `getMonthCanChi()`, `getHourCanChi()`, `getAuspiciousHours()` |
83
+ | Format & Hiển thị | `formatLunarDate()`, `formatTraditional()`, `getMonthName()`, `getDayName()` |
84
+ | i18n | `t()`, `getZodiacAnimal()` |
85
+ | Types | `LunarDate`, `SolarDate`, `Locale` |
86
+
87
+ Xem chi tiết đầy đủ (tham số, kiểu trả về, ví dụ đã chạy thật) tại trang [API Reference](https://lichta.zeneo.app/api).
88
+
89
+ ## Styles (dùng chung cho Calendar component)
90
+
91
+ Package này cũng export sẵn CSS cho component `Calendar` ở các package binding framework — không cần thiết nếu bạn chỉ dùng logic tính toán:
92
+
93
+ ```typescript
94
+ import '@lichta/core/styles/calendar-base.css';
95
+ import '@lichta/core/styles/calendar-glass.css'; // theme kính mờ (tùy chọn)
96
+ ```
97
+
98
+ ## Thuật toán
99
+
100
+ Dựa trên thuật toán của **Hồ Ngọc Đức** (Đại học Leipzig), tham khảo các công thức thiên văn trong *"Astronomical Algorithms"* của **Jean Meeus** (1998) — chuẩn de facto cho lịch âm Việt Nam trong lập trình.
101
+
102
+ ## License
103
+
104
+ [MIT](./LICENSE)
@@ -0,0 +1,265 @@
1
+ /** Kết quả chuyển đổi sang Âm lịch */
2
+ interface LunarDate {
3
+ day: number;
4
+ month: number;
5
+ year: number;
6
+ isLeap: boolean;
7
+ jd: number;
8
+ dayCanChi?: string;
9
+ monthCanChi?: string;
10
+ yearCanChi?: string;
11
+ }
12
+ /** Kết quả chuyển đổi sang Dương lịch */
13
+ interface SolarDate {
14
+ day: number;
15
+ month: number;
16
+ year: number;
17
+ }
18
+
19
+ /**
20
+ * Chuyển ngày Gregorian sang Julian Day Number.
21
+ *
22
+ * @param dd - Ngày (1-31)
23
+ * @param mm - Tháng (1-12)
24
+ * @param yy - Năm
25
+ */
26
+ declare function jdFromDate(dd: number, mm: number, yy: number): number;
27
+ /**
28
+ * Chuyển Julian Day Number sang ngày Gregorian.
29
+ *
30
+ * @param jd - Julian Day Number
31
+ * @returns Tuple [day, month, year]
32
+ */
33
+ declare function jdToDate(jd: number): [number, number, number];
34
+ declare class LichTa {
35
+ /**
36
+ * Chuyển đổi ngày Dương lịch sang Âm lịch.
37
+ *
38
+ * Sử dụng thuật toán Hồ Ngọc Đức để tìm Điểm Sóc và Tiết Khí,
39
+ * từ đó xác định ngày, tháng, năm âm lịch tương ứng.
40
+ *
41
+ * @param day - Ngày dương lịch (1-31)
42
+ * @param month - Tháng dương lịch (1-12)
43
+ * @param year - Năm dương lịch (1800-2199)
44
+ * @param timeZone - Múi giờ (mặc định: 7 cho GMT+7 Việt Nam)
45
+ * @returns Đối tượng LunarDate chứa thông tin ngày âm lịch
46
+ * @throws {RangeError} Khi input ngoài phạm vi hợp lệ
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const lunar = LichTa.toLunar(10, 2, 2024);
51
+ * // → { day: 1, month: 1, year: 2024, isLeap: false, yearCanChi: 'Giáp Thìn' }
52
+ * ```
53
+ */
54
+ static toLunar(day: number, month: number, year: number, timeZone?: number): LunarDate;
55
+ /**
56
+ * Chuyển đổi ngày Âm lịch sang Dương lịch.
57
+ *
58
+ * @param lunarDay - Ngày âm lịch
59
+ * @param lunarMonth - Tháng âm lịch
60
+ * @param lunarYear - Năm âm lịch
61
+ * @param isLeap - Có phải tháng nhuận không
62
+ * @param timeZone - Múi giờ (mặc định: 7 cho GMT+7 Việt Nam)
63
+ * @returns Đối tượng SolarDate
64
+ * @throws {RangeError} Khi năm ngoài phạm vi 1800-2199
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const solar = LichTa.toSolar(1, 1, 2024, false);
69
+ * // → { day: 10, month: 2, year: 2024 }
70
+ * ```
71
+ */
72
+ static toSolar(lunarDay: number, lunarMonth: number, lunarYear: number, isLeap?: boolean, timeZone?: number): SolarDate;
73
+ }
74
+
75
+ /**
76
+ * Lấy ra chuỗi mô tả toàn bộ Can, Chi và Mệnh dựa vào số năm (Ví dụ: 2024)
77
+ * Theo quy ước: Năm 4 (sau CN) là năm Giáp Tý (Can index 0, Chi index 0)
78
+ */
79
+ declare function getYearDetails(year: number): {
80
+ can: "Giáp" | "Ất" | "Bính" | "Đinh" | "Mậu" | "Kỷ" | "Canh" | "Tân" | "Nhâm" | "Quý";
81
+ chi: "Tý" | "Sửu" | "Dần" | "Mão" | "Thìn" | "Tỵ" | "Ngọ" | "Mùi" | "Thân" | "Dậu" | "Tuất" | "Hợi";
82
+ menh: string;
83
+ fullString: string;
84
+ };
85
+ /**
86
+ * Tính Can Chi ngày từ Julian Day Number.
87
+ *
88
+ * @param jd - Julian Day Number
89
+ * @returns Chuỗi Can Chi (ví dụ: "Giáp Tý")
90
+ */
91
+ declare function getDayCanChi(jd: number): string;
92
+ /**
93
+ * Tính Can Chi tháng từ tháng và năm âm lịch.
94
+ * Can tháng phụ thuộc vào Can của năm (quy tắc Ngũ Hổ Độn):
95
+ * - Năm Giáp/Kỷ → Tháng Giêng bắt đầu bằng Bính (index 2)
96
+ * - Năm Ất/Canh → Tháng Giêng bắt đầu bằng Mậu (index 4)
97
+ * - Năm Bính/Tân → Tháng Giêng bắt đầu bằng Canh (index 6)
98
+ * - Năm Đinh/Nhâm → Tháng Giêng bắt đầu bằng Nhâm (index 8)
99
+ * - Năm Mậu/Quý → Tháng Giêng bắt đầu bằng Giáp (index 0)
100
+ *
101
+ * @param lunarMonth - Tháng âm lịch (1-12)
102
+ * @param lunarYear - Năm âm lịch
103
+ */
104
+ declare function getMonthCanChi(lunarMonth: number, lunarYear: number): string;
105
+ /**
106
+ * Tính Can Chi giờ từ giờ (0-23) và Julian Day Number của ngày.
107
+ *
108
+ * 12 canh giờ (mỗi canh = 2 tiếng):
109
+ * Tý: 23h-01h, Sửu: 01h-03h, Dần: 03h-05h, ...
110
+ *
111
+ * Can giờ Tý phụ thuộc Can ngày (quy tắc Ngũ Thử Độn):
112
+ * - Ngày Giáp/Kỷ → Giờ Tý bắt đầu bằng Giáp
113
+ * - Ngày Ất/Canh → Giờ Tý bắt đầu bằng Bính
114
+ * - Ngày Bính/Tân → Giờ Tý bắt đầu bằng Mậu
115
+ * - Ngày Đinh/Nhâm → Giờ Tý bắt đầu bằng Canh
116
+ * - Ngày Mậu/Quý → Giờ Tý bắt đầu bằng Nhâm
117
+ *
118
+ * @param hour - Giờ (0-23)
119
+ * @param dayJd - Julian Day Number của ngày
120
+ */
121
+ declare function getHourCanChi(hour: number, dayJd: number): string;
122
+ /**
123
+ * Lấy danh sách 6 giờ Hoàng Đạo trong ngày.
124
+ * Giờ Hoàng Đạo phụ thuộc vào Địa Chi của ngày.
125
+ *
126
+ * @param dayJd - Julian Day Number của ngày
127
+ * @returns Mảng 6 chuỗi tên Địa Chi (ví dụ: ["Tý", "Sửu", "Mão", "Ngọ", "Mùi", "Dậu"])
128
+ */
129
+ declare function getAuspiciousHours(dayJd: number): string[];
130
+
131
+ /**
132
+ * Lấy tên tháng âm lịch dạng chữ truyền thống.
133
+ *
134
+ * @param month - Tháng âm lịch (1-12)
135
+ * @returns Tên tháng (ví dụ: 1 → "Giêng", 12 → "Chạp")
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * getMonthName(1); // "Giêng"
140
+ * getMonthName(12); // "Chạp"
141
+ * ```
142
+ */
143
+ declare function getMonthName(month: number): string;
144
+ /**
145
+ * Lấy tên ngày âm lịch theo cách gọi truyền thống Việt Nam.
146
+ *
147
+ * - 1-10: "Mùng Một", "Mùng Hai", ..., "Mùng Mười"
148
+ * - 11-20: "Mười Một", ..., "Hai Mươi"
149
+ * - 21-30: "Hăm Mốt", "Hăm Hai", ..., "Ba Mươi"
150
+ *
151
+ * @param day - Ngày âm lịch (1-30)
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * getDayName(1); // "Mùng Một"
156
+ * getDayName(15); // "Rằm"
157
+ * getDayName(30); // "Ba Mươi"
158
+ * ```
159
+ */
160
+ declare function getDayName(day: number): string;
161
+ /**
162
+ * Format ngày âm lịch theo pattern.
163
+ *
164
+ * **Patterns hỗ trợ:**
165
+ * | Token | Mô tả | Ví dụ |
166
+ * |-------|------------------------------------------|----------------|
167
+ * | `dd` | Ngày 2 chữ số | 01, 15, 30 |
168
+ * | `d` | Ngày | 1, 15, 30 |
169
+ * | `MM` | Tháng 2 chữ số | 01, 12 |
170
+ * | `M` | Tháng | 1, 12 |
171
+ * | `yyyy`| Năm 4 chữ số | 2024 |
172
+ * | `yy` | Năm 2 chữ số cuối | 24 |
173
+ * | `L` | "Nhuận" nếu tháng nhuận, "" nếu không | Nhuận |
174
+ * | `CC` | Can Chi năm | Giáp Thìn |
175
+ * | `DC` | Can Chi ngày | Giáp Tý |
176
+ * | `MC` | Can Chi tháng | Bính Dần |
177
+ *
178
+ * @param lunar - Đối tượng LunarDate
179
+ * @param pattern - Chuỗi pattern
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * formatLunarDate(lunar, 'dd/MM/yyyy');
184
+ * // → "01/01/2024"
185
+ *
186
+ * formatLunarDate(lunar, 'Ngày d tháng M năm CC');
187
+ * // → "Ngày 1 tháng 1 năm Giáp Thìn"
188
+ * ```
189
+ */
190
+ declare function formatLunarDate(lunar: LunarDate, pattern: string): string;
191
+ /**
192
+ * Format ngày âm lịch theo kiểu truyền thống Việt Nam.
193
+ *
194
+ * @param lunar - Đối tượng LunarDate
195
+ * @returns Chuỗi truyền thống (ví dụ: "Mùng Một tháng Giêng năm Giáp Thìn")
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * formatTraditional(lunar);
200
+ * // → "Mùng Một tháng Giêng năm Giáp Thìn"
201
+ * ```
202
+ */
203
+ declare function formatTraditional(lunar: LunarDate): string;
204
+
205
+ /**
206
+ * Internationalization — Hỗ trợ song ngữ Việt-Anh
207
+ */
208
+ type Locale = 'vi' | 'en' | 'ja' | 'ko';
209
+ /**
210
+ * Lấy bộ dịch theo locale
211
+ * @param locale - Ngôn ngữ ('vi' | 'en' | 'ja' | 'ko')
212
+ */
213
+ declare function t(locale: Locale): {
214
+ readonly heavenlyStems: readonly ["Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"];
215
+ readonly earthlyBranches: readonly ["Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"];
216
+ readonly fiveElements: readonly ["Kim", "Mộc", "Thủy", "Hỏa", "Thổ"];
217
+ readonly zodiacAnimals: readonly ["Chuột", "Trâu", "Cọp", "Thỏ", "Rồng", "Rắn", "Ngựa", "Dê", "Khỉ", "Gà", "Chó", "Heo"];
218
+ readonly monthNames: readonly ["Giêng", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy", "Tám", "Chín", "Mười", "Một", "Chạp"];
219
+ readonly weekDays: readonly ["CN", "T2", "T3", "T4", "T5", "T6", "T7"];
220
+ readonly leapLabel: "Nhuận";
221
+ readonly yearLabel: "Năm";
222
+ readonly monthLabel: "Tháng";
223
+ readonly destiny: "Mệnh";
224
+ } | {
225
+ readonly heavenlyStems: readonly ["Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"];
226
+ readonly earthlyBranches: readonly ["Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"];
227
+ readonly fiveElements: readonly ["Metal", "Wood", "Water", "Fire", "Earth"];
228
+ readonly zodiacAnimals: readonly ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"];
229
+ readonly monthNames: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
230
+ readonly weekDays: readonly ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
231
+ readonly leapLabel: "Leap";
232
+ readonly yearLabel: "Year";
233
+ readonly monthLabel: "Month";
234
+ readonly destiny: "Destiny";
235
+ } | {
236
+ readonly heavenlyStems: readonly ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"];
237
+ readonly earthlyBranches: readonly ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"];
238
+ readonly fiveElements: readonly ["金", "木", "水", "火", "土"];
239
+ readonly zodiacAnimals: readonly ["鼠", "牛", "虎", "兎", "竜", "蛇", "馬", "羊", "猿", "鶏", "犬", "猪"];
240
+ readonly monthNames: readonly ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
241
+ readonly weekDays: readonly ["日", "月", "火", "水", "木", "金", "土"];
242
+ readonly leapLabel: "閏";
243
+ readonly yearLabel: "年";
244
+ readonly monthLabel: "月";
245
+ readonly destiny: "命";
246
+ } | {
247
+ readonly heavenlyStems: readonly ["갑", "을", "병", "정", "무", "기", "경", "신", "임", "계"];
248
+ readonly earthlyBranches: readonly ["자", "축", "인", "묘", "진", "사", "오", "미", "신", "유", "술", "해"];
249
+ readonly fiveElements: readonly ["금", "목", "수", "화", "토"];
250
+ readonly zodiacAnimals: readonly ["쥐", "소", "호랑이", "토끼", "용", "뱀", "말", "양", "원숭이", "닭", "개", "돼지"];
251
+ readonly monthNames: readonly ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"];
252
+ readonly weekDays: readonly ["일", "월", "화", "수", "목", "금", "토"];
253
+ readonly leapLabel: "윤";
254
+ readonly yearLabel: "년";
255
+ readonly monthLabel: "월";
256
+ readonly destiny: "명";
257
+ };
258
+ /**
259
+ * Lấy tên con giáp theo locale
260
+ * @param branchIndex - Index Địa Chi (0-11)
261
+ * @param locale - Ngôn ngữ
262
+ */
263
+ declare function getZodiacAnimal(branchIndex: number, locale?: Locale): string;
264
+
265
+ export { LichTa, type Locale, type LunarDate, type SolarDate, formatLunarDate, formatTraditional, getAuspiciousHours, getDayCanChi, getDayName, getHourCanChi, getMonthCanChi, getMonthName, getYearDetails, getZodiacAnimal, jdFromDate, jdToDate, t };
@@ -0,0 +1,265 @@
1
+ /** Kết quả chuyển đổi sang Âm lịch */
2
+ interface LunarDate {
3
+ day: number;
4
+ month: number;
5
+ year: number;
6
+ isLeap: boolean;
7
+ jd: number;
8
+ dayCanChi?: string;
9
+ monthCanChi?: string;
10
+ yearCanChi?: string;
11
+ }
12
+ /** Kết quả chuyển đổi sang Dương lịch */
13
+ interface SolarDate {
14
+ day: number;
15
+ month: number;
16
+ year: number;
17
+ }
18
+
19
+ /**
20
+ * Chuyển ngày Gregorian sang Julian Day Number.
21
+ *
22
+ * @param dd - Ngày (1-31)
23
+ * @param mm - Tháng (1-12)
24
+ * @param yy - Năm
25
+ */
26
+ declare function jdFromDate(dd: number, mm: number, yy: number): number;
27
+ /**
28
+ * Chuyển Julian Day Number sang ngày Gregorian.
29
+ *
30
+ * @param jd - Julian Day Number
31
+ * @returns Tuple [day, month, year]
32
+ */
33
+ declare function jdToDate(jd: number): [number, number, number];
34
+ declare class LichTa {
35
+ /**
36
+ * Chuyển đổi ngày Dương lịch sang Âm lịch.
37
+ *
38
+ * Sử dụng thuật toán Hồ Ngọc Đức để tìm Điểm Sóc và Tiết Khí,
39
+ * từ đó xác định ngày, tháng, năm âm lịch tương ứng.
40
+ *
41
+ * @param day - Ngày dương lịch (1-31)
42
+ * @param month - Tháng dương lịch (1-12)
43
+ * @param year - Năm dương lịch (1800-2199)
44
+ * @param timeZone - Múi giờ (mặc định: 7 cho GMT+7 Việt Nam)
45
+ * @returns Đối tượng LunarDate chứa thông tin ngày âm lịch
46
+ * @throws {RangeError} Khi input ngoài phạm vi hợp lệ
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const lunar = LichTa.toLunar(10, 2, 2024);
51
+ * // → { day: 1, month: 1, year: 2024, isLeap: false, yearCanChi: 'Giáp Thìn' }
52
+ * ```
53
+ */
54
+ static toLunar(day: number, month: number, year: number, timeZone?: number): LunarDate;
55
+ /**
56
+ * Chuyển đổi ngày Âm lịch sang Dương lịch.
57
+ *
58
+ * @param lunarDay - Ngày âm lịch
59
+ * @param lunarMonth - Tháng âm lịch
60
+ * @param lunarYear - Năm âm lịch
61
+ * @param isLeap - Có phải tháng nhuận không
62
+ * @param timeZone - Múi giờ (mặc định: 7 cho GMT+7 Việt Nam)
63
+ * @returns Đối tượng SolarDate
64
+ * @throws {RangeError} Khi năm ngoài phạm vi 1800-2199
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const solar = LichTa.toSolar(1, 1, 2024, false);
69
+ * // → { day: 10, month: 2, year: 2024 }
70
+ * ```
71
+ */
72
+ static toSolar(lunarDay: number, lunarMonth: number, lunarYear: number, isLeap?: boolean, timeZone?: number): SolarDate;
73
+ }
74
+
75
+ /**
76
+ * Lấy ra chuỗi mô tả toàn bộ Can, Chi và Mệnh dựa vào số năm (Ví dụ: 2024)
77
+ * Theo quy ước: Năm 4 (sau CN) là năm Giáp Tý (Can index 0, Chi index 0)
78
+ */
79
+ declare function getYearDetails(year: number): {
80
+ can: "Giáp" | "Ất" | "Bính" | "Đinh" | "Mậu" | "Kỷ" | "Canh" | "Tân" | "Nhâm" | "Quý";
81
+ chi: "Tý" | "Sửu" | "Dần" | "Mão" | "Thìn" | "Tỵ" | "Ngọ" | "Mùi" | "Thân" | "Dậu" | "Tuất" | "Hợi";
82
+ menh: string;
83
+ fullString: string;
84
+ };
85
+ /**
86
+ * Tính Can Chi ngày từ Julian Day Number.
87
+ *
88
+ * @param jd - Julian Day Number
89
+ * @returns Chuỗi Can Chi (ví dụ: "Giáp Tý")
90
+ */
91
+ declare function getDayCanChi(jd: number): string;
92
+ /**
93
+ * Tính Can Chi tháng từ tháng và năm âm lịch.
94
+ * Can tháng phụ thuộc vào Can của năm (quy tắc Ngũ Hổ Độn):
95
+ * - Năm Giáp/Kỷ → Tháng Giêng bắt đầu bằng Bính (index 2)
96
+ * - Năm Ất/Canh → Tháng Giêng bắt đầu bằng Mậu (index 4)
97
+ * - Năm Bính/Tân → Tháng Giêng bắt đầu bằng Canh (index 6)
98
+ * - Năm Đinh/Nhâm → Tháng Giêng bắt đầu bằng Nhâm (index 8)
99
+ * - Năm Mậu/Quý → Tháng Giêng bắt đầu bằng Giáp (index 0)
100
+ *
101
+ * @param lunarMonth - Tháng âm lịch (1-12)
102
+ * @param lunarYear - Năm âm lịch
103
+ */
104
+ declare function getMonthCanChi(lunarMonth: number, lunarYear: number): string;
105
+ /**
106
+ * Tính Can Chi giờ từ giờ (0-23) và Julian Day Number của ngày.
107
+ *
108
+ * 12 canh giờ (mỗi canh = 2 tiếng):
109
+ * Tý: 23h-01h, Sửu: 01h-03h, Dần: 03h-05h, ...
110
+ *
111
+ * Can giờ Tý phụ thuộc Can ngày (quy tắc Ngũ Thử Độn):
112
+ * - Ngày Giáp/Kỷ → Giờ Tý bắt đầu bằng Giáp
113
+ * - Ngày Ất/Canh → Giờ Tý bắt đầu bằng Bính
114
+ * - Ngày Bính/Tân → Giờ Tý bắt đầu bằng Mậu
115
+ * - Ngày Đinh/Nhâm → Giờ Tý bắt đầu bằng Canh
116
+ * - Ngày Mậu/Quý → Giờ Tý bắt đầu bằng Nhâm
117
+ *
118
+ * @param hour - Giờ (0-23)
119
+ * @param dayJd - Julian Day Number của ngày
120
+ */
121
+ declare function getHourCanChi(hour: number, dayJd: number): string;
122
+ /**
123
+ * Lấy danh sách 6 giờ Hoàng Đạo trong ngày.
124
+ * Giờ Hoàng Đạo phụ thuộc vào Địa Chi của ngày.
125
+ *
126
+ * @param dayJd - Julian Day Number của ngày
127
+ * @returns Mảng 6 chuỗi tên Địa Chi (ví dụ: ["Tý", "Sửu", "Mão", "Ngọ", "Mùi", "Dậu"])
128
+ */
129
+ declare function getAuspiciousHours(dayJd: number): string[];
130
+
131
+ /**
132
+ * Lấy tên tháng âm lịch dạng chữ truyền thống.
133
+ *
134
+ * @param month - Tháng âm lịch (1-12)
135
+ * @returns Tên tháng (ví dụ: 1 → "Giêng", 12 → "Chạp")
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * getMonthName(1); // "Giêng"
140
+ * getMonthName(12); // "Chạp"
141
+ * ```
142
+ */
143
+ declare function getMonthName(month: number): string;
144
+ /**
145
+ * Lấy tên ngày âm lịch theo cách gọi truyền thống Việt Nam.
146
+ *
147
+ * - 1-10: "Mùng Một", "Mùng Hai", ..., "Mùng Mười"
148
+ * - 11-20: "Mười Một", ..., "Hai Mươi"
149
+ * - 21-30: "Hăm Mốt", "Hăm Hai", ..., "Ba Mươi"
150
+ *
151
+ * @param day - Ngày âm lịch (1-30)
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * getDayName(1); // "Mùng Một"
156
+ * getDayName(15); // "Rằm"
157
+ * getDayName(30); // "Ba Mươi"
158
+ * ```
159
+ */
160
+ declare function getDayName(day: number): string;
161
+ /**
162
+ * Format ngày âm lịch theo pattern.
163
+ *
164
+ * **Patterns hỗ trợ:**
165
+ * | Token | Mô tả | Ví dụ |
166
+ * |-------|------------------------------------------|----------------|
167
+ * | `dd` | Ngày 2 chữ số | 01, 15, 30 |
168
+ * | `d` | Ngày | 1, 15, 30 |
169
+ * | `MM` | Tháng 2 chữ số | 01, 12 |
170
+ * | `M` | Tháng | 1, 12 |
171
+ * | `yyyy`| Năm 4 chữ số | 2024 |
172
+ * | `yy` | Năm 2 chữ số cuối | 24 |
173
+ * | `L` | "Nhuận" nếu tháng nhuận, "" nếu không | Nhuận |
174
+ * | `CC` | Can Chi năm | Giáp Thìn |
175
+ * | `DC` | Can Chi ngày | Giáp Tý |
176
+ * | `MC` | Can Chi tháng | Bính Dần |
177
+ *
178
+ * @param lunar - Đối tượng LunarDate
179
+ * @param pattern - Chuỗi pattern
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * formatLunarDate(lunar, 'dd/MM/yyyy');
184
+ * // → "01/01/2024"
185
+ *
186
+ * formatLunarDate(lunar, 'Ngày d tháng M năm CC');
187
+ * // → "Ngày 1 tháng 1 năm Giáp Thìn"
188
+ * ```
189
+ */
190
+ declare function formatLunarDate(lunar: LunarDate, pattern: string): string;
191
+ /**
192
+ * Format ngày âm lịch theo kiểu truyền thống Việt Nam.
193
+ *
194
+ * @param lunar - Đối tượng LunarDate
195
+ * @returns Chuỗi truyền thống (ví dụ: "Mùng Một tháng Giêng năm Giáp Thìn")
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * formatTraditional(lunar);
200
+ * // → "Mùng Một tháng Giêng năm Giáp Thìn"
201
+ * ```
202
+ */
203
+ declare function formatTraditional(lunar: LunarDate): string;
204
+
205
+ /**
206
+ * Internationalization — Hỗ trợ song ngữ Việt-Anh
207
+ */
208
+ type Locale = 'vi' | 'en' | 'ja' | 'ko';
209
+ /**
210
+ * Lấy bộ dịch theo locale
211
+ * @param locale - Ngôn ngữ ('vi' | 'en' | 'ja' | 'ko')
212
+ */
213
+ declare function t(locale: Locale): {
214
+ readonly heavenlyStems: readonly ["Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"];
215
+ readonly earthlyBranches: readonly ["Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"];
216
+ readonly fiveElements: readonly ["Kim", "Mộc", "Thủy", "Hỏa", "Thổ"];
217
+ readonly zodiacAnimals: readonly ["Chuột", "Trâu", "Cọp", "Thỏ", "Rồng", "Rắn", "Ngựa", "Dê", "Khỉ", "Gà", "Chó", "Heo"];
218
+ readonly monthNames: readonly ["Giêng", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy", "Tám", "Chín", "Mười", "Một", "Chạp"];
219
+ readonly weekDays: readonly ["CN", "T2", "T3", "T4", "T5", "T6", "T7"];
220
+ readonly leapLabel: "Nhuận";
221
+ readonly yearLabel: "Năm";
222
+ readonly monthLabel: "Tháng";
223
+ readonly destiny: "Mệnh";
224
+ } | {
225
+ readonly heavenlyStems: readonly ["Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"];
226
+ readonly earthlyBranches: readonly ["Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"];
227
+ readonly fiveElements: readonly ["Metal", "Wood", "Water", "Fire", "Earth"];
228
+ readonly zodiacAnimals: readonly ["Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"];
229
+ readonly monthNames: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
230
+ readonly weekDays: readonly ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
231
+ readonly leapLabel: "Leap";
232
+ readonly yearLabel: "Year";
233
+ readonly monthLabel: "Month";
234
+ readonly destiny: "Destiny";
235
+ } | {
236
+ readonly heavenlyStems: readonly ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"];
237
+ readonly earthlyBranches: readonly ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"];
238
+ readonly fiveElements: readonly ["金", "木", "水", "火", "土"];
239
+ readonly zodiacAnimals: readonly ["鼠", "牛", "虎", "兎", "竜", "蛇", "馬", "羊", "猿", "鶏", "犬", "猪"];
240
+ readonly monthNames: readonly ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
241
+ readonly weekDays: readonly ["日", "月", "火", "水", "木", "金", "土"];
242
+ readonly leapLabel: "閏";
243
+ readonly yearLabel: "年";
244
+ readonly monthLabel: "月";
245
+ readonly destiny: "命";
246
+ } | {
247
+ readonly heavenlyStems: readonly ["갑", "을", "병", "정", "무", "기", "경", "신", "임", "계"];
248
+ readonly earthlyBranches: readonly ["자", "축", "인", "묘", "진", "사", "오", "미", "신", "유", "술", "해"];
249
+ readonly fiveElements: readonly ["금", "목", "수", "화", "토"];
250
+ readonly zodiacAnimals: readonly ["쥐", "소", "호랑이", "토끼", "용", "뱀", "말", "양", "원숭이", "닭", "개", "돼지"];
251
+ readonly monthNames: readonly ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"];
252
+ readonly weekDays: readonly ["일", "월", "화", "수", "목", "금", "토"];
253
+ readonly leapLabel: "윤";
254
+ readonly yearLabel: "년";
255
+ readonly monthLabel: "월";
256
+ readonly destiny: "명";
257
+ };
258
+ /**
259
+ * Lấy tên con giáp theo locale
260
+ * @param branchIndex - Index Địa Chi (0-11)
261
+ * @param locale - Ngôn ngữ
262
+ */
263
+ declare function getZodiacAnimal(branchIndex: number, locale?: Locale): string;
264
+
265
+ export { LichTa, type Locale, type LunarDate, type SolarDate, formatLunarDate, formatTraditional, getAuspiciousHours, getDayCanChi, getDayName, getHourCanChi, getMonthCanChi, getMonthName, getYearDetails, getZodiacAnimal, jdFromDate, jdToDate, t };