@thyrith/momentkh

2.5.4 • Public • Published

NPM version GitHub issues GitHub forks GitHub stars GitHub license

momentkh

momentkh is an add-on feature to moment js library DEMO.

Install 🗜

$ npm install moment --save
$ npm install @thyrith/momentkh --save

How 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);
readLunarDate*(currently working on this)* 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

Package Sidebar

Install

npm i @thyrith/momentkh

Weekly Downloads

110

Version

2.5.4

License

MIT

Unpacked Size

57 kB

Total Files

10

Last publish

Collaborators

  • thyrith