@thyrith/momentkh 3.0.1 โ 3.0.2
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/README.md +89 -69
- package/dist/momentkh.d.ts +24 -10
- package/dist/momentkh.d.ts.map +1 -1
- package/dist/momentkh.js +66 -37
- package/momentkh.js +68 -38
- package/momentkh.ts +70 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
**MomentKH** is a lightweight, zero-dependency JavaScript/TypeScript library for accurate Khmer (Cambodian) Lunar Calendar conversions. It provides a modern, standalone implementation with full TypeScript support.
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[๐ฎ **Live Demo Playground**](https://thyrithsor.github.io/momentkh/)
|
|
6
|
+
|
|
7
|
+
[](https://github.com/ThyrithSor/momentkh)
|
|
6
8
|
[](LICENSE)
|
|
7
9
|
[](https://github.com/ThyrithSor/momentkh)
|
|
8
10
|
|
|
@@ -52,7 +54,7 @@ console.log(newYear);
|
|
|
52
54
|
- [Understanding Khmer Calendar](#-understanding-khmer-calendar)
|
|
53
55
|
- [Buddhist Era (BE) Year](#buddhist-era-be-year)
|
|
54
56
|
- [Animal Year](#animal-year)
|
|
55
|
-
- [
|
|
57
|
+
- [Sak](#sak-year-sak)
|
|
56
58
|
- [When Each Year Type Increases](#when-each-year-type-increases)
|
|
57
59
|
- [Format Codes](#-format-codes)
|
|
58
60
|
- [Constants](#-constants)
|
|
@@ -66,7 +68,7 @@ console.log(newYear);
|
|
|
66
68
|
|
|
67
69
|
- โ
**Zero Dependencies** - Pure JavaScript, no external libraries required
|
|
68
70
|
- โ
**TypeScript Support** - Full type definitions included for excellent IDE experience
|
|
69
|
-
- โ
**Type-Safe Enums** - NEW in v3.0! Use enums for moonPhase, monthIndex, animalYear,
|
|
71
|
+
- โ
**Type-Safe Enums** - NEW in v3.0! Use enums for moonPhase, monthIndex, animalYear, sak, and dayOfWeek
|
|
70
72
|
- โ
**Bidirectional Conversion** - Convert between Gregorian โ Khmer Lunar dates
|
|
71
73
|
- โ
**Accurate Calculations** - Based on traditional Khmer astronomical algorithms
|
|
72
74
|
- โ
**Khmer New Year** - Precise calculation of Moha Songkran timing
|
|
@@ -85,14 +87,6 @@ console.log(newYear);
|
|
|
85
87
|
npm install @thyrith/momentkh
|
|
86
88
|
```
|
|
87
89
|
|
|
88
|
-
### Direct Download
|
|
89
|
-
|
|
90
|
-
Download `momentkh.js` from the repository and include it in your project.
|
|
91
|
-
|
|
92
|
-
```bash
|
|
93
|
-
cp momentkh.js /path/to/your/project/
|
|
94
|
-
```
|
|
95
|
-
|
|
96
90
|
### TypeScript
|
|
97
91
|
|
|
98
92
|
Type definitions are included automatically when you install via NPM. For direct downloads, you can also use `momentkh.ts` or the compiled `.d.ts` files from the `dist/` folder.
|
|
@@ -105,7 +99,7 @@ Type definitions are included automatically when you install via NPM. For direct
|
|
|
105
99
|
|
|
106
100
|
```html
|
|
107
101
|
<!-- Include the browser-compatible UMD bundle -->
|
|
108
|
-
<script src="momentkh.js"></script>
|
|
102
|
+
<script src="https://cdn.jsdelivr.net/gh/ThyrithSor/momentkh@3.0.2/momentkh.js"></script>
|
|
109
103
|
<script>
|
|
110
104
|
// Convert today to Khmer
|
|
111
105
|
const today = new Date();
|
|
@@ -153,7 +147,7 @@ import momentkh, {
|
|
|
153
147
|
MoonPhase,
|
|
154
148
|
MonthIndex,
|
|
155
149
|
AnimalYear,
|
|
156
|
-
|
|
150
|
+
Sak,
|
|
157
151
|
DayOfWeek,
|
|
158
152
|
} from "@thyrith/momentkh";
|
|
159
153
|
|
|
@@ -209,7 +203,7 @@ const monthName = momentkh.constants.LunarMonthNames[4]; // "แ
แแแแ"
|
|
|
209
203
|
- ๐ `MoonPhase` - Waxing (แแพแ) and Waning (แแแ
)
|
|
210
204
|
- ๐
`MonthIndex` - All 14 Khmer lunar months
|
|
211
205
|
- ๐ `AnimalYear` - All 12 animal years
|
|
212
|
-
- โญ `
|
|
206
|
+
- โญ `Sak` - All 10 Saks
|
|
213
207
|
- ๐ `DayOfWeek` - Sunday through Saturday
|
|
214
208
|
|
|
215
209
|
---
|
|
@@ -253,8 +247,8 @@ Converts a Gregorian (Western) date to a Khmer Lunar date.
|
|
|
253
247
|
jsYear: 1386, // Number: Jolak Sakaraj (Chula Sakaraj) year
|
|
254
248
|
animalYear: 4, // AnimalYear enum: 0-11 (NEW in v3.0)
|
|
255
249
|
animalYearName: 'แแแ', // String: Animal year name
|
|
256
|
-
|
|
257
|
-
|
|
250
|
+
sak: 6, // Sak enum: 0-9 (NEW in v3.0)
|
|
251
|
+
sakName: 'แแแแ', // String: Sak name
|
|
258
252
|
dayOfWeek: 0, // DayOfWeek enum: 0=Sunday, 6=Saturday (NEW in v3.0)
|
|
259
253
|
dayOfWeekName: 'แขแถแแทแแแ' // String: Khmer weekday name
|
|
260
254
|
},
|
|
@@ -448,9 +442,14 @@ Formats a Khmer date object into a string with optional custom formatting.
|
|
|
448
442
|
**Default Format:**
|
|
449
443
|
|
|
450
444
|
```
|
|
451
|
-
แแแแ{weekday} {day}{moonPhase} แแ{month} แแแแถแ{animalYear} {
|
|
445
|
+
แแแแ{weekday} {day}{moonPhase} แแ{month} แแแแถแ{animalYear} {sak} แแปแแแแแแแถแ {beYear}
|
|
452
446
|
```
|
|
453
447
|
|
|
448
|
+
**Escaping Characters:**
|
|
449
|
+
To escape characters in the format string (so they are not interpreted as format codes), wrap them in square brackets `[]`.
|
|
450
|
+
|
|
451
|
+
Example: `[Week] w` -> "Week แขแถ"
|
|
452
|
+
|
|
454
453
|
**Returns:** String (formatted Khmer date)
|
|
455
454
|
|
|
456
455
|
**Example:**
|
|
@@ -471,6 +470,10 @@ console.log(momentkh.format(khmer, "c/M/D"));
|
|
|
471
470
|
|
|
472
471
|
console.log(momentkh.format(khmer, "แแแแw dN m แแแแถแa e แ.แ.b"));
|
|
473
472
|
// แแแแแขแถ แฆแแพแ แ
แแแแ แแแแถแแแแ แแแแ แ.แ.แขแฅแฆแจ
|
|
473
|
+
|
|
474
|
+
// Escaping characters (use brackets [])
|
|
475
|
+
console.log(momentkh.format(khmer, "[Day:] d [Month:] m"));
|
|
476
|
+
// Day: แฆ Month: แ
แแแแ
|
|
474
477
|
```
|
|
475
478
|
|
|
476
479
|
---
|
|
@@ -536,23 +539,23 @@ AnimalYear.Cho; // 10 - ๐ แ
(Dog)
|
|
|
536
539
|
AnimalYear.Kor; // 11 - ๐ แแปแ (Pig)
|
|
537
540
|
```
|
|
538
541
|
|
|
539
|
-
#### โญ
|
|
542
|
+
#### โญ Sak
|
|
540
543
|
|
|
541
|
-
The 10
|
|
544
|
+
The 10 Saks (แแแ) cycle.
|
|
542
545
|
|
|
543
546
|
```javascript
|
|
544
|
-
const {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
547
|
+
const { Sak } = momentkh;
|
|
548
|
+
|
|
549
|
+
Sak.SamridhiSak; // 0 - ๐ แแแแนแแแแทแแแ
|
|
550
|
+
Sak.AekSak; // 1 - 1๏ธโฃ แฏแแแแ
|
|
551
|
+
Sak.ToSak; // 2 - 2๏ธโฃ แแแแแ
|
|
552
|
+
Sak.TreiSak; // 3 - 3๏ธโฃ แแแแธแแแ
|
|
553
|
+
Sak.ChattvaSak; // 4 - 4๏ธโฃ แ
แแแแถแแแ
|
|
554
|
+
Sak.PanchaSak; // 5 - 5๏ธโฃ แแแแ
แแแ
|
|
555
|
+
Sak.ChhaSak; // 6 - 6๏ธโฃ แแแแ
|
|
556
|
+
Sak.SappaSak; // 7 - 7๏ธโฃ แแแแแแแ
|
|
557
|
+
Sak.AtthaSak; // 8 - 8๏ธโฃ แขแแแแแแ
|
|
558
|
+
Sak.NappaSak; // 9 - 9๏ธโฃ แแแแแแแ
|
|
556
559
|
```
|
|
557
560
|
|
|
558
561
|
#### ๐ DayOfWeek
|
|
@@ -785,13 +788,13 @@ console.log(at.khmer.animalYear); // 'แแแถ' (Rooster) - Changed!
|
|
|
785
788
|
|
|
786
789
|
---
|
|
787
790
|
|
|
788
|
-
###
|
|
791
|
+
### Sak
|
|
789
792
|
|
|
790
793
|
**Full Name:** แแแ (Sak, Era)
|
|
791
794
|
**Cycle:** 10 years
|
|
792
795
|
**When it increases:** At **midnight (00:00) of the last day** of Khmer New Year celebration (Lerng Sak - แแแแแกแพแแแแ)
|
|
793
796
|
|
|
794
|
-
**The 10
|
|
797
|
+
**The 10 Saks (in order):**
|
|
795
798
|
| Index | Khmer | Romanization |
|
|
796
799
|
|-------|-------|--------------|
|
|
797
800
|
| 0 | แแแแนแแแแทแแแ | Samridhi Sak |
|
|
@@ -809,19 +812,19 @@ console.log(at.khmer.animalYear); // 'แแแถ' (Rooster) - Changed!
|
|
|
809
812
|
|
|
810
813
|
- ๐ **Day 1:** Moha Songkran (แแ แถแแแแแแแถแแแ) - New Year's Day
|
|
811
814
|
- ๐ **Day 2:** Virak Wanabat (แแธแแแแแแแ) - Second day
|
|
812
|
-
- โญ **Day 3 or 4:** Lerng Sak (แแแแแกแพแแแแ) - Last day &
|
|
815
|
+
- โญ **Day 3 or 4:** Lerng Sak (แแแแแกแพแแแแ) - Last day & Sak change day
|
|
813
816
|
|
|
814
817
|
**Example:**
|
|
815
818
|
|
|
816
819
|
```javascript
|
|
817
820
|
// 2024 New Year is on April 13, 22:24
|
|
818
|
-
// Lerng Sak (
|
|
821
|
+
// Lerng Sak (Sak change) is typically 3-4 days later at midnight
|
|
819
822
|
|
|
820
823
|
const newYearDay = momentkh.fromGregorian(2024, 4, 13, 23, 0);
|
|
821
|
-
console.log(newYearDay.khmer.
|
|
824
|
+
console.log(newYearDay.khmer.sak); // 'แแแแ' (still old sak)
|
|
822
825
|
|
|
823
826
|
const lerngSakDay = momentkh.fromGregorian(2024, 4, 17, 0, 0); // Midnight of Lerng Sak
|
|
824
|
-
console.log(lerngSakDay.khmer.
|
|
827
|
+
console.log(lerngSakDay.khmer.sak); // 'แแแแแแแ' (new sak!)
|
|
825
828
|
```
|
|
826
829
|
|
|
827
830
|
---
|
|
@@ -834,16 +837,16 @@ console.log(lerngSakDay.khmer.eraYear); // 'แแแแแแแ' (new era!)
|
|
|
834
837
|
| --------------- | ------------------------ | -------------------- |
|
|
835
838
|
| **BE Year** | 00:00 แแ
แแแแแกแแแ
แแแแทแแถแ | May 23, 2024 00:00 |
|
|
836
839
|
| **Animal Year** | แแแแ แแทแ แแถแแธแแแแแถแ
แปแ | April 13, 2024 22:17 |
|
|
837
|
-
| **
|
|
840
|
+
| **Sak** | 00:00 แแ
แแแแแกแพแแแแ | April 16, 2024 00:00 |
|
|
838
841
|
|
|
839
842
|
**Visual Timeline for 2024:**
|
|
840
843
|
|
|
841
844
|
```
|
|
842
|
-
April 13, 22:23 โ BE 2567, Monkey (แแ), Old
|
|
843
|
-
April 13, 22:24 โ BE 2567, Rooster (แแแถ), Old
|
|
844
|
-
April 17, 00:00 โ BE 2567, Rooster (แแแถ), New
|
|
845
|
-
May 22, 23:59 โ BE 2567, Rooster (แแแถ), New
|
|
846
|
-
May 23, 00:00 โ BE 2568, Rooster (แแแถ), New
|
|
845
|
+
April 13, 22:23 โ BE 2567, Monkey (แแ), Old Sak (แแแแ)
|
|
846
|
+
April 13, 22:24 โ BE 2567, Rooster (แแแถ), Old Sak (แแแแ) โ Animal Year changes
|
|
847
|
+
April 17, 00:00 โ BE 2567, Rooster (แแแถ), New Sak (แแแแแแแ) โ Sak changes
|
|
848
|
+
May 22, 23:59 โ BE 2567, Rooster (แแแถ), New Sak (แแแแแแแ)
|
|
849
|
+
May 23, 00:00 โ BE 2568, Rooster (แแแถ), New Sak (แแแแแแแ) โ BE Year changes
|
|
847
850
|
```
|
|
848
851
|
|
|
849
852
|
---
|
|
@@ -852,26 +855,39 @@ May 23, 00:00 โ BE 2568, Rooster (แแแถ), New Era (แแแแแแแ
|
|
|
852
855
|
|
|
853
856
|
Complete list of format tokens for the `format()` function:
|
|
854
857
|
|
|
855
|
-
| Token | Output | Description
|
|
856
|
-
| ---------------------- | ----------------- |
|
|
858
|
+
| Token | Output | Description | Example |
|
|
859
|
+
| ---------------------- | ----------------- | ------------------------------ | --------------------- |
|
|
857
860
|
| **๐
Date Components** |
|
|
858
|
-
| `W` | แแแแแแแแแแแถแ แแแแ | Weekday name (full)
|
|
859
|
-
| `w` | แแแแแแแแแแแถแ แแแแแธ | Weekday name (short)
|
|
860
|
-
| `d` | แแแแแแธ | Lunar day number
|
|
861
|
-
| `D` | แแแแแแธ (แขแแแแแ) | Lunar day (zero-padded)
|
|
861
|
+
| `W` | แแแแแแแแแแแถแ แแแแ | Weekday name (full) | แขแถแแทแแแ, แ
แแแ, แขแแแแถแ |
|
|
862
|
+
| `w` | แแแแแแแแแแแถแ แแแแแธ | Weekday name (short) | แขแถ, แ
, แข |
|
|
863
|
+
| `d` | แแแแแแธ | Lunar day number | แก, แฅ, แกแฅ |
|
|
864
|
+
| `D` | แแแแแแธ (แขแแแแแ) | Lunar day (zero-padded) | แ แก, แ แฅ, แกแฅ |
|
|
862
865
|
| **๐ Moon Phase** |
|
|
863
|
-
| `n` | แแพแ/แแแ
(แแแแธ) | Moon phase (short)
|
|
864
|
-
| `N` | แแพแ/แแแ
(แแแ) | Moon phase (full)
|
|
865
|
-
| `o` | แแทแแทแแแแแแแแถ | Moon day symbol
|
|
866
|
+
| `n` | แแพแ/แแแ
(แแแแธ) | Moon phase (short) | แ, แ |
|
|
867
|
+
| `N` | แแพแ/แแแ
(แแแ) | Moon phase (full) | แแพแ, แแแ
|
|
|
868
|
+
| `o` | แแทแแทแแแแแแแแถ | Moon day symbol | แงก, แงข, แงฃ ... แงฟ |
|
|
866
869
|
| **๐ Month Names** |
|
|
867
|
-
| `m` | แแแ
แแแแแแท | Lunar month name
|
|
868
|
-
| `
|
|
870
|
+
| `m` | แแแ
แแแแแแท | Lunar month name | แแทแแแทแ, แแปแแแ, แ
แแแแ |
|
|
871
|
+
| `ms` | แแ (แแแแแแ) | Lunar month name (abbreviated) | แแท, แแป |
|
|
872
|
+
| `Ms` | แแ (แแแแแแ) | Solar month name (abbreviated) | แแ, แแ |
|
|
873
|
+
| `M` | แแแแปแแทแแแแท | Solar month name | แแแแถ, แแปแแแแ, แแแแถ |
|
|
869
874
|
| **โฐ Year Components** |
|
|
870
|
-
| `a` | แแแแถแแแแแ | Animal year
|
|
871
|
-
| `
|
|
872
|
-
| `
|
|
873
|
-
| `
|
|
874
|
-
| `
|
|
875
|
+
| `a` | แแแแถแแแแแ | Animal year | แแผแ, แแแแผแ, แแแ |
|
|
876
|
+
| `as` | แแแแถแ (แแผแ) | Animal year emoji | ๐, ๐, ๐ |
|
|
877
|
+
| `e` | แแแ | Sak | แฏแแแแ, แแแแแ |
|
|
878
|
+
| `b` | แ.แ. | Buddhist Era year | แขแฅแฆแจ |
|
|
879
|
+
| `br` | BE | Buddhist Era year (Latin) | 2568 |
|
|
880
|
+
| `c` | แ.แ. | Common Era (Gregorian) year | แขแ แขแค |
|
|
881
|
+
| `cr` | CE | Common Era year (Latin) | 2024 |
|
|
882
|
+
| `j` | แ
.แ. | Jolak Sakaraj year | แกแฃแจแฆ |
|
|
883
|
+
| `jr` | JS | Jolak Sakaraj year (Latin) | 1386 |
|
|
884
|
+
| **๐
Day Components** |
|
|
885
|
+
| `d` | แแแแแแธ | Day of month | แก, แข, แกแค |
|
|
886
|
+
| `dr` | Day | Day of month (Latin) | 1, 2, 14 |
|
|
887
|
+
| `D` | แแแแแแธ (แแถแแ ) | Day of month (padded) | แ แก, แ แข, แกแค |
|
|
888
|
+
| `Dr` | Day (0) | Day of month (padded Latin) | 01, 02, 14 |
|
|
889
|
+
| `W` | แแแแแแแแแแแถแ แ | Day of week (full) | แขแถแแทแแแ, แ
แแแ |
|
|
890
|
+
| `w` | แแแแ (แแแแแแ) | Day of week (short) | แขแถ, แ
, แข |
|
|
875
891
|
|
|
876
892
|
**Format Examples:**
|
|
877
893
|
|
|
@@ -915,8 +931,13 @@ momentkh.constants.AnimalYearNames;
|
|
|
915
931
|
// ['แแผแ', 'แแแแผแ', 'แแถแ', 'แแแ', 'แแแ', 'แแแแถแแ',
|
|
916
932
|
// 'แแแธ', 'แแแ', 'แแ', 'แแแถ', 'แ
', 'แแปแ']
|
|
917
933
|
|
|
918
|
-
//
|
|
919
|
-
momentkh.constants.
|
|
934
|
+
// Animal year emojis array (indices 0-11)
|
|
935
|
+
momentkh.constants.AnimalYearEmojis;
|
|
936
|
+
// ['๐', '๐', '๐
', '๐', '๐', '๐',
|
|
937
|
+
// '๐', '๐', '๐', '๐', '๐', '๐']
|
|
938
|
+
|
|
939
|
+
// Sak names array (indices 0-9)
|
|
940
|
+
momentkh.constants.SakNames;
|
|
920
941
|
// ['แแแแนแแแแทแแแ', 'แฏแแแแ', 'แแแแแ', 'แแแแธแแแ', 'แ
แแแแถแแแ',
|
|
921
942
|
// 'แแแแ
แแแ', 'แแแแ', 'แแแแแแแ', 'แขแแแแแแ', 'แแแแแแแ']
|
|
922
943
|
|
|
@@ -925,7 +946,7 @@ momentkh.constants.WeekdayNames;
|
|
|
925
946
|
// ['แขแถแแทแแแ', 'แ
แแแ', 'แขแแแแถแ', 'แแปแ', 'แแแแ แแแแแทแ', 'แแปแแแ', 'แแ
แแ']
|
|
926
947
|
|
|
927
948
|
// Moon phase names array (indices 0-1)
|
|
928
|
-
momentkh.constants.
|
|
949
|
+
momentkh.constants.MoonPhaseNames;
|
|
929
950
|
// ['แแพแ', 'แแแ
']
|
|
930
951
|
```
|
|
931
952
|
|
|
@@ -1126,7 +1147,7 @@ console.log(
|
|
|
1126
1147
|
);
|
|
1127
1148
|
console.log("BE Year:", khmer.khmer.beYear);
|
|
1128
1149
|
console.log("Animal Year:", khmer.khmer.animalYear);
|
|
1129
|
-
console.log("
|
|
1150
|
+
console.log("Sak:", khmer.khmer.sak);
|
|
1130
1151
|
console.log("Month:", khmer.khmer.monthName);
|
|
1131
1152
|
console.log(
|
|
1132
1153
|
"Day:",
|
|
@@ -1137,7 +1158,7 @@ console.log(
|
|
|
1137
1158
|
// Gregorian: 14/4/2024
|
|
1138
1159
|
// BE Year: 2568
|
|
1139
1160
|
// Animal Year: แแแ
|
|
1140
|
-
//
|
|
1161
|
+
// Sak: แแแแ
|
|
1141
1162
|
// Month: แ
แแแแ
|
|
1142
1163
|
// Day: 6แแพแ
|
|
1143
1164
|
```
|
|
@@ -1274,7 +1295,7 @@ for (let day = 20; day <= 25; day++) {
|
|
|
1274
1295
|
|
|
1275
1296
|
MIT License - Same as original momentkh
|
|
1276
1297
|
|
|
1277
|
-
Copyright (c)
|
|
1298
|
+
Copyright (c) 2025
|
|
1278
1299
|
|
|
1279
1300
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
1280
1301
|
|
|
@@ -1322,12 +1343,11 @@ node test_specific_dates.js
|
|
|
1322
1343
|
|
|
1323
1344
|
## ๐ Support
|
|
1324
1345
|
|
|
1325
|
-
- **Documentation:** See examples folder (`newYearMoment.js`, `index.html`)
|
|
1326
1346
|
- **Issues:** [GitHub Issues](https://github.com/ThyrithSor/momentkh/issues)
|
|
1327
1347
|
- **Comparison:** Check behavior against original momentkh for compatibility
|
|
1348
|
+
- **Contact** [E-mail](me@thyrith.com)
|
|
1328
1349
|
|
|
1329
1350
|
---
|
|
1330
1351
|
|
|
1331
|
-
**Version:** 3.0.
|
|
1332
|
-
**Last Updated:** December
|
|
1333
|
-
**Status:** Production Ready โ
|
|
1352
|
+
**Version:** 3.0.2
|
|
1353
|
+
**Last Updated:** December 2025
|
package/dist/momentkh.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare enum AnimalYear {
|
|
|
45
45
|
Cho = 10,// แ
- Dog
|
|
46
46
|
Kor = 11
|
|
47
47
|
}
|
|
48
|
-
export declare enum
|
|
48
|
+
export declare enum Sak {
|
|
49
49
|
SamridhiSak = 0,// แแแแนแแแแทแแแ
|
|
50
50
|
AekSak = 1,// แฏแแแแ
|
|
51
51
|
ToSak = 2,// แแแแแ
|
|
@@ -85,8 +85,8 @@ export interface KhmerDateInfo {
|
|
|
85
85
|
jsYear: number;
|
|
86
86
|
animalYear: AnimalYear;
|
|
87
87
|
animalYearName: string;
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
sak: Sak;
|
|
89
|
+
sakName: string;
|
|
90
90
|
dayOfWeek: DayOfWeek;
|
|
91
91
|
dayOfWeekName: string;
|
|
92
92
|
}
|
|
@@ -138,10 +138,18 @@ export interface Constants {
|
|
|
138
138
|
LunarMonths: Record<string, number>;
|
|
139
139
|
LunarMonthNames: string[];
|
|
140
140
|
SolarMonthNames: string[];
|
|
141
|
+
SolarMonthAbbreviationNames: string[];
|
|
142
|
+
LunarMonthAbbreviationNames: string[];
|
|
141
143
|
AnimalYearNames: string[];
|
|
142
|
-
|
|
144
|
+
AnimalYearEmojis: string[];
|
|
145
|
+
SakNames: string[];
|
|
143
146
|
WeekdayNames: string[];
|
|
144
|
-
|
|
147
|
+
WeekdayNamesShort: string[];
|
|
148
|
+
MoonPhaseNames: string[];
|
|
149
|
+
MoonPhaseShort: string[];
|
|
150
|
+
MoonDaySymbols: string[];
|
|
151
|
+
KhmerNumerals: Record<string, string>;
|
|
152
|
+
khNewYearMoments: Record<string, string>;
|
|
145
153
|
}
|
|
146
154
|
declare class KhmerDate {
|
|
147
155
|
day: number;
|
|
@@ -165,10 +173,13 @@ export declare const constants: {
|
|
|
165
173
|
LunarMonths: Record<string, number>;
|
|
166
174
|
LunarMonthNames: string[];
|
|
167
175
|
SolarMonthNames: string[];
|
|
176
|
+
SolarMonthAbbreviationNames: string[];
|
|
177
|
+
LunarMonthAbbreviationNames: string[];
|
|
168
178
|
AnimalYearNames: string[];
|
|
169
|
-
|
|
179
|
+
AnimalYearEmojis: string[];
|
|
180
|
+
SakNames: string[];
|
|
170
181
|
WeekdayNames: string[];
|
|
171
|
-
|
|
182
|
+
MoonPhaseNames: string[];
|
|
172
183
|
};
|
|
173
184
|
declare const _default: {
|
|
174
185
|
fromGregorian: typeof fromGregorian;
|
|
@@ -181,15 +192,18 @@ declare const _default: {
|
|
|
181
192
|
LunarMonths: Record<string, number>;
|
|
182
193
|
LunarMonthNames: string[];
|
|
183
194
|
SolarMonthNames: string[];
|
|
195
|
+
SolarMonthAbbreviationNames: string[];
|
|
196
|
+
LunarMonthAbbreviationNames: string[];
|
|
184
197
|
AnimalYearNames: string[];
|
|
185
|
-
|
|
198
|
+
AnimalYearEmojis: string[];
|
|
199
|
+
SakNames: string[];
|
|
186
200
|
WeekdayNames: string[];
|
|
187
|
-
|
|
201
|
+
MoonPhaseNames: string[];
|
|
188
202
|
};
|
|
189
203
|
MoonPhase: typeof MoonPhase;
|
|
190
204
|
MonthIndex: typeof MonthIndex;
|
|
191
205
|
AnimalYear: typeof AnimalYear;
|
|
192
|
-
|
|
206
|
+
Sak: typeof Sak;
|
|
193
207
|
DayOfWeek: typeof DayOfWeek;
|
|
194
208
|
};
|
|
195
209
|
export default _default;
|
package/dist/momentkh.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"momentkh.d.ts","sourceRoot":"","sources":["../momentkh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,oBAAY,SAAS;IACnB,MAAM,IAAI,CAAG,MAAM;IACnB,MAAM,IAAI;CACX;AAED,oBAAY,UAAU;IACpB,OAAO,IAAI,CAAO,SAAS;IAC3B,IAAI,IAAI,CAAW,QAAQ;IAC3B,IAAI,IAAI,CAAU,MAAM;IACxB,OAAO,IAAI,CAAO,SAAS;IAC3B,KAAK,IAAI,CAAS,QAAQ;IAC1B,MAAM,IAAI,CAAQ,QAAQ;IAC1B,KAAK,IAAI,CAAS,QAA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,MAAM,GAAG,WAAW;IASjD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS;IAoCjC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS;IAmCtC,QAAQ,IAAI,MAAM;CAGnB;AAgcD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAU,EAAE,MAAM,GAAE,MAAU,EAAE,MAAM,GAAE,MAAU,GAAG,qBAAqB,CAEvJ;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAEpI;AAGD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAEtD;AAGD,wBAAgB,MAAM,CAAC,SAAS,EAAE,qBAAqB,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,qBAAqB,CAW1D;AAGD,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAGxH;AAGD,eAAO,MAAM,SAAS;;;;;;;;;;;CAWrB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;AAGF,wBAaE"}
|
package/dist/momentkh.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @license MIT
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.constants = exports.DayOfWeek = exports.
|
|
16
|
+
exports.constants = exports.DayOfWeek = exports.Sak = exports.AnimalYear = exports.MonthIndex = exports.MoonPhase = void 0;
|
|
17
17
|
exports.fromGregorian = fromGregorian;
|
|
18
18
|
exports.fromKhmer = fromKhmer;
|
|
19
19
|
exports.getNewYear = getNewYear;
|
|
@@ -61,19 +61,19 @@ var AnimalYear;
|
|
|
61
61
|
AnimalYear[AnimalYear["Cho"] = 10] = "Cho";
|
|
62
62
|
AnimalYear[AnimalYear["Kor"] = 11] = "Kor"; // แแปแ - Pig
|
|
63
63
|
})(AnimalYear || (exports.AnimalYear = AnimalYear = {}));
|
|
64
|
-
var
|
|
65
|
-
(function (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
})(
|
|
64
|
+
var Sak;
|
|
65
|
+
(function (Sak) {
|
|
66
|
+
Sak[Sak["SamridhiSak"] = 0] = "SamridhiSak";
|
|
67
|
+
Sak[Sak["AekSak"] = 1] = "AekSak";
|
|
68
|
+
Sak[Sak["ToSak"] = 2] = "ToSak";
|
|
69
|
+
Sak[Sak["TreiSak"] = 3] = "TreiSak";
|
|
70
|
+
Sak[Sak["ChattvaSak"] = 4] = "ChattvaSak";
|
|
71
|
+
Sak[Sak["PanchaSak"] = 5] = "PanchaSak";
|
|
72
|
+
Sak[Sak["ChhaSak"] = 6] = "ChhaSak";
|
|
73
|
+
Sak[Sak["SappaSak"] = 7] = "SappaSak";
|
|
74
|
+
Sak[Sak["AtthaSak"] = 8] = "AtthaSak";
|
|
75
|
+
Sak[Sak["NappaSak"] = 9] = "NappaSak"; // แแแแแแแ
|
|
76
|
+
})(Sak || (exports.Sak = Sak = {}));
|
|
77
77
|
var DayOfWeek;
|
|
78
78
|
(function (DayOfWeek) {
|
|
79
79
|
DayOfWeek[DayOfWeek["Sunday"] = 0] = "Sunday";
|
|
@@ -102,11 +102,24 @@ const SolarMonthNames = [
|
|
|
102
102
|
'แแแแถ', 'แแปแแแแ', 'แแธแแถ', 'แแแแถ', 'แงแแแถ', 'แแทแแปแแถ',
|
|
103
103
|
'แแแแแแถ', 'แแธแ แถ', 'แแแแแถ', 'แแปแแถ', 'แแทแ
แแแทแแถ', 'แแแแผ'
|
|
104
104
|
];
|
|
105
|
+
const SolarMonthAbbreviationNames = [
|
|
106
|
+
'แแ', 'แแ', 'แแ', 'แแ', 'แงแ', 'แแ',
|
|
107
|
+
'แแ', 'แแ ', 'แแ', 'แแ', 'แแ', 'แแ'
|
|
108
|
+
];
|
|
109
|
+
const LunarMonthAbbreviationNames = [
|
|
110
|
+
'แแท', 'แแป', 'แแถ', 'แแ', 'แ
แ', 'แแท',
|
|
111
|
+
'แแ', 'แขแถ', 'แแแ', 'แ', 'แข', 'แ',
|
|
112
|
+
'แแ', 'แแปแแท'
|
|
113
|
+
];
|
|
105
114
|
const AnimalYearNames = [
|
|
106
115
|
'แแผแ', 'แแแแผแ', 'แแถแ', 'แแแ', 'แแแ', 'แแแแถแแ',
|
|
107
116
|
'แแแธ', 'แแแ', 'แแ', 'แแแถ', 'แ
', 'แแปแ'
|
|
108
117
|
];
|
|
109
|
-
const
|
|
118
|
+
const AnimalYearEmojis = [
|
|
119
|
+
'๐', '๐', '๐
', '๐', '๐', '๐',
|
|
120
|
+
'๐', '๐', '๐', '๐', '๐', '๐'
|
|
121
|
+
];
|
|
122
|
+
const SakNames = [
|
|
110
123
|
'แแแแนแแแแทแแแ', 'แฏแแแแ', 'แแแแแ', 'แแแแธแแแ', 'แ
แแแแถแแแ',
|
|
111
124
|
'แแแแ
แแแ', 'แแแแ', 'แแแแแแแ', 'แขแแแแแแ', 'แแแแแแแ'
|
|
112
125
|
];
|
|
@@ -114,8 +127,8 @@ const WeekdayNames = [
|
|
|
114
127
|
'แขแถแแทแแแ', 'แ
แแแ', 'แขแแแแถแ', 'แแปแ', 'แแแแ แแแแแทแ', 'แแปแแแ', 'แแ
แแ'
|
|
115
128
|
];
|
|
116
129
|
const WeekdayNamesShort = ['แขแถ', 'แ
', 'แข', 'แ', 'แแแ', 'แแป', 'แ'];
|
|
117
|
-
const
|
|
118
|
-
const
|
|
130
|
+
const MoonPhaseNames = ['แแพแ', 'แแแ
'];
|
|
131
|
+
const MoonPhaseShort = ['แ', 'แ'];
|
|
119
132
|
const MoonDaySymbols = [
|
|
120
133
|
'แงก', 'แงข', 'แงฃ', 'แงค', 'แงฅ', 'แงฆ', 'แงง', 'แงจ', 'แงฉ', 'แงช',
|
|
121
134
|
'แงซ', 'แงฌ', 'แงญ', 'แงฎ', 'แงฏ', 'แงฑ', 'แงฒ', 'แงณ', 'แงด', 'แงต',
|
|
@@ -655,7 +668,7 @@ class KhmerDate {
|
|
|
655
668
|
return result;
|
|
656
669
|
}
|
|
657
670
|
toString() {
|
|
658
|
-
return `${this.day}${
|
|
671
|
+
return `${this.day}${MoonPhaseNames[this.moonPhase]} แแ${LunarMonthNames[this.monthIndex]} แ.แ.${this.beYear}`;
|
|
659
672
|
}
|
|
660
673
|
}
|
|
661
674
|
// ============================================================================
|
|
@@ -806,7 +819,7 @@ function gregorianToKhmerInternal(year, month, day, hour = 0, minute = 0, second
|
|
|
806
819
|
jsYear++;
|
|
807
820
|
}
|
|
808
821
|
}
|
|
809
|
-
const
|
|
822
|
+
const sakIndex = ((jsYear % 10) + 10) % 10;
|
|
810
823
|
const dayOfWeek = getDayOfWeek(year, month, day);
|
|
811
824
|
const khmerDate = new KhmerDate(khmerDayInfo.day, khmerDayInfo.moonPhase, khmerMonth, beYear);
|
|
812
825
|
return {
|
|
@@ -814,15 +827,15 @@ function gregorianToKhmerInternal(year, month, day, hour = 0, minute = 0, second
|
|
|
814
827
|
khmer: {
|
|
815
828
|
day: khmerDayInfo.day,
|
|
816
829
|
moonPhase: khmerDayInfo.moonPhase,
|
|
817
|
-
moonPhaseName:
|
|
830
|
+
moonPhaseName: MoonPhaseNames[khmerDayInfo.moonPhase],
|
|
818
831
|
monthIndex: khmerMonth,
|
|
819
832
|
monthName: LunarMonthNames[khmerMonth],
|
|
820
833
|
beYear: beYear,
|
|
821
834
|
jsYear: jsYear,
|
|
822
835
|
animalYear: animalYearIndex,
|
|
823
836
|
animalYearName: AnimalYearNames[animalYearIndex],
|
|
824
|
-
|
|
825
|
-
|
|
837
|
+
sak: sakIndex,
|
|
838
|
+
sakName: SakNames[sakIndex],
|
|
826
839
|
dayOfWeek: dayOfWeek,
|
|
827
840
|
dayOfWeekName: WeekdayNames[dayOfWeek]
|
|
828
841
|
},
|
|
@@ -974,29 +987,42 @@ function formatKhmer(khmerData, formatString) {
|
|
|
974
987
|
// Default format
|
|
975
988
|
const { khmer } = khmerData;
|
|
976
989
|
const moonDay = `${khmer.day}${khmer.moonPhaseName}`;
|
|
977
|
-
return toKhmerNumeral(`แแแแ${khmer.dayOfWeekName} ${moonDay} แแ${khmer.monthName} แแแแถแ${khmer.animalYearName} ${khmer.
|
|
990
|
+
return toKhmerNumeral(`แแแแ${khmer.dayOfWeekName} ${moonDay} แแ${khmer.monthName} แแแแถแ${khmer.animalYearName} ${khmer.sakName} แแปแแแแแแแถแ ${khmer.beYear}`);
|
|
978
991
|
}
|
|
979
992
|
// Custom format
|
|
980
993
|
const formatRules = {
|
|
981
994
|
'W': () => khmerData.khmer.dayOfWeekName,
|
|
982
995
|
'w': () => WeekdayNamesShort[khmerData.gregorian.dayOfWeek],
|
|
983
|
-
'd': () => khmerData.khmer.day,
|
|
984
|
-
'D': () => (khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day,
|
|
985
|
-
'
|
|
996
|
+
'd': () => toKhmerNumeral(khmerData.khmer.day),
|
|
997
|
+
'D': () => toKhmerNumeral((khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day),
|
|
998
|
+
'dr': () => khmerData.khmer.day,
|
|
999
|
+
'Dr': () => (khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day,
|
|
1000
|
+
'n': () => MoonPhaseShort[khmerData.khmer.moonPhase],
|
|
986
1001
|
'N': () => khmerData.khmer.moonPhaseName,
|
|
987
1002
|
'o': () => MoonDaySymbols[khmerData._khmerDateObj.getDayNumber()],
|
|
988
1003
|
'm': () => khmerData.khmer.monthName,
|
|
989
1004
|
'M': () => SolarMonthNames[khmerData.gregorian.month - 1],
|
|
990
1005
|
'a': () => khmerData.khmer.animalYearName,
|
|
991
|
-
'
|
|
992
|
-
'
|
|
993
|
-
'
|
|
994
|
-
'
|
|
1006
|
+
'as': () => AnimalYearEmojis[khmerData.khmer.animalYear],
|
|
1007
|
+
'e': () => khmerData.khmer.sakName,
|
|
1008
|
+
'b': () => toKhmerNumeral(khmerData.khmer.beYear),
|
|
1009
|
+
'br': () => khmerData.khmer.beYear,
|
|
1010
|
+
'c': () => toKhmerNumeral(khmerData.gregorian.year),
|
|
1011
|
+
'cr': () => khmerData.gregorian.year,
|
|
1012
|
+
'j': () => toKhmerNumeral(khmerData.khmer.jsYear),
|
|
1013
|
+
'jr': () => khmerData.khmer.jsYear,
|
|
1014
|
+
'Ms': () => SolarMonthAbbreviationNames[khmerData.gregorian.month - 1],
|
|
1015
|
+
'ms': () => LunarMonthAbbreviationNames[khmerData.khmer.monthIndex]
|
|
995
1016
|
};
|
|
996
|
-
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1017
|
+
// Sort keys by length descending to ensure longer tokens (like 'Ms', 'ms') are matched before shorter ones (like 'M', 'm')
|
|
1018
|
+
const sortedKeys = Object.keys(formatRules).sort((a, b) => b.length - a.length);
|
|
1019
|
+
const regex = new RegExp(`\\[([^\\]]+)\\]|(${sortedKeys.join('|')})`, 'g');
|
|
1020
|
+
const result = formatString.replace(regex, (match, escaped, token) => {
|
|
1021
|
+
if (escaped) {
|
|
1022
|
+
return escaped;
|
|
1023
|
+
}
|
|
1024
|
+
const value = formatRules[token]();
|
|
1025
|
+
return String(value);
|
|
1000
1026
|
});
|
|
1001
1027
|
return result;
|
|
1002
1028
|
}
|
|
@@ -1041,10 +1067,13 @@ exports.constants = {
|
|
|
1041
1067
|
LunarMonths,
|
|
1042
1068
|
LunarMonthNames,
|
|
1043
1069
|
SolarMonthNames,
|
|
1070
|
+
SolarMonthAbbreviationNames,
|
|
1071
|
+
LunarMonthAbbreviationNames,
|
|
1044
1072
|
AnimalYearNames,
|
|
1045
|
-
|
|
1073
|
+
AnimalYearEmojis,
|
|
1074
|
+
SakNames,
|
|
1046
1075
|
WeekdayNames,
|
|
1047
|
-
|
|
1076
|
+
MoonPhaseNames
|
|
1048
1077
|
};
|
|
1049
1078
|
// Default export - aggregate all exports for convenience
|
|
1050
1079
|
exports.default = {
|
|
@@ -1058,6 +1087,6 @@ exports.default = {
|
|
|
1058
1087
|
MoonPhase,
|
|
1059
1088
|
MonthIndex,
|
|
1060
1089
|
AnimalYear,
|
|
1061
|
-
|
|
1090
|
+
Sak,
|
|
1062
1091
|
DayOfWeek
|
|
1063
1092
|
};
|
package/momentkh.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
root.MoonPhase = exp.MoonPhase;
|
|
13
13
|
root.MonthIndex = exp.MonthIndex;
|
|
14
14
|
root.AnimalYear = exp.AnimalYear;
|
|
15
|
-
root.
|
|
15
|
+
root.AnimalYearEmojis = exp.AnimalYearEmojis;
|
|
16
|
+
root.Sak = exp.Sak;
|
|
16
17
|
root.DayOfWeek = exp.DayOfWeek;
|
|
17
18
|
}
|
|
18
19
|
}(typeof self !== 'undefined' ? self : this, function () {
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
* @license MIT
|
|
36
37
|
*/
|
|
37
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.constants = exports.DayOfWeek = exports.
|
|
39
|
+
exports.constants = exports.DayOfWeek = exports.Sak = exports.AnimalYear = exports.MonthIndex = exports.MoonPhase = void 0;
|
|
39
40
|
exports.fromGregorian = fromGregorian;
|
|
40
41
|
exports.fromKhmer = fromKhmer;
|
|
41
42
|
exports.getNewYear = getNewYear;
|
|
@@ -83,19 +84,19 @@ var AnimalYear;
|
|
|
83
84
|
AnimalYear[AnimalYear["Cho"] = 10] = "Cho";
|
|
84
85
|
AnimalYear[AnimalYear["Kor"] = 11] = "Kor"; // แแปแ - Pig
|
|
85
86
|
})(AnimalYear || (exports.AnimalYear = AnimalYear = {}));
|
|
86
|
-
var
|
|
87
|
-
(function (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})(
|
|
87
|
+
var Sak;
|
|
88
|
+
(function (Sak) {
|
|
89
|
+
Sak[Sak["SamridhiSak"] = 0] = "SamridhiSak";
|
|
90
|
+
Sak[Sak["AekSak"] = 1] = "AekSak";
|
|
91
|
+
Sak[Sak["ToSak"] = 2] = "ToSak";
|
|
92
|
+
Sak[Sak["TreiSak"] = 3] = "TreiSak";
|
|
93
|
+
Sak[Sak["ChattvaSak"] = 4] = "ChattvaSak";
|
|
94
|
+
Sak[Sak["PanchaSak"] = 5] = "PanchaSak";
|
|
95
|
+
Sak[Sak["ChhaSak"] = 6] = "ChhaSak";
|
|
96
|
+
Sak[Sak["SappaSak"] = 7] = "SappaSak";
|
|
97
|
+
Sak[Sak["AtthaSak"] = 8] = "AtthaSak";
|
|
98
|
+
Sak[Sak["NappaSak"] = 9] = "NappaSak"; // แแแแแแแ
|
|
99
|
+
})(Sak || (exports.Sak = Sak = {}));
|
|
99
100
|
var DayOfWeek;
|
|
100
101
|
(function (DayOfWeek) {
|
|
101
102
|
DayOfWeek[DayOfWeek["Sunday"] = 0] = "Sunday";
|
|
@@ -124,11 +125,24 @@ const SolarMonthNames = [
|
|
|
124
125
|
'แแแแถ', 'แแปแแแแ', 'แแธแแถ', 'แแแแถ', 'แงแแแถ', 'แแทแแปแแถ',
|
|
125
126
|
'แแแแแแถ', 'แแธแ แถ', 'แแแแแถ', 'แแปแแถ', 'แแทแ
แแแทแแถ', 'แแแแผ'
|
|
126
127
|
];
|
|
128
|
+
const SolarMonthAbbreviationNames = [
|
|
129
|
+
'แแ', 'แแ', 'แแ', 'แแ', 'แงแ', 'แแ',
|
|
130
|
+
'แแ', 'แแ ', 'แแ', 'แแ', 'แแ', 'แแ'
|
|
131
|
+
];
|
|
132
|
+
const LunarMonthAbbreviationNames = [
|
|
133
|
+
'แแท', 'แแป', 'แแถ', 'แแ', 'แ
แ', 'แแท',
|
|
134
|
+
'แแ', 'แขแถ', 'แแแ', 'แ', 'แข', 'แ',
|
|
135
|
+
'แแ', 'แแปแแท'
|
|
136
|
+
];
|
|
127
137
|
const AnimalYearNames = [
|
|
128
138
|
'แแผแ', 'แแแแผแ', 'แแถแ', 'แแแ', 'แแแ', 'แแแแถแแ',
|
|
129
139
|
'แแแธ', 'แแแ', 'แแ', 'แแแถ', 'แ
', 'แแปแ'
|
|
130
140
|
];
|
|
131
|
-
const
|
|
141
|
+
const AnimalYearEmojis = [
|
|
142
|
+
'๐', '๐', '๐
', '๐', '๐', '๐',
|
|
143
|
+
'๐', '๐', '๐', '๐', '๐', '๐'
|
|
144
|
+
];
|
|
145
|
+
const SakNames = [
|
|
132
146
|
'แแแแนแแแแทแแแ', 'แฏแแแแ', 'แแแแแ', 'แแแแธแแแ', 'แ
แแแแถแแแ',
|
|
133
147
|
'แแแแ
แแแ', 'แแแแ', 'แแแแแแแ', 'แขแแแแแแ', 'แแแแแแแ'
|
|
134
148
|
];
|
|
@@ -136,8 +150,8 @@ const WeekdayNames = [
|
|
|
136
150
|
'แขแถแแทแแแ', 'แ
แแแ', 'แขแแแแถแ', 'แแปแ', 'แแแแ แแแแแทแ', 'แแปแแแ', 'แแ
แแ'
|
|
137
151
|
];
|
|
138
152
|
const WeekdayNamesShort = ['แขแถ', 'แ
', 'แข', 'แ', 'แแแ', 'แแป', 'แ'];
|
|
139
|
-
const
|
|
140
|
-
const
|
|
153
|
+
const MoonPhaseNames = ['แแพแ', 'แแแ
'];
|
|
154
|
+
const MoonPhaseShort = ['แ', 'แ'];
|
|
141
155
|
const MoonDaySymbols = [
|
|
142
156
|
'แงก', 'แงข', 'แงฃ', 'แงค', 'แงฅ', 'แงฆ', 'แงง', 'แงจ', 'แงฉ', 'แงช',
|
|
143
157
|
'แงซ', 'แงฌ', 'แงญ', 'แงฎ', 'แงฏ', 'แงฑ', 'แงฒ', 'แงณ', 'แงด', 'แงต',
|
|
@@ -677,7 +691,7 @@ class KhmerDate {
|
|
|
677
691
|
return result;
|
|
678
692
|
}
|
|
679
693
|
toString() {
|
|
680
|
-
return `${this.day}${
|
|
694
|
+
return `${this.day}${MoonPhaseNames[this.moonPhase]} แแ${LunarMonthNames[this.monthIndex]} แ.แ.${this.beYear}`;
|
|
681
695
|
}
|
|
682
696
|
}
|
|
683
697
|
// ============================================================================
|
|
@@ -828,7 +842,7 @@ function gregorianToKhmerInternal(year, month, day, hour = 0, minute = 0, second
|
|
|
828
842
|
jsYear++;
|
|
829
843
|
}
|
|
830
844
|
}
|
|
831
|
-
const
|
|
845
|
+
const sakIndex = ((jsYear % 10) + 10) % 10;
|
|
832
846
|
const dayOfWeek = getDayOfWeek(year, month, day);
|
|
833
847
|
const khmerDate = new KhmerDate(khmerDayInfo.day, khmerDayInfo.moonPhase, khmerMonth, beYear);
|
|
834
848
|
return {
|
|
@@ -836,15 +850,15 @@ function gregorianToKhmerInternal(year, month, day, hour = 0, minute = 0, second
|
|
|
836
850
|
khmer: {
|
|
837
851
|
day: khmerDayInfo.day,
|
|
838
852
|
moonPhase: khmerDayInfo.moonPhase,
|
|
839
|
-
moonPhaseName:
|
|
853
|
+
moonPhaseName: MoonPhaseNames[khmerDayInfo.moonPhase],
|
|
840
854
|
monthIndex: khmerMonth,
|
|
841
855
|
monthName: LunarMonthNames[khmerMonth],
|
|
842
856
|
beYear: beYear,
|
|
843
857
|
jsYear: jsYear,
|
|
844
858
|
animalYear: animalYearIndex,
|
|
845
859
|
animalYearName: AnimalYearNames[animalYearIndex],
|
|
846
|
-
|
|
847
|
-
|
|
860
|
+
sak: sakIndex,
|
|
861
|
+
sakName: SakNames[sakIndex],
|
|
848
862
|
dayOfWeek: dayOfWeek,
|
|
849
863
|
dayOfWeekName: WeekdayNames[dayOfWeek]
|
|
850
864
|
},
|
|
@@ -996,29 +1010,42 @@ function formatKhmer(khmerData, formatString) {
|
|
|
996
1010
|
// Default format
|
|
997
1011
|
const { khmer } = khmerData;
|
|
998
1012
|
const moonDay = `${khmer.day}${khmer.moonPhaseName}`;
|
|
999
|
-
return toKhmerNumeral(`แแแแ${khmer.dayOfWeekName} ${moonDay} แแ${khmer.monthName} แแแแถแ${khmer.animalYearName} ${khmer.
|
|
1013
|
+
return toKhmerNumeral(`แแแแ${khmer.dayOfWeekName} ${moonDay} แแ${khmer.monthName} แแแแถแ${khmer.animalYearName} ${khmer.sakName} แแปแแแแแแแถแ ${khmer.beYear}`);
|
|
1000
1014
|
}
|
|
1001
1015
|
// Custom format
|
|
1002
1016
|
const formatRules = {
|
|
1003
1017
|
'W': () => khmerData.khmer.dayOfWeekName,
|
|
1004
1018
|
'w': () => WeekdayNamesShort[khmerData.gregorian.dayOfWeek],
|
|
1005
|
-
'd': () => khmerData.khmer.day,
|
|
1006
|
-
'D': () => (khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day,
|
|
1007
|
-
'
|
|
1019
|
+
'd': () => toKhmerNumeral(khmerData.khmer.day),
|
|
1020
|
+
'D': () => toKhmerNumeral((khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day),
|
|
1021
|
+
'dr': () => khmerData.khmer.day,
|
|
1022
|
+
'Dr': () => (khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day,
|
|
1023
|
+
'n': () => MoonPhaseShort[khmerData.khmer.moonPhase],
|
|
1008
1024
|
'N': () => khmerData.khmer.moonPhaseName,
|
|
1009
1025
|
'o': () => MoonDaySymbols[khmerData._khmerDateObj.getDayNumber()],
|
|
1010
1026
|
'm': () => khmerData.khmer.monthName,
|
|
1011
1027
|
'M': () => SolarMonthNames[khmerData.gregorian.month - 1],
|
|
1012
1028
|
'a': () => khmerData.khmer.animalYearName,
|
|
1013
|
-
'
|
|
1014
|
-
'
|
|
1015
|
-
'
|
|
1016
|
-
'
|
|
1029
|
+
'as': () => AnimalYearEmojis[khmerData.khmer.animalYear],
|
|
1030
|
+
'e': () => khmerData.khmer.sakName,
|
|
1031
|
+
'b': () => toKhmerNumeral(khmerData.khmer.beYear),
|
|
1032
|
+
'br': () => khmerData.khmer.beYear,
|
|
1033
|
+
'c': () => toKhmerNumeral(khmerData.gregorian.year),
|
|
1034
|
+
'cr': () => khmerData.gregorian.year,
|
|
1035
|
+
'j': () => toKhmerNumeral(khmerData.khmer.jsYear),
|
|
1036
|
+
'jr': () => khmerData.khmer.jsYear,
|
|
1037
|
+
'Ms': () => SolarMonthAbbreviationNames[khmerData.gregorian.month - 1],
|
|
1038
|
+
'ms': () => LunarMonthAbbreviationNames[khmerData.khmer.monthIndex]
|
|
1017
1039
|
};
|
|
1018
|
-
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1040
|
+
// Sort keys by length descending to ensure longer tokens (like 'Ms', 'ms') are matched before shorter ones (like 'M', 'm')
|
|
1041
|
+
const sortedKeys = Object.keys(formatRules).sort((a, b) => b.length - a.length);
|
|
1042
|
+
const regex = new RegExp(`\\[([^\\]]+)\\]|(${sortedKeys.join('|')})`, 'g');
|
|
1043
|
+
const result = formatString.replace(regex, (match, escaped, token) => {
|
|
1044
|
+
if (escaped) {
|
|
1045
|
+
return escaped;
|
|
1046
|
+
}
|
|
1047
|
+
const value = formatRules[token]();
|
|
1048
|
+
return String(value);
|
|
1022
1049
|
});
|
|
1023
1050
|
return result;
|
|
1024
1051
|
}
|
|
@@ -1063,10 +1090,13 @@ exports.constants = {
|
|
|
1063
1090
|
LunarMonths,
|
|
1064
1091
|
LunarMonthNames,
|
|
1065
1092
|
SolarMonthNames,
|
|
1093
|
+
SolarMonthAbbreviationNames,
|
|
1094
|
+
LunarMonthAbbreviationNames,
|
|
1066
1095
|
AnimalYearNames,
|
|
1067
|
-
|
|
1096
|
+
AnimalYearEmojis,
|
|
1097
|
+
SakNames,
|
|
1068
1098
|
WeekdayNames,
|
|
1069
|
-
|
|
1099
|
+
MoonPhaseNames
|
|
1070
1100
|
};
|
|
1071
1101
|
// Default export - aggregate all exports for convenience
|
|
1072
1102
|
exports.default = {
|
|
@@ -1080,7 +1110,7 @@ exports.default = {
|
|
|
1080
1110
|
MoonPhase,
|
|
1081
1111
|
MonthIndex,
|
|
1082
1112
|
AnimalYear,
|
|
1083
|
-
|
|
1113
|
+
Sak,
|
|
1084
1114
|
DayOfWeek
|
|
1085
1115
|
};
|
|
1086
1116
|
|
package/momentkh.ts
CHANGED
|
@@ -55,7 +55,7 @@ export enum AnimalYear {
|
|
|
55
55
|
Kor = 11 // แแปแ - Pig
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export enum
|
|
58
|
+
export enum Sak {
|
|
59
59
|
SamridhiSak = 0, // แแแแนแแแแทแแแ
|
|
60
60
|
AekSak = 1, // แฏแแแแ
|
|
61
61
|
ToSak = 2, // แแแแแ
|
|
@@ -94,12 +94,12 @@ export interface KhmerDateInfo {
|
|
|
94
94
|
moonPhaseName: string; // String name: "แแพแ" or "แแแ
"
|
|
95
95
|
monthIndex: MonthIndex; // Enum: MonthIndex (0-13)
|
|
96
96
|
monthName: string; // String name of the month
|
|
97
|
-
beYear: number; // Buddhist
|
|
97
|
+
beYear: number; // Buddhist Sak
|
|
98
98
|
jsYear: number; // Jolak Sakaraj year
|
|
99
99
|
animalYear: AnimalYear; // Enum: AnimalYear (0-11)
|
|
100
100
|
animalYearName: string; // String name of animal year
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
sak: Sak; // Enum: Sak (0-9)
|
|
102
|
+
sakName: string; // String name of Sak
|
|
103
103
|
dayOfWeek: DayOfWeek; // Enum: DayOfWeek (0-6)
|
|
104
104
|
dayOfWeekName: string; // String name of day of week
|
|
105
105
|
}
|
|
@@ -159,10 +159,18 @@ export interface Constants {
|
|
|
159
159
|
LunarMonths: Record<string, number>;
|
|
160
160
|
LunarMonthNames: string[];
|
|
161
161
|
SolarMonthNames: string[];
|
|
162
|
+
SolarMonthAbbreviationNames: string[];
|
|
163
|
+
LunarMonthAbbreviationNames: string[];
|
|
162
164
|
AnimalYearNames: string[];
|
|
163
|
-
|
|
165
|
+
AnimalYearEmojis: string[];
|
|
166
|
+
SakNames: string[];
|
|
164
167
|
WeekdayNames: string[];
|
|
165
|
-
|
|
168
|
+
WeekdayNamesShort: string[];
|
|
169
|
+
MoonPhaseNames: string[];
|
|
170
|
+
MoonPhaseShort: string[];
|
|
171
|
+
MoonDaySymbols: string[];
|
|
172
|
+
KhmerNumerals: Record<string, string>;
|
|
173
|
+
khNewYearMoments: Record<string, string>;
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
// ============================================================================
|
|
@@ -187,12 +195,28 @@ const SolarMonthNames: string[] = [
|
|
|
187
195
|
'แแแแแแถ', 'แแธแ แถ', 'แแแแแถ', 'แแปแแถ', 'แแทแ
แแแทแแถ', 'แแแแผ'
|
|
188
196
|
];
|
|
189
197
|
|
|
198
|
+
const SolarMonthAbbreviationNames: string[] = [
|
|
199
|
+
'แแ', 'แแ', 'แแ', 'แแ', 'แงแ', 'แแ',
|
|
200
|
+
'แแ', 'แแ ', 'แแ', 'แแ', 'แแ', 'แแ'
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const LunarMonthAbbreviationNames: string[] = [
|
|
204
|
+
'แแท', 'แแป', 'แแถ', 'แแ', 'แ
แ', 'แแท',
|
|
205
|
+
'แแ', 'แขแถ', 'แแแ', 'แ', 'แข', 'แ',
|
|
206
|
+
'แแ', 'แแปแแท'
|
|
207
|
+
];
|
|
208
|
+
|
|
190
209
|
const AnimalYearNames: string[] = [
|
|
191
210
|
'แแผแ', 'แแแแผแ', 'แแถแ', 'แแแ', 'แแแ', 'แแแแถแแ',
|
|
192
211
|
'แแแธ', 'แแแ', 'แแ', 'แแแถ', 'แ
', 'แแปแ'
|
|
193
212
|
];
|
|
194
213
|
|
|
195
|
-
const
|
|
214
|
+
const AnimalYearEmojis: string[] = [
|
|
215
|
+
'๐', '๐', '๐
', '๐', '๐', '๐',
|
|
216
|
+
'๐', '๐', '๐', '๐', '๐', '๐'
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
const SakNames: string[] = [
|
|
196
220
|
'แแแแนแแแแทแแแ', 'แฏแแแแ', 'แแแแแ', 'แแแแธแแแ', 'แ
แแแแถแแแ',
|
|
197
221
|
'แแแแ
แแแ', 'แแแแ', 'แแแแแแแ', 'แขแแแแแแ', 'แแแแแแแ'
|
|
198
222
|
];
|
|
@@ -203,8 +227,8 @@ const WeekdayNames: string[] = [
|
|
|
203
227
|
|
|
204
228
|
const WeekdayNamesShort: string[] = ['แขแถ', 'แ
', 'แข', 'แ', 'แแแ', 'แแป', 'แ'];
|
|
205
229
|
|
|
206
|
-
const
|
|
207
|
-
const
|
|
230
|
+
const MoonPhaseNames: string[] = ['แแพแ', 'แแแ
'];
|
|
231
|
+
const MoonPhaseShort: string[] = ['แ', 'แ'];
|
|
208
232
|
|
|
209
233
|
const MoonDaySymbols: string[] = [
|
|
210
234
|
'แงก', 'แงข', 'แงฃ', 'แงค', 'แงฅ', 'แงฆ', 'แงง', 'แงจ', 'แงฉ', 'แงช',
|
|
@@ -839,7 +863,7 @@ class KhmerDate {
|
|
|
839
863
|
}
|
|
840
864
|
|
|
841
865
|
toString(): string {
|
|
842
|
-
return `${this.day}${
|
|
866
|
+
return `${this.day}${MoonPhaseNames[this.moonPhase]} แแ${LunarMonthNames[this.monthIndex]} แ.แ.${this.beYear}`;
|
|
843
867
|
}
|
|
844
868
|
}
|
|
845
869
|
|
|
@@ -1017,7 +1041,7 @@ function gregorianToKhmerInternal(
|
|
|
1017
1041
|
}
|
|
1018
1042
|
}
|
|
1019
1043
|
|
|
1020
|
-
const
|
|
1044
|
+
const sakIndex = ((jsYear % 10) + 10) % 10;
|
|
1021
1045
|
const dayOfWeek = getDayOfWeek(year, month, day);
|
|
1022
1046
|
|
|
1023
1047
|
const khmerDate = new KhmerDate(khmerDayInfo.day, khmerDayInfo.moonPhase, khmerMonth as MonthIndex, beYear);
|
|
@@ -1027,15 +1051,15 @@ function gregorianToKhmerInternal(
|
|
|
1027
1051
|
khmer: {
|
|
1028
1052
|
day: khmerDayInfo.day,
|
|
1029
1053
|
moonPhase: khmerDayInfo.moonPhase,
|
|
1030
|
-
moonPhaseName:
|
|
1054
|
+
moonPhaseName: MoonPhaseNames[khmerDayInfo.moonPhase],
|
|
1031
1055
|
monthIndex: khmerMonth as MonthIndex,
|
|
1032
1056
|
monthName: LunarMonthNames[khmerMonth],
|
|
1033
1057
|
beYear: beYear,
|
|
1034
1058
|
jsYear: jsYear,
|
|
1035
1059
|
animalYear: animalYearIndex as AnimalYear,
|
|
1036
1060
|
animalYearName: AnimalYearNames[animalYearIndex],
|
|
1037
|
-
|
|
1038
|
-
|
|
1061
|
+
sak: sakIndex as Sak,
|
|
1062
|
+
sakName: SakNames[sakIndex],
|
|
1039
1063
|
dayOfWeek: dayOfWeek as DayOfWeek,
|
|
1040
1064
|
dayOfWeekName: WeekdayNames[dayOfWeek]
|
|
1041
1065
|
},
|
|
@@ -1231,7 +1255,7 @@ function formatKhmer(khmerData: KhmerConversionResult, formatString?: string): s
|
|
|
1231
1255
|
const { khmer } = khmerData;
|
|
1232
1256
|
const moonDay = `${khmer.day}${khmer.moonPhaseName}`;
|
|
1233
1257
|
return toKhmerNumeral(
|
|
1234
|
-
`แแแแ${khmer.dayOfWeekName} ${moonDay} แแ${khmer.monthName} แแแแถแ${khmer.animalYearName} ${khmer.
|
|
1258
|
+
`แแแแ${khmer.dayOfWeekName} ${moonDay} แแ${khmer.monthName} แแแแถแ${khmer.animalYearName} ${khmer.sakName} แแปแแแแแแแถแ ${khmer.beYear}`
|
|
1235
1259
|
);
|
|
1236
1260
|
}
|
|
1237
1261
|
|
|
@@ -1239,24 +1263,38 @@ function formatKhmer(khmerData: KhmerConversionResult, formatString?: string): s
|
|
|
1239
1263
|
const formatRules: Record<string, () => string | number> = {
|
|
1240
1264
|
'W': () => khmerData.khmer.dayOfWeekName,
|
|
1241
1265
|
'w': () => WeekdayNamesShort[khmerData.gregorian.dayOfWeek],
|
|
1242
|
-
'd': () => khmerData.khmer.day,
|
|
1243
|
-
'D': () => (khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day,
|
|
1244
|
-
'
|
|
1266
|
+
'd': () => toKhmerNumeral(khmerData.khmer.day),
|
|
1267
|
+
'D': () => toKhmerNumeral((khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day),
|
|
1268
|
+
'dr': () => khmerData.khmer.day,
|
|
1269
|
+
'Dr': () => (khmerData.khmer.day < 10 ? '0' : '') + khmerData.khmer.day,
|
|
1270
|
+
'n': () => MoonPhaseShort[khmerData.khmer.moonPhase],
|
|
1245
1271
|
'N': () => khmerData.khmer.moonPhaseName,
|
|
1246
1272
|
'o': () => MoonDaySymbols[khmerData._khmerDateObj.getDayNumber()],
|
|
1247
1273
|
'm': () => khmerData.khmer.monthName,
|
|
1248
1274
|
'M': () => SolarMonthNames[khmerData.gregorian.month - 1],
|
|
1249
1275
|
'a': () => khmerData.khmer.animalYearName,
|
|
1250
|
-
'
|
|
1251
|
-
'
|
|
1252
|
-
'
|
|
1253
|
-
'
|
|
1276
|
+
'as': () => AnimalYearEmojis[khmerData.khmer.animalYear],
|
|
1277
|
+
'e': () => khmerData.khmer.sakName,
|
|
1278
|
+
'b': () => toKhmerNumeral(khmerData.khmer.beYear),
|
|
1279
|
+
'br': () => khmerData.khmer.beYear,
|
|
1280
|
+
'c': () => toKhmerNumeral(khmerData.gregorian.year),
|
|
1281
|
+
'cr': () => khmerData.gregorian.year,
|
|
1282
|
+
'j': () => toKhmerNumeral(khmerData.khmer.jsYear),
|
|
1283
|
+
'jr': () => khmerData.khmer.jsYear,
|
|
1284
|
+
'Ms': () => SolarMonthAbbreviationNames[khmerData.gregorian.month - 1],
|
|
1285
|
+
'ms': () => LunarMonthAbbreviationNames[khmerData.khmer.monthIndex]
|
|
1254
1286
|
};
|
|
1255
1287
|
|
|
1256
|
-
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1288
|
+
// Sort keys by length descending to ensure longer tokens (like 'Ms', 'ms') are matched before shorter ones (like 'M', 'm')
|
|
1289
|
+
const sortedKeys = Object.keys(formatRules).sort((a, b) => b.length - a.length);
|
|
1290
|
+
const regex = new RegExp(`\\[([^\\]]+)\\]|(${sortedKeys.join('|')})`, 'g');
|
|
1291
|
+
|
|
1292
|
+
const result = formatString.replace(regex, (match, escaped, token) => {
|
|
1293
|
+
if (escaped) {
|
|
1294
|
+
return escaped;
|
|
1295
|
+
}
|
|
1296
|
+
const value = formatRules[token]();
|
|
1297
|
+
return String(value);
|
|
1260
1298
|
});
|
|
1261
1299
|
|
|
1262
1300
|
return result;
|
|
@@ -1292,7 +1330,6 @@ export function getNewYear(ceYear: number): NewYearInfo {
|
|
|
1292
1330
|
export function format(khmerData: KhmerConversionResult, formatString?: string): string {
|
|
1293
1331
|
return formatKhmer(khmerData, formatString);
|
|
1294
1332
|
}
|
|
1295
|
-
|
|
1296
1333
|
// Utility for creating date from Date object
|
|
1297
1334
|
export function fromDate(date: Date): KhmerConversionResult {
|
|
1298
1335
|
// Validate Date object
|
|
@@ -1318,10 +1355,13 @@ export const constants = {
|
|
|
1318
1355
|
LunarMonths,
|
|
1319
1356
|
LunarMonthNames,
|
|
1320
1357
|
SolarMonthNames,
|
|
1358
|
+
SolarMonthAbbreviationNames,
|
|
1359
|
+
LunarMonthAbbreviationNames,
|
|
1321
1360
|
AnimalYearNames,
|
|
1322
|
-
|
|
1361
|
+
AnimalYearEmojis,
|
|
1362
|
+
SakNames,
|
|
1323
1363
|
WeekdayNames,
|
|
1324
|
-
|
|
1364
|
+
MoonPhaseNames
|
|
1325
1365
|
};
|
|
1326
1366
|
|
|
1327
1367
|
// Default export - aggregate all exports for convenience
|
|
@@ -1336,6 +1376,6 @@ export default {
|
|
|
1336
1376
|
MoonPhase,
|
|
1337
1377
|
MonthIndex,
|
|
1338
1378
|
AnimalYear,
|
|
1339
|
-
|
|
1379
|
+
Sak,
|
|
1340
1380
|
DayOfWeek
|
|
1341
1381
|
};
|