@thyrith/momentkh 3.0.0 โ 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 +134 -114
- package/dist/momentkh.d.ts +65 -36
- package/dist/momentkh.d.ts.map +1 -1
- package/dist/momentkh.js +152 -112
- package/momentkh.js +1117 -11
- package/momentkh.ts +169 -125
- package/package.json +3 -2
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
|
|
|
@@ -17,11 +19,11 @@ const momentkh = require("@thyrith/momentkh");
|
|
|
17
19
|
// Convert date to Khmer format (default)
|
|
18
20
|
const khmer = momentkh.fromDate(new Date());
|
|
19
21
|
console.log(momentkh.format(khmer));
|
|
20
|
-
// Output:
|
|
22
|
+
// Output: แแแแแแปแ แกแขแแแ
แแแแทแแแทแ แแแแถแแแแแถแแ แแแแแแแ แแปแแแแแแแถแ แขแฅแฆแฉ
|
|
21
23
|
|
|
22
24
|
// Convert date to Khmer format (custom)
|
|
23
25
|
console.log(momentkh.format(khmer, "dN แแm แแแแถแa"));
|
|
24
|
-
// Output:
|
|
26
|
+
// Output: แกแขแแแ
แแแแทแแแทแ แแแแถแแแแแถแแ
|
|
25
27
|
|
|
26
28
|
// Convert Khmer date to Gregorian
|
|
27
29
|
const gregorian = momentkh.fromKhmer(15, 0, 5, 2568); // 15แแพแ แแแแทแแถแ แ.แ.แขแฅแฆแจ
|
|
@@ -31,7 +33,7 @@ console.log(gregorian);
|
|
|
31
33
|
// Get Khmer New Year
|
|
32
34
|
const newYear = momentkh.getNewYear(2025);
|
|
33
35
|
console.log(newYear);
|
|
34
|
-
// Output: { year: 2025, month: 4, day:
|
|
36
|
+
// Output: { year: 2025, month: 4, day: 14, hour: 4, minute: 48 }
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
---
|
|
@@ -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.
|
|
@@ -104,19 +98,23 @@ Type definitions are included automatically when you install via NPM. For direct
|
|
|
104
98
|
### Browser (HTML)
|
|
105
99
|
|
|
106
100
|
```html
|
|
107
|
-
|
|
101
|
+
<!-- Include the browser-compatible UMD bundle -->
|
|
102
|
+
<script src="https://cdn.jsdelivr.net/gh/ThyrithSor/momentkh@3.0.2/momentkh.js"></script>
|
|
108
103
|
<script>
|
|
109
104
|
// Convert today to Khmer
|
|
110
105
|
const today = new Date();
|
|
111
106
|
const khmer = momentkh.fromDate(today);
|
|
112
107
|
console.log(momentkh.format(khmer));
|
|
113
|
-
// Output:
|
|
108
|
+
// Output: แแแแแแปแ แกแขแแแ
แแแแทแแแทแ แแแแถแแแแแถแแ แแแแแแแ แแปแแแแแแแถแ แขแฅแฆแฉ
|
|
114
109
|
</script>
|
|
115
110
|
```
|
|
116
111
|
|
|
112
|
+
> **Note:** Use `momentkh.js` (UMD bundle) for browsers. The `dist/momentkh.js` is CommonJS format for Node.js.
|
|
113
|
+
|
|
117
114
|
### Node.js (CommonJS)
|
|
118
115
|
|
|
119
116
|
```javascript
|
|
117
|
+
// Use the CommonJS module from dist/
|
|
120
118
|
const momentkh = require("@thyrith/momentkh");
|
|
121
119
|
|
|
122
120
|
// Convert specific date
|
|
@@ -125,7 +123,7 @@ console.log(momentkh.format(khmer));
|
|
|
125
123
|
|
|
126
124
|
// Get Khmer New Year
|
|
127
125
|
const newYear = momentkh.getNewYear(2024);
|
|
128
|
-
console.log(newYear); // { year: 2024, month: 4, day: 13, hour: 22, minute:
|
|
126
|
+
console.log(newYear); // { year: 2024, month: 4, day: 13, hour: 22, minute: 17 }
|
|
129
127
|
```
|
|
130
128
|
|
|
131
129
|
### ES Modules
|
|
@@ -149,7 +147,7 @@ import momentkh, {
|
|
|
149
147
|
MoonPhase,
|
|
150
148
|
MonthIndex,
|
|
151
149
|
AnimalYear,
|
|
152
|
-
|
|
150
|
+
Sak,
|
|
153
151
|
DayOfWeek,
|
|
154
152
|
} from "@thyrith/momentkh";
|
|
155
153
|
|
|
@@ -165,14 +163,14 @@ console.log(momentkh.format(khmer));
|
|
|
165
163
|
|
|
166
164
|
// Access enum values (NEW in v3.0!)
|
|
167
165
|
console.log(khmer.khmer.moonPhase === MoonPhase.Waxing); // Type-safe comparison
|
|
168
|
-
console.log(khmer.khmer.monthIndex === MonthIndex.
|
|
166
|
+
console.log(khmer.khmer.monthIndex === MonthIndex.Cheit); // Enum comparison
|
|
169
167
|
console.log(khmer.khmer.dayOfWeek === DayOfWeek.Sunday); // Autocomplete support!
|
|
170
168
|
|
|
171
169
|
// Reverse conversion with enums (type-safe!)
|
|
172
170
|
const gregorianDate: GregorianDate = momentkh.fromKhmer(
|
|
173
171
|
15,
|
|
174
172
|
MoonPhase.Waxing, // Use enum instead of 0
|
|
175
|
-
MonthIndex.
|
|
173
|
+
MonthIndex.Pisakh, // Use enum instead of 5
|
|
176
174
|
2568
|
|
177
175
|
);
|
|
178
176
|
console.log(
|
|
@@ -205,7 +203,7 @@ const monthName = momentkh.constants.LunarMonthNames[4]; // "แ
แแแแ"
|
|
|
205
203
|
- ๐ `MoonPhase` - Waxing (แแพแ) and Waning (แแแ
)
|
|
206
204
|
- ๐
`MonthIndex` - All 14 Khmer lunar months
|
|
207
205
|
- ๐ `AnimalYear` - All 12 animal years
|
|
208
|
-
- โญ `
|
|
206
|
+
- โญ `Sak` - All 10 Saks
|
|
209
207
|
- ๐ `DayOfWeek` - Sunday through Saturday
|
|
210
208
|
|
|
211
209
|
---
|
|
@@ -249,8 +247,8 @@ Converts a Gregorian (Western) date to a Khmer Lunar date.
|
|
|
249
247
|
jsYear: 1386, // Number: Jolak Sakaraj (Chula Sakaraj) year
|
|
250
248
|
animalYear: 4, // AnimalYear enum: 0-11 (NEW in v3.0)
|
|
251
249
|
animalYearName: 'แแแ', // String: Animal year name
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
sak: 6, // Sak enum: 0-9 (NEW in v3.0)
|
|
251
|
+
sakName: 'แแแแ', // String: Sak name
|
|
254
252
|
dayOfWeek: 0, // DayOfWeek enum: 0=Sunday, 6=Saturday (NEW in v3.0)
|
|
255
253
|
dayOfWeekName: 'แขแถแแทแแแ' // String: Khmer weekday name
|
|
256
254
|
},
|
|
@@ -267,9 +265,9 @@ Converts a Gregorian (Western) date to a Khmer Lunar date.
|
|
|
267
265
|
|
|
268
266
|
```javascript
|
|
269
267
|
const result = momentkh.fromGregorian(2024, 4, 14);
|
|
270
|
-
console.log(result.khmer.beYear); //
|
|
268
|
+
console.log(result.khmer.beYear); // 2567
|
|
271
269
|
console.log(result.khmer.monthName); // 'แ
แแแแ'
|
|
272
|
-
console.log(result.khmer.animalYear); //
|
|
270
|
+
console.log(result.khmer.animalYear); // 4 (แแแ)
|
|
273
271
|
```
|
|
274
272
|
|
|
275
273
|
---
|
|
@@ -319,14 +317,14 @@ Converts a Khmer Lunar date to a Gregorian date.
|
|
|
319
317
|
```javascript
|
|
320
318
|
// Using numbers (backward compatible)
|
|
321
319
|
const gregorian1 = momentkh.fromKhmer(6, 0, 4, 2568);
|
|
322
|
-
console.log(gregorian1); // { year:
|
|
320
|
+
console.log(gregorian1); // { year: 2025, month: 4, day: 3 }
|
|
323
321
|
|
|
324
322
|
// Using enums (NEW in v3.0 - type-safe!)
|
|
325
323
|
const { MoonPhase, MonthIndex } = momentkh;
|
|
326
324
|
const gregorian2 = momentkh.fromKhmer(
|
|
327
325
|
6,
|
|
328
326
|
MoonPhase.Waxing,
|
|
329
|
-
MonthIndex.
|
|
327
|
+
MonthIndex.Cheit,
|
|
330
328
|
2568
|
|
331
329
|
);
|
|
332
330
|
console.log(gregorian2); // { year: 2024, month: 4, day: 14 }
|
|
@@ -415,7 +413,7 @@ console.log(
|
|
|
415
413
|
ny2024.hour
|
|
416
414
|
}:${String(ny2024.minute).padStart(2, "0")}`
|
|
417
415
|
);
|
|
418
|
-
// Output: Khmer New Year 2024: 13/4/2024 at 22:
|
|
416
|
+
// Output: Khmer New Year 2024: 13/4/2024 at 22:17
|
|
419
417
|
|
|
420
418
|
// Loop through multiple years
|
|
421
419
|
for (let year = 2020; year <= 2025; year++) {
|
|
@@ -444,9 +442,14 @@ Formats a Khmer date object into a string with optional custom formatting.
|
|
|
444
442
|
**Default Format:**
|
|
445
443
|
|
|
446
444
|
```
|
|
447
|
-
แแแแ{weekday} {day}{moonPhase} แแ{month} แแแแถแ{animalYear} {
|
|
445
|
+
แแแแ{weekday} {day}{moonPhase} แแ{month} แแแแถแ{animalYear} {sak} แแปแแแแแแแถแ {beYear}
|
|
448
446
|
```
|
|
449
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
|
+
|
|
450
453
|
**Returns:** String (formatted Khmer date)
|
|
451
454
|
|
|
452
455
|
**Example:**
|
|
@@ -467,6 +470,10 @@ console.log(momentkh.format(khmer, "c/M/D"));
|
|
|
467
470
|
|
|
468
471
|
console.log(momentkh.format(khmer, "แแแแw dN m แแแแถแa e แ.แ.b"));
|
|
469
472
|
// แแแแแขแถ แฆแแพแ แ
แแแแ แแแแถแแแแ แแแแ แ.แ.แขแฅแฆแจ
|
|
473
|
+
|
|
474
|
+
// Escaping characters (use brackets [])
|
|
475
|
+
console.log(momentkh.format(khmer, "[Day:] d [Month:] m"));
|
|
476
|
+
// Day: แฆ Month: แ
แแแแ
|
|
470
477
|
```
|
|
471
478
|
|
|
472
479
|
---
|
|
@@ -495,20 +502,20 @@ All 14 Khmer lunar months (including leap months).
|
|
|
495
502
|
```javascript
|
|
496
503
|
const { MonthIndex } = momentkh;
|
|
497
504
|
|
|
498
|
-
MonthIndex.
|
|
505
|
+
MonthIndex.Migasir; // 0 - แแทแแแทแ
|
|
499
506
|
MonthIndex.Bos; // 1 - แแปแแแ
|
|
500
507
|
MonthIndex.Meak; // 2 - แแถแ
|
|
501
|
-
MonthIndex.
|
|
502
|
-
MonthIndex.
|
|
503
|
-
MonthIndex.
|
|
508
|
+
MonthIndex.Phalkun; // 3 - แแแแแปแ
|
|
509
|
+
MonthIndex.Cheit; // 4 - แ
แแแแ
|
|
510
|
+
MonthIndex.Pisakh; // 5 - แแทแแถแ
|
|
504
511
|
MonthIndex.Jesth; // 6 - แแแแแ
|
|
505
|
-
MonthIndex.
|
|
512
|
+
MonthIndex.Asadh; // 7 - แขแถแแถแ
|
|
506
513
|
MonthIndex.Srap; // 8 - แแแแถแแแ
|
|
507
|
-
MonthIndex.
|
|
514
|
+
MonthIndex.Phatrabot; // 9 - แแแแแแ
|
|
508
515
|
MonthIndex.Assoch; // 10 - แขแแแแปแ
|
|
509
|
-
MonthIndex.
|
|
510
|
-
MonthIndex.
|
|
511
|
-
MonthIndex.
|
|
516
|
+
MonthIndex.Kadeuk; // 11 - แแแแแทแ
|
|
517
|
+
MonthIndex.Pathamasadh; // 12 - แแแแถแแถแ (leap month only)
|
|
518
|
+
MonthIndex.Tutiyasadh; // 13 - แแปแแทแแถแแถแ (leap month only)
|
|
512
519
|
```
|
|
513
520
|
|
|
514
521
|
#### ๐ AnimalYear
|
|
@@ -532,23 +539,23 @@ AnimalYear.Cho; // 10 - ๐ แ
(Dog)
|
|
|
532
539
|
AnimalYear.Kor; // 11 - ๐ แแปแ (Pig)
|
|
533
540
|
```
|
|
534
541
|
|
|
535
|
-
#### โญ
|
|
542
|
+
#### โญ Sak
|
|
536
543
|
|
|
537
|
-
The 10
|
|
544
|
+
The 10 Saks (แแแ) cycle.
|
|
538
545
|
|
|
539
546
|
```javascript
|
|
540
|
-
const {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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๏ธโฃ แแแแแแแ
|
|
552
559
|
```
|
|
553
560
|
|
|
554
561
|
#### ๐ DayOfWeek
|
|
@@ -583,8 +590,8 @@ if (khmer.khmer.moonPhase === MoonPhase.Waxing) {
|
|
|
583
590
|
}
|
|
584
591
|
|
|
585
592
|
// Check specific month
|
|
586
|
-
if (khmer.khmer.monthIndex === MonthIndex.
|
|
587
|
-
console.log("It is
|
|
593
|
+
if (khmer.khmer.monthIndex === MonthIndex.Migasir) {
|
|
594
|
+
console.log("It is Migasir month!");
|
|
588
595
|
}
|
|
589
596
|
|
|
590
597
|
// Check day of week
|
|
@@ -602,7 +609,7 @@ const { MoonPhase, MonthIndex } = momentkh;
|
|
|
602
609
|
const date1 = momentkh.fromKhmer(
|
|
603
610
|
15, // day
|
|
604
611
|
MoonPhase.Waxing, // instead of 0
|
|
605
|
-
MonthIndex.
|
|
612
|
+
MonthIndex.Pisakh, // instead of 5
|
|
606
613
|
2568
|
|
607
614
|
);
|
|
608
615
|
|
|
@@ -622,14 +629,14 @@ const khmer = momentkh.fromGregorian(2024, 12, 16);
|
|
|
622
629
|
|
|
623
630
|
// Switch on month
|
|
624
631
|
switch (khmer.khmer.monthIndex) {
|
|
625
|
-
case MonthIndex.
|
|
632
|
+
case MonthIndex.Migasir:
|
|
626
633
|
case MonthIndex.Bos:
|
|
627
634
|
case MonthIndex.Meak:
|
|
628
635
|
console.log("Winter months");
|
|
629
636
|
break;
|
|
630
|
-
case MonthIndex.
|
|
631
|
-
case MonthIndex.
|
|
632
|
-
case MonthIndex.
|
|
637
|
+
case MonthIndex.Phalkun:
|
|
638
|
+
case MonthIndex.Cheit:
|
|
639
|
+
case MonthIndex.Pisakh:
|
|
633
640
|
console.log("Spring months");
|
|
634
641
|
break;
|
|
635
642
|
// ... more cases
|
|
@@ -666,14 +673,14 @@ const month: MonthIndex = result.khmer.monthIndex;
|
|
|
666
673
|
const date = momentkh.fromKhmer(
|
|
667
674
|
15,
|
|
668
675
|
MoonPhase. // โ IDE shows: Waxing, Waning
|
|
669
|
-
MonthIndex. // โ IDE shows:
|
|
676
|
+
MonthIndex. // โ IDE shows: Migasir, Bos, Meak, etc.
|
|
670
677
|
2568
|
|
671
678
|
);
|
|
672
679
|
```
|
|
673
680
|
|
|
674
681
|
### Benefits of Using Enums
|
|
675
682
|
|
|
676
|
-
1. ๐ **Readability**: `MonthIndex.
|
|
683
|
+
1. ๐ **Readability**: `MonthIndex.Pisakh` is clearer than `5`
|
|
677
684
|
2. ๐ก๏ธ **Type Safety**: TypeScript catches invalid values at compile time
|
|
678
685
|
3. โก **Autocomplete**: IDEs show all available options
|
|
679
686
|
4. ๐ง **Maintainability**: Easier to understand code months later
|
|
@@ -686,8 +693,8 @@ const date = momentkh.fromKhmer(
|
|
|
686
693
|
|
|
687
694
|
```javascript
|
|
688
695
|
// All of these work:
|
|
689
|
-
momentkh.fromKhmer(15, MoonPhase.Waxing, MonthIndex.
|
|
690
|
-
momentkh.fromKhmer(15, 0, MonthIndex.
|
|
696
|
+
momentkh.fromKhmer(15, MoonPhase.Waxing, MonthIndex.Pisakh, 2568); // โจ New enum way
|
|
697
|
+
momentkh.fromKhmer(15, 0, MonthIndex.Pisakh, 2568); // ๐ Mixed
|
|
691
698
|
momentkh.fromKhmer(15, MoonPhase.Waxing, 5, 2568); // ๐ Mixed
|
|
692
699
|
momentkh.fromKhmer(15, 0, 5, 2568); // ๐ Old way still works!
|
|
693
700
|
```
|
|
@@ -704,15 +711,15 @@ The Khmer calendar is a **lunisolar calendar** that tracks both the moon phases
|
|
|
704
711
|
|
|
705
712
|
**Full Name:** แแปแแแแแแแถแ (Putthsak, Buddhist Era)
|
|
706
713
|
**Offset from Gregorian:** +543 or +544
|
|
707
|
-
**When it increases:** At midnight (00:00) on the **
|
|
714
|
+
**When it increases:** At midnight (00:00) on the **1st waning day of Pisakh month** (แกแแแ
แแแแทแแถแ)
|
|
708
715
|
|
|
709
716
|
**Example Timeline:**
|
|
710
717
|
|
|
711
718
|
```
|
|
712
|
-
2024-05-22 23:59 โ
|
|
713
|
-
2024-05-23 00:00 โ
|
|
714
|
-
2024-05-23 23:59 โ
|
|
715
|
-
2024-05-24 00:00 โ
|
|
719
|
+
2024-05-22 23:59 โ 15แแพแ Pisakh, BE 2567
|
|
720
|
+
2024-05-23 00:00 โ 1แแแ
Pisakh, BE 2568 (NEW year starts!)
|
|
721
|
+
2024-05-23 23:59 โ 1แแแ
Pisakh, BE 2568
|
|
722
|
+
2024-05-24 00:00 โ 2แแแ
Pisakh, BE 2568
|
|
716
723
|
```
|
|
717
724
|
|
|
718
725
|
**Important:**
|
|
@@ -781,13 +788,13 @@ console.log(at.khmer.animalYear); // 'แแแถ' (Rooster) - Changed!
|
|
|
781
788
|
|
|
782
789
|
---
|
|
783
790
|
|
|
784
|
-
###
|
|
791
|
+
### Sak
|
|
785
792
|
|
|
786
793
|
**Full Name:** แแแ (Sak, Era)
|
|
787
794
|
**Cycle:** 10 years
|
|
788
795
|
**When it increases:** At **midnight (00:00) of the last day** of Khmer New Year celebration (Lerng Sak - แแแแแกแพแแแแ)
|
|
789
796
|
|
|
790
|
-
**The 10
|
|
797
|
+
**The 10 Saks (in order):**
|
|
791
798
|
| Index | Khmer | Romanization |
|
|
792
799
|
|-------|-------|--------------|
|
|
793
800
|
| 0 | แแแแนแแแแทแแแ | Samridhi Sak |
|
|
@@ -805,19 +812,19 @@ console.log(at.khmer.animalYear); // 'แแแถ' (Rooster) - Changed!
|
|
|
805
812
|
|
|
806
813
|
- ๐ **Day 1:** Moha Songkran (แแ แถแแแแแแแถแแแ) - New Year's Day
|
|
807
814
|
- ๐ **Day 2:** Virak Wanabat (แแธแแแแแแแ) - Second day
|
|
808
|
-
- โญ **Day 3 or 4:** Lerng Sak (แแแแแกแพแแแแ) - Last day &
|
|
815
|
+
- โญ **Day 3 or 4:** Lerng Sak (แแแแแกแพแแแแ) - Last day & Sak change day
|
|
809
816
|
|
|
810
817
|
**Example:**
|
|
811
818
|
|
|
812
819
|
```javascript
|
|
813
820
|
// 2024 New Year is on April 13, 22:24
|
|
814
|
-
// Lerng Sak (
|
|
821
|
+
// Lerng Sak (Sak change) is typically 3-4 days later at midnight
|
|
815
822
|
|
|
816
823
|
const newYearDay = momentkh.fromGregorian(2024, 4, 13, 23, 0);
|
|
817
|
-
console.log(newYearDay.khmer.
|
|
824
|
+
console.log(newYearDay.khmer.sak); // 'แแแแ' (still old sak)
|
|
818
825
|
|
|
819
826
|
const lerngSakDay = momentkh.fromGregorian(2024, 4, 17, 0, 0); // Midnight of Lerng Sak
|
|
820
|
-
console.log(lerngSakDay.khmer.
|
|
827
|
+
console.log(lerngSakDay.khmer.sak); // 'แแแแแแแ' (new sak!)
|
|
821
828
|
```
|
|
822
829
|
|
|
823
830
|
---
|
|
@@ -826,20 +833,20 @@ console.log(lerngSakDay.khmer.eraYear); // 'แแแแแแแ' (new era!)
|
|
|
826
833
|
|
|
827
834
|
**Summary Table:**
|
|
828
835
|
|
|
829
|
-
| Year Type | Changes At
|
|
830
|
-
| --------------- |
|
|
831
|
-
| **BE Year** | 00:00
|
|
832
|
-
| **Animal Year** | แแแแ แแทแ แแถแแธแแแแแถแ
แปแ
|
|
833
|
-
| **
|
|
836
|
+
| Year Type | Changes At | Example Date/Time |
|
|
837
|
+
| --------------- | ------------------------ | -------------------- |
|
|
838
|
+
| **BE Year** | 00:00 แแ
แแแแแกแแแ
แแแแทแแถแ | May 23, 2024 00:00 |
|
|
839
|
+
| **Animal Year** | แแแแ แแทแ แแถแแธแแแแแถแ
แปแ | April 13, 2024 22:17 |
|
|
840
|
+
| **Sak** | 00:00 แแ
แแแแแกแพแแแแ | April 16, 2024 00:00 |
|
|
834
841
|
|
|
835
842
|
**Visual Timeline for 2024:**
|
|
836
843
|
|
|
837
844
|
```
|
|
838
|
-
April 13, 22:23 โ BE 2567, Monkey (แแ), Old
|
|
839
|
-
April 13, 22:24 โ BE 2567, Rooster (แแแถ), Old
|
|
840
|
-
April 17, 00:00 โ BE 2567, Rooster (แแแถ), New
|
|
841
|
-
May 22, 23:59 โ BE 2567, Rooster (แแแถ), New
|
|
842
|
-
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
|
|
843
850
|
```
|
|
844
851
|
|
|
845
852
|
---
|
|
@@ -848,26 +855,39 @@ May 23, 00:00 โ BE 2568, Rooster (แแแถ), New Era (แแแแแแแ
|
|
|
848
855
|
|
|
849
856
|
Complete list of format tokens for the `format()` function:
|
|
850
857
|
|
|
851
|
-
| Token | Output | Description
|
|
852
|
-
| ---------------------- | ----------------- |
|
|
858
|
+
| Token | Output | Description | Example |
|
|
859
|
+
| ---------------------- | ----------------- | ------------------------------ | --------------------- |
|
|
853
860
|
| **๐
Date Components** |
|
|
854
|
-
| `W` | แแแแแแแแแแแถแ แแแแ | Weekday name (full)
|
|
855
|
-
| `w` | แแแแแแแแแแแถแ แแแแแธ | Weekday name (short)
|
|
856
|
-
| `d` | แแแแแแธ | Lunar day number
|
|
857
|
-
| `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) | แ แก, แ แฅ, แกแฅ |
|
|
858
865
|
| **๐ Moon Phase** |
|
|
859
|
-
| `n` | แแพแ/แแแ
(แแแแธ) | Moon phase (short)
|
|
860
|
-
| `N` | แแพแ/แแแ
(แแแ) | Moon phase (full)
|
|
861
|
-
| `o` | แแทแแทแแแแแแแแถ | Moon day symbol
|
|
866
|
+
| `n` | แแพแ/แแแ
(แแแแธ) | Moon phase (short) | แ, แ |
|
|
867
|
+
| `N` | แแพแ/แแแ
(แแแ) | Moon phase (full) | แแพแ, แแแ
|
|
|
868
|
+
| `o` | แแทแแทแแแแแแแแถ | Moon day symbol | แงก, แงข, แงฃ ... แงฟ |
|
|
862
869
|
| **๐ Month Names** |
|
|
863
|
-
| `m` | แแแ
แแแแแแท | Lunar month name
|
|
864
|
-
| `
|
|
870
|
+
| `m` | แแแ
แแแแแแท | Lunar month name | แแทแแแทแ, แแปแแแ, แ
แแแแ |
|
|
871
|
+
| `ms` | แแ (แแแแแแ) | Lunar month name (abbreviated) | แแท, แแป |
|
|
872
|
+
| `Ms` | แแ (แแแแแแ) | Solar month name (abbreviated) | แแ, แแ |
|
|
873
|
+
| `M` | แแแแปแแทแแแแท | Solar month name | แแแแถ, แแปแแแแ, แแแแถ |
|
|
865
874
|
| **โฐ Year Components** |
|
|
866
|
-
| `a` | แแแแถแแแแแ | Animal year
|
|
867
|
-
| `
|
|
868
|
-
| `
|
|
869
|
-
| `
|
|
870
|
-
| `
|
|
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) | แขแถ, แ
, แข |
|
|
871
891
|
|
|
872
892
|
**Format Examples:**
|
|
873
893
|
|
|
@@ -911,8 +931,13 @@ momentkh.constants.AnimalYearNames;
|
|
|
911
931
|
// ['แแผแ', 'แแแแผแ', 'แแถแ', 'แแแ', 'แแแ', 'แแแแถแแ',
|
|
912
932
|
// 'แแแธ', 'แแแ', 'แแ', 'แแแถ', 'แ
', 'แแปแ']
|
|
913
933
|
|
|
914
|
-
//
|
|
915
|
-
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;
|
|
916
941
|
// ['แแแแนแแแแทแแแ', 'แฏแแแแ', 'แแแแแ', 'แแแแธแแแ', 'แ
แแแแถแแแ',
|
|
917
942
|
// 'แแแแ
แแแ', 'แแแแ', 'แแแแแแแ', 'แขแแแแแแ', 'แแแแแแแ']
|
|
918
943
|
|
|
@@ -921,7 +946,7 @@ momentkh.constants.WeekdayNames;
|
|
|
921
946
|
// ['แขแถแแทแแแ', 'แ
แแแ', 'แขแแแแถแ', 'แแปแ', 'แแแแ แแแแแทแ', 'แแปแแแ', 'แแ
แแ']
|
|
922
947
|
|
|
923
948
|
// Moon phase names array (indices 0-1)
|
|
924
|
-
momentkh.constants.
|
|
949
|
+
momentkh.constants.MoonPhaseNames;
|
|
925
950
|
// ['แแพแ', 'แแแ
']
|
|
926
951
|
```
|
|
927
952
|
|
|
@@ -1122,7 +1147,7 @@ console.log(
|
|
|
1122
1147
|
);
|
|
1123
1148
|
console.log("BE Year:", khmer.khmer.beYear);
|
|
1124
1149
|
console.log("Animal Year:", khmer.khmer.animalYear);
|
|
1125
|
-
console.log("
|
|
1150
|
+
console.log("Sak:", khmer.khmer.sak);
|
|
1126
1151
|
console.log("Month:", khmer.khmer.monthName);
|
|
1127
1152
|
console.log(
|
|
1128
1153
|
"Day:",
|
|
@@ -1133,7 +1158,7 @@ console.log(
|
|
|
1133
1158
|
// Gregorian: 14/4/2024
|
|
1134
1159
|
// BE Year: 2568
|
|
1135
1160
|
// Animal Year: แแแ
|
|
1136
|
-
//
|
|
1161
|
+
// Sak: แแแแ
|
|
1137
1162
|
// Month: แ
แแแแ
|
|
1138
1163
|
// Day: 6แแพแ
|
|
1139
1164
|
```
|
|
@@ -1270,7 +1295,7 @@ for (let day = 20; day <= 25; day++) {
|
|
|
1270
1295
|
|
|
1271
1296
|
MIT License - Same as original momentkh
|
|
1272
1297
|
|
|
1273
|
-
Copyright (c)
|
|
1298
|
+
Copyright (c) 2025
|
|
1274
1299
|
|
|
1275
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:
|
|
1276
1301
|
|
|
@@ -1283,10 +1308,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
1283
1308
|
## ๐ Credits & References
|
|
1284
1309
|
|
|
1285
1310
|
- **Original momentkh library** by [Thyrith Sor](https://github.com/ThyrithSor)
|
|
1286
|
-
- **Algorithm based on:**
|
|
1287
|
-
- Traditional Khmer astronomical calculations
|
|
1288
|
-
- "Pratitin Soryakkatik-Chankatik 1900-1999" by Mr. Roath Kim Soeun
|
|
1289
|
-
- Khmer calendar C++ reference implementation
|
|
1290
1311
|
- **Resources:**
|
|
1291
1312
|
- [CAM-CC: Khmer Calendar](http://www.cam-cc.org)
|
|
1292
1313
|
- [Dahlina: Khmer New Year Calculation](http://www.dahlina.com/education/khmer_new_year_time.html)
|
|
@@ -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
|