@thyrith/momentkh 3.0.1 โ 3.0.3
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 +125 -87
- package/dist/momentkh.d.ts +24 -10
- package/dist/momentkh.d.ts.map +1 -1
- package/dist/momentkh.js +70 -37
- package/momentkh.js +72 -38
- package/momentkh.ts +74 -30
- package/package.json +3 -4
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
|
|
|
@@ -19,12 +21,19 @@ const khmer = momentkh.fromDate(new Date());
|
|
|
19
21
|
console.log(momentkh.format(khmer));
|
|
20
22
|
// Output: แแแแแแปแ แกแขแแแ
แแแแทแแแทแ แแแแถแแแแแถแแ แแแแแแแ แแปแแแแแแแถแ แขแฅแฆแฉ
|
|
21
23
|
|
|
24
|
+
// Convert from gregorian data (แแแแแแปแแทแแแแท) to Khmer format
|
|
25
|
+
const date = momentkh.fromGregorian(2025, 12, 10); // แแแแแแธแกแ แแแแแแผ แแแแถแแขแ แขแฅ
|
|
26
|
+
// or
|
|
27
|
+
// const khmer = momentkh.fromGregorian(2025, 12, 10, 0, 0, 0); // (year, month, day, hour = 0, minute = 0, second = 0)
|
|
28
|
+
console.log(momentkh.format(date));
|
|
29
|
+
// Output: แแแแแแปแ แฅแแแ
แแแแทแแแทแ แแแแถแแแแแถแแ แแแแแแแ แแปแแแแแแแถแ แขแฅแฆแฉ
|
|
30
|
+
|
|
22
31
|
// Convert date to Khmer format (custom)
|
|
23
|
-
console.log(momentkh.format(
|
|
24
|
-
// Output:
|
|
32
|
+
console.log(momentkh.format(date, "แแแแถแแถแแแถแแแแแธแแแแผแแแถแแ
แแแแแแแถแแแแแแแแถแแแถแแแแแแปแ แแ
แแแแW แแธdsr แแM แแแแถแcr แแแแผแแแนแ แแแแแแธDN แแm แแแแถแa e แแปแแแแแแแถแ bแ"));
|
|
33
|
+
// Output: แแแแถแแถแแแถแแแแแธแแแแผแแแถแแ
แแแแแแแถแแแแแแแแถแแแถแแแแแแปแ แแ
แแแแแแปแ แแธ10 แแแแแแผ แแแแถแ2025 แแแแผแแแนแ แแแแแแธแ แฅแแแ
แแแแทแแแทแ แแแแถแแแแแถแแ แแแแแแแ แแปแแแแแแแถแ แขแฅแฆแฉแ
|
|
25
34
|
|
|
26
35
|
// Convert Khmer date to Gregorian
|
|
27
|
-
const gregorian = momentkh.fromKhmer(15,
|
|
36
|
+
const gregorian = momentkh.fromKhmer(15, momentkh.MoonPhase.Waxing, momentkh.MonthIndex.Pisakh, 2568); // 15แแพแ แแแแทแแถแ แ.แ.แขแฅแฆแจ
|
|
28
37
|
console.log(gregorian);
|
|
29
38
|
// Output: { year: 2025, month: 5, day: 11 }
|
|
30
39
|
|
|
@@ -52,7 +61,7 @@ console.log(newYear);
|
|
|
52
61
|
- [Understanding Khmer Calendar](#-understanding-khmer-calendar)
|
|
53
62
|
- [Buddhist Era (BE) Year](#buddhist-era-be-year)
|
|
54
63
|
- [Animal Year](#animal-year)
|
|
55
|
-
- [
|
|
64
|
+
- [Sak](#sak-year-sak)
|
|
56
65
|
- [When Each Year Type Increases](#when-each-year-type-increases)
|
|
57
66
|
- [Format Codes](#-format-codes)
|
|
58
67
|
- [Constants](#-constants)
|
|
@@ -66,7 +75,7 @@ console.log(newYear);
|
|
|
66
75
|
|
|
67
76
|
- โ
**Zero Dependencies** - Pure JavaScript, no external libraries required
|
|
68
77
|
- โ
**TypeScript Support** - Full type definitions included for excellent IDE experience
|
|
69
|
-
- โ
**Type-Safe Enums** - NEW in v3.0! Use enums for moonPhase, monthIndex, animalYear,
|
|
78
|
+
- โ
**Type-Safe Enums** - NEW in v3.0! Use enums for moonPhase, monthIndex, animalYear, sak, and dayOfWeek
|
|
70
79
|
- โ
**Bidirectional Conversion** - Convert between Gregorian โ Khmer Lunar dates
|
|
71
80
|
- โ
**Accurate Calculations** - Based on traditional Khmer astronomical algorithms
|
|
72
81
|
- โ
**Khmer New Year** - Precise calculation of Moha Songkran timing
|
|
@@ -85,14 +94,6 @@ console.log(newYear);
|
|
|
85
94
|
npm install @thyrith/momentkh
|
|
86
95
|
```
|
|
87
96
|
|
|
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
97
|
### TypeScript
|
|
97
98
|
|
|
98
99
|
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 +106,7 @@ Type definitions are included automatically when you install via NPM. For direct
|
|
|
105
106
|
|
|
106
107
|
```html
|
|
107
108
|
<!-- Include the browser-compatible UMD bundle -->
|
|
108
|
-
<script src="momentkh.js"></script>
|
|
109
|
+
<script src="https://cdn.jsdelivr.net/gh/ThyrithSor/momentkh@3.0.3/momentkh.js"></script>
|
|
109
110
|
<script>
|
|
110
111
|
// Convert today to Khmer
|
|
111
112
|
const today = new Date();
|
|
@@ -153,7 +154,7 @@ import momentkh, {
|
|
|
153
154
|
MoonPhase,
|
|
154
155
|
MonthIndex,
|
|
155
156
|
AnimalYear,
|
|
156
|
-
|
|
157
|
+
Sak,
|
|
157
158
|
DayOfWeek,
|
|
158
159
|
} from "@thyrith/momentkh";
|
|
159
160
|
|
|
@@ -209,7 +210,7 @@ const monthName = momentkh.constants.LunarMonthNames[4]; // "แ
แแแแ"
|
|
|
209
210
|
- ๐ `MoonPhase` - Waxing (แแพแ) and Waning (แแแ
)
|
|
210
211
|
- ๐
`MonthIndex` - All 14 Khmer lunar months
|
|
211
212
|
- ๐ `AnimalYear` - All 12 animal years
|
|
212
|
-
- โญ `
|
|
213
|
+
- โญ `Sak` - All 10 Saks
|
|
213
214
|
- ๐ `DayOfWeek` - Sunday through Saturday
|
|
214
215
|
|
|
215
216
|
---
|
|
@@ -253,8 +254,8 @@ Converts a Gregorian (Western) date to a Khmer Lunar date.
|
|
|
253
254
|
jsYear: 1386, // Number: Jolak Sakaraj (Chula Sakaraj) year
|
|
254
255
|
animalYear: 4, // AnimalYear enum: 0-11 (NEW in v3.0)
|
|
255
256
|
animalYearName: 'แแแ', // String: Animal year name
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
sak: 6, // Sak enum: 0-9 (NEW in v3.0)
|
|
258
|
+
sakName: 'แแแแ', // String: Sak name
|
|
258
259
|
dayOfWeek: 0, // DayOfWeek enum: 0=Sunday, 6=Saturday (NEW in v3.0)
|
|
259
260
|
dayOfWeekName: 'แขแถแแทแแแ' // String: Khmer weekday name
|
|
260
261
|
},
|
|
@@ -448,9 +449,14 @@ Formats a Khmer date object into a string with optional custom formatting.
|
|
|
448
449
|
**Default Format:**
|
|
449
450
|
|
|
450
451
|
```
|
|
451
|
-
แแแแ{weekday} {day}{moonPhase} แแ{month} แแแแถแ{animalYear} {
|
|
452
|
+
แแแแ{weekday} {day}{moonPhase} แแ{month} แแแแถแ{animalYear} {sak} แแปแแแแแแแถแ {beYear}
|
|
452
453
|
```
|
|
453
454
|
|
|
455
|
+
**Escaping Characters:**
|
|
456
|
+
To escape characters in the format string (so they are not interpreted as format codes), wrap them in square brackets `[]`.
|
|
457
|
+
|
|
458
|
+
Example: `[Week] w` -> "Week แขแถ"
|
|
459
|
+
|
|
454
460
|
**Returns:** String (formatted Khmer date)
|
|
455
461
|
|
|
456
462
|
**Example:**
|
|
@@ -471,6 +477,10 @@ console.log(momentkh.format(khmer, "c/M/D"));
|
|
|
471
477
|
|
|
472
478
|
console.log(momentkh.format(khmer, "แแแแw dN m แแแแถแa e แ.แ.b"));
|
|
473
479
|
// แแแแแขแถ แฆแแพแ แ
แแแแ แแแแถแแแแ แแแแ แ.แ.แขแฅแฆแจ
|
|
480
|
+
|
|
481
|
+
// Escaping characters (use brackets [])
|
|
482
|
+
console.log(momentkh.format(khmer, "[Day:] d [Month:] m"));
|
|
483
|
+
// Day: แฆ Month: แ
แแแแ
|
|
474
484
|
```
|
|
475
485
|
|
|
476
486
|
---
|
|
@@ -500,7 +510,7 @@ All 14 Khmer lunar months (including leap months).
|
|
|
500
510
|
const { MonthIndex } = momentkh;
|
|
501
511
|
|
|
502
512
|
MonthIndex.Migasir; // 0 - แแทแแแทแ
|
|
503
|
-
MonthIndex.
|
|
513
|
+
MonthIndex.Boss; // 1 - แแปแแแ
|
|
504
514
|
MonthIndex.Meak; // 2 - แแถแ
|
|
505
515
|
MonthIndex.Phalkun; // 3 - แแแแแปแ
|
|
506
516
|
MonthIndex.Cheit; // 4 - แ
แแแแ
|
|
@@ -536,23 +546,23 @@ AnimalYear.Cho; // 10 - ๐ แ
(Dog)
|
|
|
536
546
|
AnimalYear.Kor; // 11 - ๐ แแปแ (Pig)
|
|
537
547
|
```
|
|
538
548
|
|
|
539
|
-
#### โญ
|
|
549
|
+
#### โญ Sak
|
|
540
550
|
|
|
541
|
-
The 10
|
|
551
|
+
The 10 Saks (แแแ) cycle.
|
|
542
552
|
|
|
543
553
|
```javascript
|
|
544
|
-
const {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
554
|
+
const { Sak } = momentkh;
|
|
555
|
+
|
|
556
|
+
Sak.SamridhiSak; // 0 - ๐ แแแแนแแแแทแแแ
|
|
557
|
+
Sak.AekSak; // 1 - 1๏ธโฃ แฏแแแแ
|
|
558
|
+
Sak.ToSak; // 2 - 2๏ธโฃ แแแแแ
|
|
559
|
+
Sak.TreiSak; // 3 - 3๏ธโฃ แแแแธแแแ
|
|
560
|
+
Sak.ChattvaSak; // 4 - 4๏ธโฃ แ
แแแแถแแแ
|
|
561
|
+
Sak.PanchaSak; // 5 - 5๏ธโฃ แแแแ
แแแ
|
|
562
|
+
Sak.ChhaSak; // 6 - 6๏ธโฃ แแแแ
|
|
563
|
+
Sak.SappaSak; // 7 - 7๏ธโฃ แแแแแแแ
|
|
564
|
+
Sak.AtthaSak; // 8 - 8๏ธโฃ แขแแแแแแ
|
|
565
|
+
Sak.NappaSak; // 9 - 9๏ธโฃ แแแแแแแ
|
|
556
566
|
```
|
|
557
567
|
|
|
558
568
|
#### ๐ DayOfWeek
|
|
@@ -627,7 +637,7 @@ const khmer = momentkh.fromGregorian(2024, 12, 16);
|
|
|
627
637
|
// Switch on month
|
|
628
638
|
switch (khmer.khmer.monthIndex) {
|
|
629
639
|
case MonthIndex.Migasir:
|
|
630
|
-
case MonthIndex.
|
|
640
|
+
case MonthIndex.Boss:
|
|
631
641
|
case MonthIndex.Meak:
|
|
632
642
|
console.log("Winter months");
|
|
633
643
|
break;
|
|
@@ -670,7 +680,7 @@ const month: MonthIndex = result.khmer.monthIndex;
|
|
|
670
680
|
const date = momentkh.fromKhmer(
|
|
671
681
|
15,
|
|
672
682
|
MoonPhase. // โ IDE shows: Waxing, Waning
|
|
673
|
-
MonthIndex. // โ IDE shows: Migasir,
|
|
683
|
+
MonthIndex. // โ IDE shows: Migasir, Boss, Meak, etc.
|
|
674
684
|
2568
|
|
675
685
|
);
|
|
676
686
|
```
|
|
@@ -785,13 +795,13 @@ console.log(at.khmer.animalYear); // 'แแแถ' (Rooster) - Changed!
|
|
|
785
795
|
|
|
786
796
|
---
|
|
787
797
|
|
|
788
|
-
###
|
|
798
|
+
### Sak
|
|
789
799
|
|
|
790
800
|
**Full Name:** แแแ (Sak, Era)
|
|
791
801
|
**Cycle:** 10 years
|
|
792
802
|
**When it increases:** At **midnight (00:00) of the last day** of Khmer New Year celebration (Lerng Sak - แแแแแกแพแแแแ)
|
|
793
803
|
|
|
794
|
-
**The 10
|
|
804
|
+
**The 10 Saks (in order):**
|
|
795
805
|
| Index | Khmer | Romanization |
|
|
796
806
|
|-------|-------|--------------|
|
|
797
807
|
| 0 | แแแแนแแแแทแแแ | Samridhi Sak |
|
|
@@ -809,19 +819,19 @@ console.log(at.khmer.animalYear); // 'แแแถ' (Rooster) - Changed!
|
|
|
809
819
|
|
|
810
820
|
- ๐ **Day 1:** Moha Songkran (แแ แถแแแแแแแถแแแ) - New Year's Day
|
|
811
821
|
- ๐ **Day 2:** Virak Wanabat (แแธแแแแแแแ) - Second day
|
|
812
|
-
- โญ **Day 3 or 4:** Lerng Sak (แแแแแกแพแแแแ) - Last day &
|
|
822
|
+
- โญ **Day 3 or 4:** Lerng Sak (แแแแแกแพแแแแ) - Last day & Sak change day
|
|
813
823
|
|
|
814
824
|
**Example:**
|
|
815
825
|
|
|
816
826
|
```javascript
|
|
817
827
|
// 2024 New Year is on April 13, 22:24
|
|
818
|
-
// Lerng Sak (
|
|
828
|
+
// Lerng Sak (Sak change) is typically 3-4 days later at midnight
|
|
819
829
|
|
|
820
830
|
const newYearDay = momentkh.fromGregorian(2024, 4, 13, 23, 0);
|
|
821
|
-
console.log(newYearDay.khmer.
|
|
831
|
+
console.log(newYearDay.khmer.sak); // 'แแแแ' (still old sak)
|
|
822
832
|
|
|
823
833
|
const lerngSakDay = momentkh.fromGregorian(2024, 4, 17, 0, 0); // Midnight of Lerng Sak
|
|
824
|
-
console.log(lerngSakDay.khmer.
|
|
834
|
+
console.log(lerngSakDay.khmer.sak); // 'แแแแแแแ' (new sak!)
|
|
825
835
|
```
|
|
826
836
|
|
|
827
837
|
---
|
|
@@ -834,16 +844,16 @@ console.log(lerngSakDay.khmer.eraYear); // 'แแแแแแแ' (new era!)
|
|
|
834
844
|
| --------------- | ------------------------ | -------------------- |
|
|
835
845
|
| **BE Year** | 00:00 แแ
แแแแแกแแแ
แแแแทแแถแ | May 23, 2024 00:00 |
|
|
836
846
|
| **Animal Year** | แแแแ แแทแ แแถแแธแแแแแถแ
แปแ | April 13, 2024 22:17 |
|
|
837
|
-
| **
|
|
847
|
+
| **Sak** | 00:00 แแ
แแแแแกแพแแแแ | April 16, 2024 00:00 |
|
|
838
848
|
|
|
839
849
|
**Visual Timeline for 2024:**
|
|
840
850
|
|
|
841
851
|
```
|
|
842
|
-
April 13, 22:
|
|
843
|
-
April 13, 22:
|
|
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
|
|
852
|
+
April 13, 22:16 โ BE 2567, Monkey (แแ), Old Sak (แแแแ)
|
|
853
|
+
April 13, 22:17 โ BE 2567, Rooster (แแแถ), Old Sak (แแแแ) โ Animal Year changes
|
|
854
|
+
April 17, 00:00 โ BE 2567, Rooster (แแแถ), New Sak (แแแแแแแ) โ Sak changes
|
|
855
|
+
May 22, 23:59 โ BE 2567, Rooster (แแแถ), New Sak (แแแแแแแ)
|
|
856
|
+
May 23, 00:00 โ BE 2568, Rooster (แแแถ), New Sak (แแแแแแแ) โ BE Year changes
|
|
847
857
|
```
|
|
848
858
|
|
|
849
859
|
---
|
|
@@ -852,43 +862,67 @@ May 23, 00:00 โ BE 2568, Rooster (แแแถ), New Era (แแแแแแแ
|
|
|
852
862
|
|
|
853
863
|
Complete list of format tokens for the `format()` function:
|
|
854
864
|
|
|
855
|
-
| Token
|
|
856
|
-
|
|
|
857
|
-
| **๐
|
|
858
|
-
| `W`
|
|
859
|
-
| `w`
|
|
860
|
-
|
|
|
861
|
-
| `
|
|
862
|
-
|
|
|
863
|
-
| `
|
|
864
|
-
| `
|
|
865
|
-
|
|
|
866
|
-
|
|
|
867
|
-
| `
|
|
868
|
-
| `
|
|
869
|
-
|
|
|
870
|
-
|
|
|
871
|
-
| `
|
|
872
|
-
| `
|
|
873
|
-
| `
|
|
874
|
-
|
|
|
865
|
+
| Token | Output | Description | Example |
|
|
866
|
+
| -------------------------- | ----------------- | ----------------------------------- | --------------------- |
|
|
867
|
+
| **๐
Weekday** |
|
|
868
|
+
| `W` | แแแแแแแแแแแถแ แแแแ | Weekday name (full) | แขแถแแทแแแ, แ
แแแ, แขแแแแถแ |
|
|
869
|
+
| `w` | แแแแแแแแแแแถแ แแแแแธ | Weekday name (short) | แขแถ, แ
, แข |
|
|
870
|
+
| **๐ Lunar Day** |
|
|
871
|
+
| `d` | แแแแแแธ | Lunar day number | แก, แฅ, แกแฅ |
|
|
872
|
+
| `D` | แแแแแแธ (แขแแแแแ) | Lunar day (zero-padded) | แ แก, แ แฅ, แกแฅ |
|
|
873
|
+
| `dr` | Day | Lunar day (Latin) | 1, 5, 15 |
|
|
874
|
+
| `Dr` | Day (0) | Lunar day (padded Latin) | 01, 05, 15 |
|
|
875
|
+
| **๐ Gregorian Day** |
|
|
876
|
+
| `ds` | แแแแแแธ | Gregorian day number | แก, แฅ, แกแค |
|
|
877
|
+
| `Ds` | แแแแแแธ (แขแแแแแ) | Gregorian day (zero-padded) | แ แก, แ แฅ, แกแค |
|
|
878
|
+
| `dsr` | Day | Gregorian day (Latin) | 1, 5, 14 |
|
|
879
|
+
| `Dsr` | Day (0) | Gregorian day (padded Latin) | 01, 05, 14 |
|
|
880
|
+
| **๐ Moon Phase** |
|
|
881
|
+
| `n` | แแพแ/แแแ
(แแแแธ) | Moon phase (short) | แ, แ |
|
|
882
|
+
| `N` | แแพแ/แแแ
(แแแ) | Moon phase (full) | แแพแ, แแแ
|
|
|
883
|
+
| `o` | แแทแแทแแแแแแแแถ | Moon day symbol | แงก, แงข, แงฃ ... แงฟ |
|
|
884
|
+
| **๐ Month Names** |
|
|
885
|
+
| `m` | แแแ
แแแแแแท | Lunar month name | แแทแแแทแ, แแปแแแ, แ
แแแแ |
|
|
886
|
+
| `ms` | แแ (แแแแแแ) | Lunar month name (abbreviated) | แแท, แแป |
|
|
887
|
+
| `M` | แแแแปแแทแแแแท | Solar (Gregorian) month name | แแแแถ, แแปแแแแ, แแแแถ |
|
|
888
|
+
| `Ms` | แแ (แแแแแแ) | Solar month name (abbreviated) | แแ, แแ |
|
|
889
|
+
| **โฐ Year Components** |
|
|
890
|
+
| `a` | แแแแถแแแแแ | Animal year | แแผแ, แแแแผแ, แแแ |
|
|
891
|
+
| `as` | แแแแถแ (แแผแ) | Animal year emoji | ๐, ๐, ๐ |
|
|
892
|
+
| `e` | แแแ | Sak | แฏแแแแ, แแแแแ |
|
|
893
|
+
| `b` | แ.แ. | Buddhist Era year | แขแฅแฆแจ |
|
|
894
|
+
| `br` | BE | Buddhist Era year (Latin) | 2568 |
|
|
895
|
+
| `c` | แ.แ. | Common Era (Gregorian) year | แขแ แขแค |
|
|
896
|
+
| `cr` | CE | Common Era year (Latin) | 2024 |
|
|
897
|
+
| `j` | แ
.แ. | Jolak Sakaraj year | แกแฃแจแฆ |
|
|
898
|
+
| `jr` | JS | Jolak Sakaraj year (Latin) | 1386 |
|
|
875
899
|
|
|
876
900
|
**Format Examples:**
|
|
877
901
|
|
|
878
902
|
```javascript
|
|
879
|
-
const khmer = momentkh.fromGregorian(
|
|
903
|
+
const khmer = momentkh.fromGregorian(2025, 5, 3);
|
|
880
904
|
|
|
881
905
|
console.log(momentkh.format(khmer, "W, dN แแm แ.แ.b"));
|
|
882
|
-
//
|
|
906
|
+
// แแ
แแ, แงแแพแ แแแแทแแถแ แ.แ.แขแฅแฆแจ
|
|
883
907
|
|
|
884
|
-
console.log(momentkh.format(khmer, "c/M/
|
|
885
|
-
//
|
|
908
|
+
console.log(momentkh.format(khmer, "c/M/Ds แแแแw"));
|
|
909
|
+
// แขแ แขแฅ/แงแแแถ/แ แฃ แแแแแ
|
|
886
910
|
|
|
887
|
-
console.log(momentkh.format(khmer, "แแแแถแa e แแm แแแแแแธ
|
|
888
|
-
//
|
|
911
|
+
console.log(momentkh.format(khmer, "แแแแถแa e แแm แแแแแแธDN"));
|
|
912
|
+
// แแแแถแแแแแถแแ แแแแแแแ แแแแทแแถแ แแแแแแธแ แงแแพแ
|
|
889
913
|
|
|
890
914
|
console.log(momentkh.format(khmer, "แแแแแแธ o"));
|
|
891
|
-
// แแแแแแธ
|
|
915
|
+
// แแแแแแธ แงง
|
|
916
|
+
|
|
917
|
+
// Using new Gregorian day format codes
|
|
918
|
+
console.log(momentkh.format(khmer, "แแแแแแธds แแM แแแแถแc"));
|
|
919
|
+
// แแแแแแธแฃ แแแงแแแถ แแแแถแแขแ แขแฅ
|
|
920
|
+
|
|
921
|
+
console.log(momentkh.format(khmer, "dsr/M/cr"));
|
|
922
|
+
// 3/แงแแแถ/2025
|
|
923
|
+
|
|
924
|
+
console.log(momentkh.format(khmer, "Dsr-M-cr"));
|
|
925
|
+
// 03-แงแแแถ-2025
|
|
892
926
|
```
|
|
893
927
|
|
|
894
928
|
---
|
|
@@ -915,8 +949,13 @@ momentkh.constants.AnimalYearNames;
|
|
|
915
949
|
// ['แแผแ', 'แแแแผแ', 'แแถแ', 'แแแ', 'แแแ', 'แแแแถแแ',
|
|
916
950
|
// 'แแแธ', 'แแแ', 'แแ', 'แแแถ', 'แ
', 'แแปแ']
|
|
917
951
|
|
|
918
|
-
//
|
|
919
|
-
momentkh.constants.
|
|
952
|
+
// Animal year emojis array (indices 0-11)
|
|
953
|
+
momentkh.constants.AnimalYearEmojis;
|
|
954
|
+
// ['๐', '๐', '๐
', '๐', '๐', '๐',
|
|
955
|
+
// '๐', '๐', '๐', '๐', '๐', '๐']
|
|
956
|
+
|
|
957
|
+
// Sak names array (indices 0-9)
|
|
958
|
+
momentkh.constants.SakNames;
|
|
920
959
|
// ['แแแแนแแแแทแแแ', 'แฏแแแแ', 'แแแแแ', 'แแแแธแแแ', 'แ
แแแแถแแแ',
|
|
921
960
|
// 'แแแแ
แแแ', 'แแแแ', 'แแแแแแแ', 'แขแแแแแแ', 'แแแแแแแ']
|
|
922
961
|
|
|
@@ -925,7 +964,7 @@ momentkh.constants.WeekdayNames;
|
|
|
925
964
|
// ['แขแถแแทแแแ', 'แ
แแแ', 'แขแแแแถแ', 'แแปแ', 'แแแแ แแแแแทแ', 'แแปแแแ', 'แแ
แแ']
|
|
926
965
|
|
|
927
966
|
// Moon phase names array (indices 0-1)
|
|
928
|
-
momentkh.constants.
|
|
967
|
+
momentkh.constants.MoonPhaseNames;
|
|
929
968
|
// ['แแพแ', 'แแแ
']
|
|
930
969
|
```
|
|
931
970
|
|
|
@@ -960,7 +999,7 @@ npm install @thyrith/momentkh --save
|
|
|
960
999
|
**After (v2):**
|
|
961
1000
|
|
|
962
1001
|
```bash
|
|
963
|
-
|
|
1002
|
+
npm install @thyrith/momentkh
|
|
964
1003
|
```
|
|
965
1004
|
|
|
966
1005
|
### Import Changes
|
|
@@ -1126,7 +1165,7 @@ console.log(
|
|
|
1126
1165
|
);
|
|
1127
1166
|
console.log("BE Year:", khmer.khmer.beYear);
|
|
1128
1167
|
console.log("Animal Year:", khmer.khmer.animalYear);
|
|
1129
|
-
console.log("
|
|
1168
|
+
console.log("Sak:", khmer.khmer.sak);
|
|
1130
1169
|
console.log("Month:", khmer.khmer.monthName);
|
|
1131
1170
|
console.log(
|
|
1132
1171
|
"Day:",
|
|
@@ -1137,7 +1176,7 @@ console.log(
|
|
|
1137
1176
|
// Gregorian: 14/4/2024
|
|
1138
1177
|
// BE Year: 2568
|
|
1139
1178
|
// Animal Year: แแแ
|
|
1140
|
-
//
|
|
1179
|
+
// Sak: แแแแ
|
|
1141
1180
|
// Month: แ
แแแแ
|
|
1142
1181
|
// Day: 6แแพแ
|
|
1143
1182
|
```
|
|
@@ -1274,7 +1313,7 @@ for (let day = 20; day <= 25; day++) {
|
|
|
1274
1313
|
|
|
1275
1314
|
MIT License - Same as original momentkh
|
|
1276
1315
|
|
|
1277
|
-
Copyright (c)
|
|
1316
|
+
Copyright (c) 2025
|
|
1278
1317
|
|
|
1279
1318
|
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
1319
|
|
|
@@ -1322,12 +1361,11 @@ node test_specific_dates.js
|
|
|
1322
1361
|
|
|
1323
1362
|
## ๐ Support
|
|
1324
1363
|
|
|
1325
|
-
- **Documentation:** See examples folder (`newYearMoment.js`, `index.html`)
|
|
1326
1364
|
- **Issues:** [GitHub Issues](https://github.com/ThyrithSor/momentkh/issues)
|
|
1327
1365
|
- **Comparison:** Check behavior against original momentkh for compatibility
|
|
1366
|
+
- **Contact:** [E-mail](mailto:me@thyrith.com)
|
|
1328
1367
|
|
|
1329
1368
|
---
|
|
1330
1369
|
|
|
1331
|
-
**Version:** 3.0.
|
|
1332
|
-
**Last Updated:** December
|
|
1333
|
-
**Status:** Production Ready โ
|
|
1370
|
+
**Version:** 3.0.3
|
|
1371
|
+
**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,QAAQ;IAC1B,KAAK,IAAI,CAAS,QAAQ;IAC1B,IAAI,IAAI,CAAU,UAAU;IAC5B,SAAS,IAAI,CAAK,SAAS;IAC3B,MAAM,KAAK,CAAO,SAAS;IAC3B,MAAM,KAAK,CAAQ,SAAS;IAC5B,WAAW,KAAK,CAAI,UAAU;IAC9B,UAAU,KAAK;CAChB;AAED,oBAAY,UAAU;IACpB,KAAK,IAAI,CAAK,YAAY;IAC1B,KAAK,IAAI,CAAK,aAAa;IAC3B,IAAI,IAAI,CAAM,cAAc;IAC5B,IAAI,IAAI,CAAM,eAAe;IAC7B,IAAI,IAAI,CAAM,eAAe;IAC7B,MAAM,IAAI,CAAI,iB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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,46 @@ 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
|
+
'ds': () => toKhmerNumeral(khmerData.gregorian.day),
|
|
1001
|
+
'Ds': () => toKhmerNumeral((khmerData.gregorian.day < 10 ? '0' : '') + khmerData.gregorian.day),
|
|
1002
|
+
'dsr': () => khmerData.gregorian.day,
|
|
1003
|
+
'Dsr': () => (khmerData.gregorian.day < 10 ? '0' : '') + khmerData.gregorian.day,
|
|
1004
|
+
'n': () => MoonPhaseShort[khmerData.khmer.moonPhase],
|
|
986
1005
|
'N': () => khmerData.khmer.moonPhaseName,
|
|
987
1006
|
'o': () => MoonDaySymbols[khmerData._khmerDateObj.getDayNumber()],
|
|
988
1007
|
'm': () => khmerData.khmer.monthName,
|
|
989
1008
|
'M': () => SolarMonthNames[khmerData.gregorian.month - 1],
|
|
990
1009
|
'a': () => khmerData.khmer.animalYearName,
|
|
991
|
-
'
|
|
992
|
-
'
|
|
993
|
-
'
|
|
994
|
-
'
|
|
1010
|
+
'as': () => AnimalYearEmojis[khmerData.khmer.animalYear],
|
|
1011
|
+
'e': () => khmerData.khmer.sakName,
|
|
1012
|
+
'b': () => toKhmerNumeral(khmerData.khmer.beYear),
|
|
1013
|
+
'br': () => khmerData.khmer.beYear,
|
|
1014
|
+
'c': () => toKhmerNumeral(khmerData.gregorian.year),
|
|
1015
|
+
'cr': () => khmerData.gregorian.year,
|
|
1016
|
+
'j': () => toKhmerNumeral(khmerData.khmer.jsYear),
|
|
1017
|
+
'jr': () => khmerData.khmer.jsYear,
|
|
1018
|
+
'Ms': () => SolarMonthAbbreviationNames[khmerData.gregorian.month - 1],
|
|
1019
|
+
'ms': () => LunarMonthAbbreviationNames[khmerData.khmer.monthIndex]
|
|
995
1020
|
};
|
|
996
|
-
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1021
|
+
// Sort keys by length descending to ensure longer tokens (like 'Ms', 'ms') are matched before shorter ones (like 'M', 'm')
|
|
1022
|
+
const sortedKeys = Object.keys(formatRules).sort((a, b) => b.length - a.length);
|
|
1023
|
+
const regex = new RegExp(`\\[([^\\]]+)\\]|(${sortedKeys.join('|')})`, 'g');
|
|
1024
|
+
const result = formatString.replace(regex, (match, escaped, token) => {
|
|
1025
|
+
if (escaped) {
|
|
1026
|
+
return escaped;
|
|
1027
|
+
}
|
|
1028
|
+
const value = formatRules[token]();
|
|
1029
|
+
return String(value);
|
|
1000
1030
|
});
|
|
1001
1031
|
return result;
|
|
1002
1032
|
}
|
|
@@ -1041,10 +1071,13 @@ exports.constants = {
|
|
|
1041
1071
|
LunarMonths,
|
|
1042
1072
|
LunarMonthNames,
|
|
1043
1073
|
SolarMonthNames,
|
|
1074
|
+
SolarMonthAbbreviationNames,
|
|
1075
|
+
LunarMonthAbbreviationNames,
|
|
1044
1076
|
AnimalYearNames,
|
|
1045
|
-
|
|
1077
|
+
AnimalYearEmojis,
|
|
1078
|
+
SakNames,
|
|
1046
1079
|
WeekdayNames,
|
|
1047
|
-
|
|
1080
|
+
MoonPhaseNames
|
|
1048
1081
|
};
|
|
1049
1082
|
// Default export - aggregate all exports for convenience
|
|
1050
1083
|
exports.default = {
|
|
@@ -1058,6 +1091,6 @@ exports.default = {
|
|
|
1058
1091
|
MoonPhase,
|
|
1059
1092
|
MonthIndex,
|
|
1060
1093
|
AnimalYear,
|
|
1061
|
-
|
|
1094
|
+
Sak,
|
|
1062
1095
|
DayOfWeek
|
|
1063
1096
|
};
|
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,46 @@ 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
|
+
'ds': () => toKhmerNumeral(khmerData.gregorian.day),
|
|
1024
|
+
'Ds': () => toKhmerNumeral((khmerData.gregorian.day < 10 ? '0' : '') + khmerData.gregorian.day),
|
|
1025
|
+
'dsr': () => khmerData.gregorian.day,
|
|
1026
|
+
'Dsr': () => (khmerData.gregorian.day < 10 ? '0' : '') + khmerData.gregorian.day,
|
|
1027
|
+
'n': () => MoonPhaseShort[khmerData.khmer.moonPhase],
|
|
1008
1028
|
'N': () => khmerData.khmer.moonPhaseName,
|
|
1009
1029
|
'o': () => MoonDaySymbols[khmerData._khmerDateObj.getDayNumber()],
|
|
1010
1030
|
'm': () => khmerData.khmer.monthName,
|
|
1011
1031
|
'M': () => SolarMonthNames[khmerData.gregorian.month - 1],
|
|
1012
1032
|
'a': () => khmerData.khmer.animalYearName,
|
|
1013
|
-
'
|
|
1014
|
-
'
|
|
1015
|
-
'
|
|
1016
|
-
'
|
|
1033
|
+
'as': () => AnimalYearEmojis[khmerData.khmer.animalYear],
|
|
1034
|
+
'e': () => khmerData.khmer.sakName,
|
|
1035
|
+
'b': () => toKhmerNumeral(khmerData.khmer.beYear),
|
|
1036
|
+
'br': () => khmerData.khmer.beYear,
|
|
1037
|
+
'c': () => toKhmerNumeral(khmerData.gregorian.year),
|
|
1038
|
+
'cr': () => khmerData.gregorian.year,
|
|
1039
|
+
'j': () => toKhmerNumeral(khmerData.khmer.jsYear),
|
|
1040
|
+
'jr': () => khmerData.khmer.jsYear,
|
|
1041
|
+
'Ms': () => SolarMonthAbbreviationNames[khmerData.gregorian.month - 1],
|
|
1042
|
+
'ms': () => LunarMonthAbbreviationNames[khmerData.khmer.monthIndex]
|
|
1017
1043
|
};
|
|
1018
|
-
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1044
|
+
// Sort keys by length descending to ensure longer tokens (like 'Ms', 'ms') are matched before shorter ones (like 'M', 'm')
|
|
1045
|
+
const sortedKeys = Object.keys(formatRules).sort((a, b) => b.length - a.length);
|
|
1046
|
+
const regex = new RegExp(`\\[([^\\]]+)\\]|(${sortedKeys.join('|')})`, 'g');
|
|
1047
|
+
const result = formatString.replace(regex, (match, escaped, token) => {
|
|
1048
|
+
if (escaped) {
|
|
1049
|
+
return escaped;
|
|
1050
|
+
}
|
|
1051
|
+
const value = formatRules[token]();
|
|
1052
|
+
return String(value);
|
|
1022
1053
|
});
|
|
1023
1054
|
return result;
|
|
1024
1055
|
}
|
|
@@ -1063,10 +1094,13 @@ exports.constants = {
|
|
|
1063
1094
|
LunarMonths,
|
|
1064
1095
|
LunarMonthNames,
|
|
1065
1096
|
SolarMonthNames,
|
|
1097
|
+
SolarMonthAbbreviationNames,
|
|
1098
|
+
LunarMonthAbbreviationNames,
|
|
1066
1099
|
AnimalYearNames,
|
|
1067
|
-
|
|
1100
|
+
AnimalYearEmojis,
|
|
1101
|
+
SakNames,
|
|
1068
1102
|
WeekdayNames,
|
|
1069
|
-
|
|
1103
|
+
MoonPhaseNames
|
|
1070
1104
|
};
|
|
1071
1105
|
// Default export - aggregate all exports for convenience
|
|
1072
1106
|
exports.default = {
|
|
@@ -1080,7 +1114,7 @@ exports.default = {
|
|
|
1080
1114
|
MoonPhase,
|
|
1081
1115
|
MonthIndex,
|
|
1082
1116
|
AnimalYear,
|
|
1083
|
-
|
|
1117
|
+
Sak,
|
|
1084
1118
|
DayOfWeek
|
|
1085
1119
|
};
|
|
1086
1120
|
|
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,42 @@ 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
|
+
'ds': () => toKhmerNumeral(khmerData.gregorian.day),
|
|
1271
|
+
'Ds': () => toKhmerNumeral((khmerData.gregorian.day < 10 ? '0' : '') + khmerData.gregorian.day),
|
|
1272
|
+
'dsr': () => khmerData.gregorian.day,
|
|
1273
|
+
'Dsr': () => (khmerData.gregorian.day < 10 ? '0' : '') + khmerData.gregorian.day,
|
|
1274
|
+
'n': () => MoonPhaseShort[khmerData.khmer.moonPhase],
|
|
1245
1275
|
'N': () => khmerData.khmer.moonPhaseName,
|
|
1246
1276
|
'o': () => MoonDaySymbols[khmerData._khmerDateObj.getDayNumber()],
|
|
1247
1277
|
'm': () => khmerData.khmer.monthName,
|
|
1248
1278
|
'M': () => SolarMonthNames[khmerData.gregorian.month - 1],
|
|
1249
1279
|
'a': () => khmerData.khmer.animalYearName,
|
|
1250
|
-
'
|
|
1251
|
-
'
|
|
1252
|
-
'
|
|
1253
|
-
'
|
|
1280
|
+
'as': () => AnimalYearEmojis[khmerData.khmer.animalYear],
|
|
1281
|
+
'e': () => khmerData.khmer.sakName,
|
|
1282
|
+
'b': () => toKhmerNumeral(khmerData.khmer.beYear),
|
|
1283
|
+
'br': () => khmerData.khmer.beYear,
|
|
1284
|
+
'c': () => toKhmerNumeral(khmerData.gregorian.year),
|
|
1285
|
+
'cr': () => khmerData.gregorian.year,
|
|
1286
|
+
'j': () => toKhmerNumeral(khmerData.khmer.jsYear),
|
|
1287
|
+
'jr': () => khmerData.khmer.jsYear,
|
|
1288
|
+
'Ms': () => SolarMonthAbbreviationNames[khmerData.gregorian.month - 1],
|
|
1289
|
+
'ms': () => LunarMonthAbbreviationNames[khmerData.khmer.monthIndex]
|
|
1254
1290
|
};
|
|
1255
1291
|
|
|
1256
|
-
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1292
|
+
// Sort keys by length descending to ensure longer tokens (like 'Ms', 'ms') are matched before shorter ones (like 'M', 'm')
|
|
1293
|
+
const sortedKeys = Object.keys(formatRules).sort((a, b) => b.length - a.length);
|
|
1294
|
+
const regex = new RegExp(`\\[([^\\]]+)\\]|(${sortedKeys.join('|')})`, 'g');
|
|
1295
|
+
|
|
1296
|
+
const result = formatString.replace(regex, (match, escaped, token) => {
|
|
1297
|
+
if (escaped) {
|
|
1298
|
+
return escaped;
|
|
1299
|
+
}
|
|
1300
|
+
const value = formatRules[token]();
|
|
1301
|
+
return String(value);
|
|
1260
1302
|
});
|
|
1261
1303
|
|
|
1262
1304
|
return result;
|
|
@@ -1292,7 +1334,6 @@ export function getNewYear(ceYear: number): NewYearInfo {
|
|
|
1292
1334
|
export function format(khmerData: KhmerConversionResult, formatString?: string): string {
|
|
1293
1335
|
return formatKhmer(khmerData, formatString);
|
|
1294
1336
|
}
|
|
1295
|
-
|
|
1296
1337
|
// Utility for creating date from Date object
|
|
1297
1338
|
export function fromDate(date: Date): KhmerConversionResult {
|
|
1298
1339
|
// Validate Date object
|
|
@@ -1318,10 +1359,13 @@ export const constants = {
|
|
|
1318
1359
|
LunarMonths,
|
|
1319
1360
|
LunarMonthNames,
|
|
1320
1361
|
SolarMonthNames,
|
|
1362
|
+
SolarMonthAbbreviationNames,
|
|
1363
|
+
LunarMonthAbbreviationNames,
|
|
1321
1364
|
AnimalYearNames,
|
|
1322
|
-
|
|
1365
|
+
AnimalYearEmojis,
|
|
1366
|
+
SakNames,
|
|
1323
1367
|
WeekdayNames,
|
|
1324
|
-
|
|
1368
|
+
MoonPhaseNames
|
|
1325
1369
|
};
|
|
1326
1370
|
|
|
1327
1371
|
// Default export - aggregate all exports for convenience
|
|
@@ -1336,6 +1380,6 @@ export default {
|
|
|
1336
1380
|
MoonPhase,
|
|
1337
1381
|
MonthIndex,
|
|
1338
1382
|
AnimalYear,
|
|
1339
|
-
|
|
1383
|
+
Sak,
|
|
1340
1384
|
DayOfWeek
|
|
1341
1385
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thyrith/momentkh",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Working on khmer calendar by implementting moment js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "component",
|
|
@@ -52,8 +52,7 @@
|
|
|
52
52
|
]
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
"dependencies": {
|
|
56
|
-
},
|
|
55
|
+
"dependencies": {},
|
|
57
56
|
"spm": {
|
|
58
57
|
"main": "momentkh.js",
|
|
59
58
|
"output": [
|
|
@@ -63,4 +62,4 @@
|
|
|
63
62
|
"devDependencies": {
|
|
64
63
|
"typescript": "^5.9.3"
|
|
65
64
|
}
|
|
66
|
-
}
|
|
65
|
+
}
|