@thyrith/momentkh 2.4.0 β 2.5.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 +24 -3
- package/constant.js +11 -4
- package/example/newYearMoment.js +4 -0
- package/example/toKhDate.js +6 -0
- package/getSoriyatraLerngSak.js +23 -7
- package/index.html +169 -0
- package/locale/km.js +15 -3
- package/momentkh.js +104 -49
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[]()
|
|
6
6
|
|
|
7
7
|
# momentkh
|
|
8
|
-
momentkh is an add-on feature to moment js library
|
|
8
|
+
momentkh is an add-on feature to moment js library [DEMO](https://thyrithsor.github.io/momentkh).
|
|
9
9
|
|
|
10
10
|
## Install π
|
|
11
11
|
```
|
|
@@ -17,6 +17,7 @@ $ npm install @thyrith/momentkh --save
|
|
|
17
17
|
This library is built depends on [moment.js](https://momentjs.com) popular library.
|
|
18
18
|
We added some functionality to make it easier to work with Khmer date format.
|
|
19
19
|
|
|
20
|
+
### Nodejs
|
|
20
21
|
```javascript
|
|
21
22
|
const moment = require('moment');
|
|
22
23
|
// Add our features to your preferred moment.js version
|
|
@@ -37,6 +38,25 @@ console.log(khmerDate);
|
|
|
37
38
|
// For example: αααααα
αα α¨ααΎα αααα·ααα·α ααααΆαα
ααααΉαααααα αα»αααααααΆα α’α₯α¦α’
|
|
38
39
|
```
|
|
39
40
|
|
|
41
|
+
### HTML
|
|
42
|
+
First, you need to clone this package to the root of your project or your `/public` folder.
|
|
43
|
+
|
|
44
|
+
\*\*\* *For `momentjs` library, you can import it any method or any version you want.*
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
|
|
48
|
+
<script src="momentkh/constant.js"></script>
|
|
49
|
+
<script src="momentkh/locale/km.js"></script>
|
|
50
|
+
<script src="momentkh/getSoriyatraLerngSak.js"></script>
|
|
51
|
+
<script src="momentkh/momentkh.js"></script>
|
|
52
|
+
<script>
|
|
53
|
+
var moment = momentkh(moment)
|
|
54
|
+
var today = moment()
|
|
55
|
+
console.log('Today: ', today.toKhDate())
|
|
56
|
+
console.log('New year at: ', moment.getKhNewYearMoment(2021))
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
40
60
|
## Added Functionality π‘
|
|
41
61
|
|
|
42
62
|
#### Attributes of moment instance
|
|
@@ -86,7 +106,8 @@ myBirthday.toLunarDate('dN ααααW ααm α.α. b');
|
|
|
86
106
|
| n | ααΎα α¬ ααα
| α |
|
|
87
107
|
| N | ααΎα α¬ ααα
| ααΎα |
|
|
88
108
|
| o | αααααααααααααΈα’αααΈααααααΈ | α§‘ (ααΆααααααΆ α‘ααΎα)|
|
|
89
|
-
| m |
|
|
109
|
+
| m | ααα
αααααα· | αα·ααα·α |
|
|
110
|
+
| M | αααα»αα·αααα· | ααααΆ |
|
|
90
111
|
| a | ααααΆααααα | αααΆ |
|
|
91
112
|
| e | ααα | α―αααα |
|
|
92
113
|
| b | ααααΆααα»αααααααΆα | α’α₯α₯α¦ |
|
|
@@ -109,4 +130,4 @@ Welcome pull request
|
|
|
109
130
|
# Support me
|
|
110
131
|
I'm really happy if this project is useful to you.
|
|
111
132
|
|
|
112
|
-
If you would like to buy me some breakfast, here is my ABA account number: **000 485 222**. Don't forget to remark `momentkh` so that I can count it as usefulness of my work.
|
|
133
|
+
If you would like to buy me some breakfast, here is my ABA account number: **000 485 222**. Don't forget to remark `momentkh` so that I can count it as usefulness of my work.
|
package/constant.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
;(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined'
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
3
|
+
module.exports = factory()
|
|
4
|
+
} else {
|
|
5
|
+
if (typeof define === 'function' && define.amd) {
|
|
6
|
+
define(factory)
|
|
7
|
+
} else {
|
|
8
|
+
global.momentkhConstant = factory()
|
|
9
|
+
}
|
|
10
|
+
}
|
|
5
11
|
}(this, (function () {
|
|
6
12
|
'use strict';
|
|
7
13
|
|
|
@@ -33,11 +39,12 @@
|
|
|
33
39
|
// ααααΆαααΎαααααα½αα
ααα½αααααα»αααΈααΆαααααΆ
|
|
34
40
|
const khNewYearMoments = {
|
|
35
41
|
'1879' : '12-04-1879 11:36',
|
|
42
|
+
'1897' : '13-04-1897 02:00',
|
|
36
43
|
'2011' : '14-04-2011 13:12',
|
|
37
44
|
'2012' : '14-04-2012 19:11',
|
|
38
45
|
'2013' : '14-04-2013 02:12',
|
|
39
46
|
'2014' : '14-04-2014 08:07',
|
|
40
|
-
'2015' : '14-04-2015 14:02'
|
|
47
|
+
'2015' : '14-04-2015 14:02',
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
return {
|
package/getSoriyatraLerngSak.js
CHANGED
|
@@ -5,15 +5,31 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
;(function (global, factory) {
|
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined'
|
|
9
|
-
|
|
8
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
9
|
+
module.exports = factory
|
|
10
|
+
} else {
|
|
11
|
+
if (typeof define === 'function' && define.amd) {
|
|
12
|
+
define(factory)
|
|
13
|
+
} else {
|
|
10
14
|
global.getSoriyatraLerngSak = factory
|
|
15
|
+
}
|
|
16
|
+
}
|
|
11
17
|
}(this, (function (jsYear) {
|
|
12
18
|
'use strict';
|
|
13
19
|
|
|
14
20
|
return (function (jsYear) {
|
|
15
21
|
|
|
16
|
-
let
|
|
22
|
+
let LunarMonths;
|
|
23
|
+
|
|
24
|
+
if (typeof require === 'function') {
|
|
25
|
+
LunarMonths = require('./constant').LunarMonths;
|
|
26
|
+
} else {
|
|
27
|
+
if (!window.momentkhConstant) {
|
|
28
|
+
throw "Please import [MOMENTKH]/constant.js to your project"
|
|
29
|
+
} else {
|
|
30
|
+
LunarMonths = window.momentkhConstant.LunarMonths;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
17
33
|
|
|
18
34
|
/**
|
|
19
35
|
* ααααΆ α αΆααα»α Kromathopol α’αααΆα αα·α ααΌαα·ααΈ
|
|
@@ -125,7 +141,7 @@
|
|
|
125
141
|
}
|
|
126
142
|
return {
|
|
127
143
|
day: bodithey >= 6 ? bodithey - 1 : bodithey,
|
|
128
|
-
month: bodithey >= 6 ? LunarMonths
|
|
144
|
+
month: bodithey >= 6 ? LunarMonths['α
αααα'] : LunarMonths['αα·ααΆα']
|
|
129
145
|
};
|
|
130
146
|
})();
|
|
131
147
|
|
|
@@ -239,7 +255,7 @@
|
|
|
239
255
|
}
|
|
240
256
|
|
|
241
257
|
let newYearsDaySotins = (function () { // α
ααα½αααααααααα
|
|
242
|
-
let sotins = getHas366day(jsYear - 1) ? [363,364,365,366] : [362,363,364,365]; // αα»αα·α
|
|
258
|
+
let sotins = getHas366day(jsYear - 1) ? [363, 364, 365, 366] : [362, 363, 364, 365]; // αα»αα·α
|
|
243
259
|
return sotins.map(function (sotin) {
|
|
244
260
|
let sunInfo = getSunInfo(sotin);
|
|
245
261
|
return {
|
|
@@ -255,7 +271,7 @@
|
|
|
255
271
|
let sotinNewYear = newYearsDaySotins.filter(function (sotin) {
|
|
256
272
|
return sotin.angsar === 0;
|
|
257
273
|
});
|
|
258
|
-
if (sotinNewYear.length
|
|
274
|
+
if (sotinNewYear.length > 0) {
|
|
259
275
|
let libda = sotinNewYear[0].libda; // α’α€ αααα ααΆα α¦α αα·ααααΆ
|
|
260
276
|
let minutes = (24 * 60) - (libda * 24)
|
|
261
277
|
return {
|
|
@@ -263,7 +279,7 @@
|
|
|
263
279
|
minute: minutes % 60
|
|
264
280
|
}
|
|
265
281
|
} else {
|
|
266
|
-
Error('Plugin is facing wrong calculation on new years hour');
|
|
282
|
+
throw Error('Plugin is facing wrong calculation on new years hour. No sotin with angsar = 0');
|
|
267
283
|
}
|
|
268
284
|
})();
|
|
269
285
|
|
package/index.html
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<!-- To branch gh-pages -->
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>MomentKH</title>
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
8
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
9
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
|
+
<link href="https://fonts.googleapis.com/css2?family=Koh+Santepheap:wght@300&family=Moulpali&display=swap" rel="stylesheet">
|
|
11
|
+
<link rel="stylesheet" href="https://bootswatch.com/5/superhero/bootstrap.min.css">
|
|
12
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
|
13
|
+
|
|
14
|
+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
|
|
15
|
+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
|
16
|
+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
|
|
17
|
+
|
|
18
|
+
<style>
|
|
19
|
+
body {
|
|
20
|
+
font-family: 'Koh Santepheap', cursive;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.pali {
|
|
24
|
+
font-family: 'Moulpali', cursive;
|
|
25
|
+
line-height: 2.5rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.vdp-datepicker__calendar {
|
|
29
|
+
background-color: #4e5d6c !important;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div id="app">
|
|
35
|
+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
36
|
+
<div class="container">
|
|
37
|
+
<a class="navbar-brand" href="#">momentkh</a>
|
|
38
|
+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor02" aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation">
|
|
39
|
+
<span class="navbar-toggler-icon"></span>
|
|
40
|
+
</button>
|
|
41
|
+
|
|
42
|
+
<div class="collapse navbar-collapse" id="navbarColor02">
|
|
43
|
+
<ul class="navbar-nav me-auto">
|
|
44
|
+
<li class="nav-item">
|
|
45
|
+
<a class="nav-link active" href="#">Demo
|
|
46
|
+
<span class="visually-hidden">(current)</span>
|
|
47
|
+
</a>
|
|
48
|
+
</li>
|
|
49
|
+
<!-- <li class="nav-item">
|
|
50
|
+
<a class="nav-link" href="#">Support</a>
|
|
51
|
+
</li> -->
|
|
52
|
+
</ul>
|
|
53
|
+
<ul class="navbar-nav ms-md-auto">
|
|
54
|
+
<li class="nav-item">
|
|
55
|
+
<a target="_blank" rel="noopener" class="nav-link" href="https://github.com/ThyrithSor/momentkh"><i class="fa fa-github"></i> GitHub</a>
|
|
56
|
+
</li>
|
|
57
|
+
<li class="nav-item">
|
|
58
|
+
<a target="_blank" rel="noopener" class="nav-link" href="https://www.npmjs.com/package/@thyrith/momentkh">
|
|
59
|
+
<svg height="30px" aria-hidden="true" focusable="false" data-prefix="fab" data-icon="npm" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-npm fa-w-18 fa-3x"><path fill="currentColor" d="M288 288h-32v-64h32v64zm288-128v192H288v32H160v-32H0V160h576zm-416 32H32v128h64v-96h32v96h32V192zm160 0H192v160h64v-32h64V192zm224 0H352v128h64v-96h32v96h32v-96h32v96h32V192z" class=""></path></svg>
|
|
60
|
+
NPM
|
|
61
|
+
</a>
|
|
62
|
+
</li>
|
|
63
|
+
</ul>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</nav>
|
|
67
|
+
<div class="container">
|
|
68
|
+
<h1 class="mt-5 mb-2">
|
|
69
|
+
ααααα·αα·αααααα β momentkh
|
|
70
|
+
</h1>
|
|
71
|
+
<h2 class="my-4">
|
|
72
|
+
<svg style="margin-right: 10px;" height="30px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="calendar-alt" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-calendar-alt fa-w-14 fa-2x"><path fill="currentColor" d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z" class=""></path></svg>
|
|
73
|
+
ααααααααΆαααα·α
ααααααΈ moment instance αα
ααΆαααα·α
ααααααααα</h2>
|
|
74
|
+
<div class="row my-5">
|
|
75
|
+
<p class="col-12 text-center">
|
|
76
|
+
{{ displayedDate }}
|
|
77
|
+
</p>
|
|
78
|
+
<div class="text-center py-4">
|
|
79
|
+
<svg style="transform: rotate(180deg); height: 40px;" aria-hidden="true" focusable="false" data-prefix="far" data-icon="hand-pointer" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-hand-pointer fa-w-14 fa-3x"><path fill="currentColor" d="M358.182 179.361c-19.493-24.768-52.679-31.945-79.872-19.098-15.127-15.687-36.182-22.487-56.595-19.629V67c0-36.944-29.736-67-66.286-67S89.143 30.056 89.143 67v161.129c-19.909-7.41-43.272-5.094-62.083 8.872-29.355 21.795-35.793 63.333-14.55 93.152l109.699 154.001C134.632 501.59 154.741 512 176 512h178.286c30.802 0 57.574-21.5 64.557-51.797l27.429-118.999A67.873 67.873 0 0 0 448 326v-84c0-46.844-46.625-79.273-89.818-62.639zM80.985 279.697l27.126 38.079c8.995 12.626 29.031 6.287 29.031-9.283V67c0-25.12 36.571-25.16 36.571 0v175c0 8.836 7.163 16 16 16h6.857c8.837 0 16-7.164 16-16v-35c0-25.12 36.571-25.16 36.571 0v35c0 8.836 7.163 16 16 16H272c8.837 0 16-7.164 16-16v-21c0-25.12 36.571-25.16 36.571 0v21c0 8.836 7.163 16 16 16h6.857c8.837 0 16-7.164 16-16 0-25.121 36.571-25.16 36.571 0v84c0 1.488-.169 2.977-.502 4.423l-27.43 119.001c-1.978 8.582-9.29 14.576-17.782 14.576H176c-5.769 0-11.263-2.878-14.697-7.697l-109.712-154c-14.406-20.223 14.994-42.818 29.394-22.606zM176.143 400v-96c0-8.837 6.268-16 14-16h6c7.732 0 14 7.163 14 16v96c0 8.837-6.268 16-14 16h-6c-7.733 0-14-7.163-14-16zm75.428 0v-96c0-8.837 6.268-16 14-16h6c7.732 0 14 7.163 14 16v96c0 8.837-6.268 16-14 16h-6c-7.732 0-14-7.163-14-16zM327 400v-96c0-8.837 6.268-16 14-16h6c7.732 0 14 7.163 14 16v96c0 8.837-6.268 16-14 16h-6c-7.732 0-14-7.163-14-16z" class=""></path></svg>
|
|
80
|
+
</div>
|
|
81
|
+
<p class="pali col-12 text-center" v-html="displayedKhmerDate"></p>
|
|
82
|
+
</div>
|
|
83
|
+
<h2 class="my-4">
|
|
84
|
+
<svg style="margin-right: 10px;" height="30px" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="clock" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-clock fa-w-16 fa-3x"><path fill="currentColor" d="M256,8C119,8,8,119,8,256S119,504,256,504,504,393,504,256,393,8,256,8Zm92.49,313h0l-20,25a16,16,0,0,1-22.49,2.5h0l-67-49.72a40,40,0,0,1-15-31.23V112a16,16,0,0,1,16-16h32a16,16,0,0,1,16,16V256l58,42.5A16,16,0,0,1,348.49,321Z" class=""></path></svg>
|
|
85
|
+
αααααααααααΆα
α»α α α.α.
|
|
86
|
+
<vuejs-datepicker
|
|
87
|
+
:value="formattedDate"
|
|
88
|
+
:format="DatePickerFormat"
|
|
89
|
+
:language="language"
|
|
90
|
+
@selected="pickedYear"
|
|
91
|
+
minimum-view="year"
|
|
92
|
+
name="datepicker"
|
|
93
|
+
id="input-id"
|
|
94
|
+
wrapper-class="d-inline-block"
|
|
95
|
+
input-class="btn btn-secondary"></vuejs-datepicker>
|
|
96
|
+
</h2>
|
|
97
|
+
<div class="row my-5">
|
|
98
|
+
<p class="pali col-12 text-center">
|
|
99
|
+
{{ newYearMoment }}
|
|
100
|
+
</p>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
|
|
105
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
|
|
106
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/locale/km.min.js"></script>
|
|
107
|
+
<script src="https://unpkg.com/vuejs-datepicker"></script>
|
|
108
|
+
<script src="./constant.js"></script>
|
|
109
|
+
<script src="./locale/km.js"></script>
|
|
110
|
+
<script src="./getSoriyatraLerngSak.js"></script>
|
|
111
|
+
<script src="./momentkh.js"></script>
|
|
112
|
+
<script>
|
|
113
|
+
window.onload = function() {
|
|
114
|
+
var moment = momentkh(window.moment)
|
|
115
|
+
|
|
116
|
+
new Vue({
|
|
117
|
+
el: "#app",
|
|
118
|
+
data() {
|
|
119
|
+
return {
|
|
120
|
+
format: 'dN ααm ααααΆαa e α.α. b',
|
|
121
|
+
now: moment(),
|
|
122
|
+
date: moment(),
|
|
123
|
+
DatePickerFormat: 'yyyy',
|
|
124
|
+
language: {
|
|
125
|
+
language: 'Khmer',
|
|
126
|
+
months: ['ααααΆ', 'αα»αααα', 'ααΈααΆ', 'ααααΆ', 'α§αααΆ', 'αα·αα»ααΆ', 'ααααααΆ', 'ααΈα αΆ', 'αααααΆ', 'αα»ααΆ', 'αα·α
ααα·ααΆ', 'ααααΌ'],
|
|
127
|
+
monthsAbbr: ['ααααΆ', 'αα»αααα', 'ααΈααΆ', 'ααααΆ', 'α§αααΆ', 'αα·αα»ααΆ', 'ααααααΆ', 'ααΈα αΆ', 'αααααΆ', 'αα»ααΆ', 'αα·α
ααα·ααΆ', 'ααααΌ'],
|
|
128
|
+
days: ['α’αΆαα·ααα', 'α
ααα', 'α’ααααΆα', 'αα»α', 'αααα ααααααα·α', 'αα»ααα', 'αα
α'],
|
|
129
|
+
rtl: false,
|
|
130
|
+
ymd: false,
|
|
131
|
+
yearSuffix: ''
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
computed: {
|
|
136
|
+
year() {
|
|
137
|
+
return this.date.year()
|
|
138
|
+
},
|
|
139
|
+
formattedDate() {
|
|
140
|
+
return this.date.locale('en').format('YYYY-MM-DD')
|
|
141
|
+
},
|
|
142
|
+
displayedDate() {
|
|
143
|
+
return this.now
|
|
144
|
+
},
|
|
145
|
+
displayedKhmerDate() {
|
|
146
|
+
return this.now.locale('km').format('ααααdddd ααΈDD ααMMMM ααααΆαYYYY') + '<br/>ααααΌαααΉα<br/>ααααααΈ ' + this.now.toKhDate(this.format) + '<br/>' + this.now.locale('km').format('h:mm:ss a')
|
|
147
|
+
},
|
|
148
|
+
newYearMoment() {
|
|
149
|
+
return moment.getKhNewYearMoment(this.year).locale('km').format('ααααdddd ααΈDD ααMMMM ααααΆαYYYY ααααΆαααα h:mm ααΆααΈ a')
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
methods: {
|
|
153
|
+
pickedYear(year) {
|
|
154
|
+
this.date = moment(year)
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
mounted() {
|
|
158
|
+
setInterval(() => {
|
|
159
|
+
this.now = moment()
|
|
160
|
+
}, 1000)
|
|
161
|
+
},
|
|
162
|
+
components: {
|
|
163
|
+
'vuejs-datepicker':vuejsDatepicker
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
</script>
|
|
168
|
+
</body>
|
|
169
|
+
</html>
|
package/locale/km.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
//! moment.js locale configuration
|
|
2
2
|
|
|
3
3
|
;(function (global, factory) {
|
|
4
|
-
typeof exports === 'object' && typeof module !== 'undefined'
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
5
|
+
module.exports = factory()
|
|
6
|
+
} else {
|
|
7
|
+
if (typeof define === 'function' && define.amd) {
|
|
8
|
+
define(factory)
|
|
9
|
+
} else {
|
|
10
|
+
if (!global.momentkhLocales) {
|
|
11
|
+
global.momentkhLocales = {
|
|
12
|
+
'km': factory()
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
global.momentkhLocales['km'] = factory()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
}(this, (function () {
|
|
8
20
|
'use strict';
|
|
9
21
|
|
package/momentkh.js
CHANGED
|
@@ -13,17 +13,44 @@
|
|
|
13
13
|
|
|
14
14
|
// const Moment = require('moment');
|
|
15
15
|
function getLocaleConfig() {
|
|
16
|
-
|
|
16
|
+
if (typeof require === 'function') {
|
|
17
|
+
return require('./locale/km')
|
|
18
|
+
} else {
|
|
19
|
+
if (!this.momentkhLocales) {
|
|
20
|
+
throw "Please import [MOMENTKH]/locale/km.js to your project"
|
|
21
|
+
} else {
|
|
22
|
+
return this.momentkhLocales['km']
|
|
23
|
+
}
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
let config = getLocaleConfig();
|
|
20
28
|
|
|
21
|
-
let
|
|
29
|
+
let constant, LunarMonths, SolarMonth, MoonStatus, khNewYearMoments;
|
|
30
|
+
if (typeof require === 'function') {
|
|
31
|
+
constant = require('./constant')
|
|
32
|
+
} else {
|
|
33
|
+
if (!this.momentkhConstant) {
|
|
34
|
+
throw "Please import [MOMENTKH]/constant.js to your project"
|
|
35
|
+
} else {
|
|
36
|
+
constant = this.momentkhConstant
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
LunarMonths = constant.LunarMonths
|
|
40
|
+
SolarMonth = constant.SolarMonth
|
|
41
|
+
MoonStatus = constant.MoonStatus
|
|
42
|
+
khNewYearMoments = constant.khNewYearMoments
|
|
22
43
|
|
|
23
44
|
;(function (global, factory) {
|
|
24
|
-
typeof exports === 'object' && typeof module !== 'undefined'
|
|
25
|
-
|
|
45
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
46
|
+
module.exports = factory
|
|
47
|
+
} else {
|
|
48
|
+
if (typeof define === 'function' && define.amd) {
|
|
49
|
+
define(factory)
|
|
50
|
+
} else {
|
|
26
51
|
global.momentkh = factory
|
|
52
|
+
}
|
|
53
|
+
}
|
|
27
54
|
}(this, (function (Moment) {
|
|
28
55
|
'use strict';
|
|
29
56
|
|
|
@@ -193,10 +220,10 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
193
220
|
* @returns {number}
|
|
194
221
|
*/
|
|
195
222
|
function getNumberOfDayInKhmerMonth(beMonth, beYear) {
|
|
196
|
-
if (beMonth === LunarMonths
|
|
223
|
+
if (beMonth === LunarMonths['ααααα'] && isKhmerLeapDay(beYear)) {
|
|
197
224
|
return 30;
|
|
198
225
|
}
|
|
199
|
-
if (beMonth === LunarMonths
|
|
226
|
+
if (beMonth === LunarMonths['ααααΆααΆα'] || beMonth === LunarMonths['αα»αα·ααΆααΆα']) {
|
|
200
227
|
return 30;
|
|
201
228
|
}
|
|
202
229
|
// αα·ααα·α : 29 , αα»ααα : 30 , ααΆα : 29 .. 30 .. 29 ..30 .....
|
|
@@ -262,6 +289,22 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
262
289
|
}
|
|
263
290
|
}
|
|
264
291
|
|
|
292
|
+
/**
|
|
293
|
+
* αααααααα·ααΆαααΌααΆ
|
|
294
|
+
* ααααααΆα
αααααΆααα»αααααααΆα
|
|
295
|
+
*/
|
|
296
|
+
function getVisakhaBochea(gregorianYear) {
|
|
297
|
+
var date = Moment('1/1/' + gregorianYear, 'D/M/YYYY')
|
|
298
|
+
for (var i = 0; i < 365; i++) {
|
|
299
|
+
var lunarDate = findLunarDate(date);
|
|
300
|
+
if (lunarDate.month == LunarMonths['αα·ααΆα'] && lunarDate.day == 14) {
|
|
301
|
+
return date
|
|
302
|
+
}
|
|
303
|
+
date.add(1, 'day')
|
|
304
|
+
}
|
|
305
|
+
throw 'Cannot find Visakhabochea day. Please report this bug.';
|
|
306
|
+
}
|
|
307
|
+
|
|
265
308
|
/**
|
|
266
309
|
* Buddhist Era
|
|
267
310
|
* ααααααααααααΆα ααΊ α‘ ααα
αααα·ααΆα
|
|
@@ -271,11 +314,10 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
271
314
|
* @returns {*}
|
|
272
315
|
*/
|
|
273
316
|
function getBEYear(moment) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return parseInt(moment.format('YYYY')) + 544;
|
|
317
|
+
if (moment.diff(getVisakhaBochea(moment.year())) > 0) {
|
|
318
|
+
return moment.year() + 544;
|
|
277
319
|
} else {
|
|
278
|
-
return
|
|
320
|
+
return moment.year() + 543;
|
|
279
321
|
}
|
|
280
322
|
}
|
|
281
323
|
|
|
@@ -288,10 +330,10 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
288
330
|
* @returns {*}
|
|
289
331
|
*/
|
|
290
332
|
function getMaybeBEYear(moment) {
|
|
291
|
-
if (
|
|
292
|
-
return
|
|
333
|
+
if (moment.month() + 1 <= SolarMonth['ααααΆ'] + 1) {
|
|
334
|
+
return moment.year() + 543;
|
|
293
335
|
} else {
|
|
294
|
-
return
|
|
336
|
+
return moment.year() + 544;
|
|
295
337
|
}
|
|
296
338
|
}
|
|
297
339
|
|
|
@@ -310,7 +352,7 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
310
352
|
* @returns {number}
|
|
311
353
|
*/
|
|
312
354
|
function getJolakSakarajYear(moment) {
|
|
313
|
-
let gregorianYear =
|
|
355
|
+
let gregorianYear = moment.year();
|
|
314
356
|
let newYearMoment = getKhNewYearMoment(gregorianYear);
|
|
315
357
|
if (moment.diff(newYearMoment) < 0) {
|
|
316
358
|
return gregorianYear + 543 - 1182
|
|
@@ -327,7 +369,7 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
327
369
|
function getKhmerLunarDay(day) {
|
|
328
370
|
return {
|
|
329
371
|
count: (day % 15) + 1,
|
|
330
|
-
moonStatus: day > 14 ? MoonStatus
|
|
372
|
+
moonStatus: day > 14 ? MoonStatus['ααα
'] : MoonStatus['ααΎα']
|
|
331
373
|
}
|
|
332
374
|
}
|
|
333
375
|
|
|
@@ -337,7 +379,7 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
337
379
|
* @returns {number}
|
|
338
380
|
*/
|
|
339
381
|
function getAnimalYear(moment) {
|
|
340
|
-
let gregorianYear =
|
|
382
|
+
let gregorianYear = moment.year();
|
|
341
383
|
let newYearMoment = getKhNewYearMoment(gregorianYear);
|
|
342
384
|
if (moment.diff(newYearMoment) < 0) {
|
|
343
385
|
return (gregorianYear + 543 + 4) % 12
|
|
@@ -411,7 +453,7 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
411
453
|
return getBEYear(moment);
|
|
412
454
|
},
|
|
413
455
|
'c': function () {
|
|
414
|
-
return moment.
|
|
456
|
+
return moment.year();
|
|
415
457
|
},
|
|
416
458
|
'j': function () {
|
|
417
459
|
return getJolakSakarajYear(moment);
|
|
@@ -423,7 +465,7 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
423
465
|
}));
|
|
424
466
|
|
|
425
467
|
}
|
|
426
|
-
Error(format + ' is not a valid date format.');
|
|
468
|
+
throw Error(format + ' is not a valid date format.');
|
|
427
469
|
}
|
|
428
470
|
|
|
429
471
|
/**
|
|
@@ -441,39 +483,39 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
441
483
|
*/
|
|
442
484
|
function nextMonthOf(khmerMonth, BEYear) {
|
|
443
485
|
switch (khmerMonth) {
|
|
444
|
-
case LunarMonths
|
|
445
|
-
return LunarMonths
|
|
446
|
-
case LunarMonths
|
|
447
|
-
return LunarMonths
|
|
448
|
-
case LunarMonths
|
|
449
|
-
return LunarMonths
|
|
450
|
-
case LunarMonths
|
|
451
|
-
return LunarMonths
|
|
452
|
-
case LunarMonths
|
|
453
|
-
return LunarMonths
|
|
454
|
-
case LunarMonths
|
|
455
|
-
return LunarMonths
|
|
456
|
-
case LunarMonths
|
|
486
|
+
case LunarMonths['αα·ααα·α']:
|
|
487
|
+
return LunarMonths['αα»ααα'];
|
|
488
|
+
case LunarMonths['αα»ααα']:
|
|
489
|
+
return LunarMonths['ααΆα'];
|
|
490
|
+
case LunarMonths['ααΆα']:
|
|
491
|
+
return LunarMonths['ααααα»α'];
|
|
492
|
+
case LunarMonths['ααααα»α']:
|
|
493
|
+
return LunarMonths['α
αααα'];
|
|
494
|
+
case LunarMonths['α
αααα']:
|
|
495
|
+
return LunarMonths['αα·ααΆα'];
|
|
496
|
+
case LunarMonths['αα·ααΆα']:
|
|
497
|
+
return LunarMonths['ααααα'];
|
|
498
|
+
case LunarMonths['ααααα']: {
|
|
457
499
|
if (isKhmerLeapMonth(BEYear)) {
|
|
458
|
-
return LunarMonths
|
|
500
|
+
return LunarMonths['ααααΆααΆα']
|
|
459
501
|
} else {
|
|
460
|
-
return LunarMonths
|
|
502
|
+
return LunarMonths['α’αΆααΆα']
|
|
461
503
|
}
|
|
462
504
|
}
|
|
463
|
-
case LunarMonths
|
|
464
|
-
return LunarMonths
|
|
465
|
-
case LunarMonths
|
|
466
|
-
return LunarMonths
|
|
467
|
-
case LunarMonths
|
|
468
|
-
return LunarMonths
|
|
469
|
-
case LunarMonths
|
|
470
|
-
return LunarMonths
|
|
471
|
-
case LunarMonths
|
|
472
|
-
return LunarMonths
|
|
473
|
-
case LunarMonths
|
|
474
|
-
return LunarMonths
|
|
475
|
-
case LunarMonths
|
|
476
|
-
return LunarMonths
|
|
505
|
+
case LunarMonths['α’αΆααΆα']:
|
|
506
|
+
return LunarMonths['ααααΆααα'];
|
|
507
|
+
case LunarMonths['ααααΆααα']:
|
|
508
|
+
return LunarMonths['αααααα'];
|
|
509
|
+
case LunarMonths['αααααα']:
|
|
510
|
+
return LunarMonths['α’αααα»α'];
|
|
511
|
+
case LunarMonths['α’αααα»α']:
|
|
512
|
+
return LunarMonths['ααααα·α'];
|
|
513
|
+
case LunarMonths['ααααα·α']:
|
|
514
|
+
return LunarMonths['αα·ααα·α'];
|
|
515
|
+
case LunarMonths['ααααΆααΆα']:
|
|
516
|
+
return LunarMonths['αα»αα·ααΆααΆα'];
|
|
517
|
+
case LunarMonths['αα»αα·ααΆααΆα']:
|
|
518
|
+
return LunarMonths['ααααΆααα'];
|
|
477
519
|
default:
|
|
478
520
|
throw Error('Plugin is facing wrong calculation (Invalid month)');
|
|
479
521
|
}
|
|
@@ -489,7 +531,7 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
489
531
|
* Epoch Date: January 1, 1900
|
|
490
532
|
*/
|
|
491
533
|
let epochMoment = Moment('1/1/1900', 'D/M/YYYY')
|
|
492
|
-
let khmerMonth = LunarMonths
|
|
534
|
+
let khmerMonth = LunarMonths['αα»ααα'];
|
|
493
535
|
let khmerDay = 0; // 0 - 29 α‘ααΎα ... α‘α₯ααΎα α‘ααα
...α‘α€ααα
(α‘α₯ααα
)
|
|
494
536
|
|
|
495
537
|
let differentFromEpoch = target.diff(epochMoment)
|
|
@@ -558,7 +600,20 @@ let {LunarMonths, SolarMonth, MoonStatus, khNewYearMoments} = require('./constan
|
|
|
558
600
|
return Moment(Moment.khNewYearMoments[gregorianYear], 'DD-MM-YYYY H:m')
|
|
559
601
|
} else {
|
|
560
602
|
// console.log('calculate')
|
|
561
|
-
|
|
603
|
+
let getSoriyatraLerngSak;
|
|
604
|
+
if (typeof require === 'function') {
|
|
605
|
+
getSoriyatraLerngSak = require('./getSoriyatraLerngSak')
|
|
606
|
+
} else {
|
|
607
|
+
if (window) {
|
|
608
|
+
if (!window.getSoriyatraLerngSak) {
|
|
609
|
+
throw 'Please import [MOMENTKH]/getSoriyatraLerngSak.js to your project'
|
|
610
|
+
} else {
|
|
611
|
+
getSoriyatraLerngSak = window.getSoriyatraLerngSak
|
|
612
|
+
}
|
|
613
|
+
} else {
|
|
614
|
+
throw 'Cannot import getSoriyatraLerngSak. This is might not a nodejs environment or a browser'
|
|
615
|
+
}
|
|
616
|
+
}
|
|
562
617
|
// ααΈαααα·αααααααΆα αα
α
α»αααααααΆα
|
|
563
618
|
let jsYear = (gregorianYear + 544) - 1182;
|
|
564
619
|
let info = getSoriyatraLerngSak(jsYear);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thyrith/momentkh",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Working on khmer calendar by implementting moment js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "component",
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
]
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
"dependencies": {
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"moment": "^2.29.1"
|
|
36
|
+
},
|
|
35
37
|
"spm": {
|
|
36
38
|
"main": "momentkh.js",
|
|
37
39
|
"output": [
|