@thyrith/momentkh v2.5.5
momentkh
momentkh is an add-on feature to moment js library DEMO.
Install π
$ npm install moment --save
$ npm install @thyrith/momentkh --saveHow to use π«
This library is built depends on moment.js popular library. We added some functionality to make it easier to work with Khmer date format.
Nodejs
const moment = require('moment');
// Add our features to your preferred moment.js version
require('@thyrith/momentkh')(moment);
// From now on, your moment js is transformed
let today = moment();
console.log(today);
// Display date today as moment js object
// For example: moment("2018-12-15T14:49:38.586")
let khmerDate = today.toLunarDate();
console.log(khmerDate);
// Display khmer date
// For example: αααααα
αα α¨ααΎα αααα·ααα·α ααααΆαα
ααααΉαααααα αα»αααααααΆα α’α₯α¦α’HTML
First, you need to clone this package to the root of your project or your /public folder.
*** For momentjs library, you can import it any method or any version you want.
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="momentkh/constant.js"></script>
<script src="momentkh/locale/km.js"></script>
<script src="momentkh/getSoriyatraLerngSak.js"></script>
<script src="momentkh/momentkh.js"></script>
<script>
var moment = momentkh(moment)
var today = moment()
console.log('Today: ', today.toKhDate())
console.log('New year at: ', moment.getKhNewYearMoment(2021))
</script>Added Functionality π‘
Attributes of moment instance
| Name | Parameter | Description | Example |
|---|---|---|---|
| toLunarDate | empty or String | display format as Khmer lunar date | moment().toLunarDate(); |
| khDay | empty | display khmer day index | moment().khDay(); 0 -> α‘ααΎα 1 -> α’ααΎα 2 -> α£ααΎα ... 15 -> α‘ααα
16 -> α’ααα
17 -> α£ααα
... |
| khMonth | empty | display khmer month index | moment.khMonth(); 0 -> αα·ααα·α 1 -> αα»ααα 2 -> ααΆα 3 -> ααααα»α 4 -> α
αααα 5 -> αα·ααΆα 6 -> ααααα 7 -> α’αΆααΆα 8 -> ααααΆααα 9 -> αααααα 10 -> α’αααα»α 11 -> ααααα·α 12 -> ααααΆααΆα 13 -> αα»αα·ααΆααΆα |
| khYear | empty | display Buddhist Era year | moment().khYear(); |
Alias
| Name | Original |
|---|---|
| toKhDate, tokhdate | toLunarDate |
Attributes of moment
| Name | Parameter | Description | Example |
|---|---|---|---|
| getKhNewYearMoment | Integer | Return moment.js object. Giving the moment of Khmer New Year. (ααααααααΆα α»α) | moment.getKhNewYearMoment(2019); |
| String or Object | Return moment.js object. Just same as calling: moment('13/04/2018', 'dd/mm/yyyy'); for Gregorian date | moment.readLunarDate('α‘α₯ααΎα αα·ααΆα α.α. α’α₯α₯α₯'); |
Alias
| Name | Original |
|---|---|
| khDate, khdate | readLunarDate |
Format
By default, it will return the format as shown in example above. However, you can also customize your format.
// Use moment.js as usual. Documentaion: momentjs.com
let myBirthday = moment('4/3/1992', 'd/m/yyy');
myBirthday.toLunarDate('dN ααααW ααm α.α. b');
// α¦ααΎα αααααααα ααααα·α αααα·ααα·α α.α. α’α₯α¦α’'| Format | Description | Example |
|---|---|---|
| W | αααααααααααΆα α | α’ααααΆα |
| w | αααααααααααΆα αααΆαα | α’ |
| d | ααααααΈ α αΆααααΈααα α‘ ααα α‘α₯ | α‘ |
| D | ααααααΈ α αΆααααΈααα α α‘ ααα α‘α₯ | α α‘ |
| n | ααΎα α¬ ααα | α |
| N | ααΎα α¬ ααα | ααΎα |
| o | αααααααααααααΈα’αααΈααααααΈ | α§‘ (ααΆααααααΆ α‘ααΎα) |
| m | ααα αααααα· | αα·ααα·α |
| M | αααα»αα·αααα· | ααααΆ |
| a | ααααΆααααα | αααΆ |
| e | ααα | α―αααα |
| b | ααααΆααα»αααααααΆα | α’α₯α₯α¦ |
| c | ααααΆααααα·αααααααΆα | α’α α‘α© |
| j | ααααΆαα α»αααααααΆα | α‘α€α¦α£ |
Bug Report πππ¦π·πΈπ¦π¦πππ£
I know there will be a lot of error.
Testing
There is no test running on this package. If you are available for this work, it would be very awesome.
Contribute π‘
Welcome pull request
References
1 year ago
2 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago