Giter Club home page Giter Club logo

momentkh's Introduction

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

Support me

I'm really happy if this project is useful to you.

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.

momentkh's People

Contributors

thyrithsor avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.