jalali-moment
A Jalali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.
Jalali calendar is a solar calendar. It gains approximately 1 day on the Julian calendar every 128 years. Read more on Wikipedia.
This plugin adds Jalali calendar support to momentjs library.
Calendar conversion is based on the algorithm provided by Kazimierz M. Borkowski and has a very good performance.
Where to use it
Like momentjs
, jalali-moment
works in browser and in Node.js.
Install
Install via NPM
npm install jalali-moment -S
Node.js
var moment = require('jalali-moment');
moment().format('jYYYY/jM/jD');
Angular
import * as moment from 'jalali-moment';
add a jalali pipe
@Pipe({
name: 'jalali'
})
export class JalaliPipe implements PipeTransform {
transform(value: any, args?: any): any {
let MomentDate=moment(value);
return MomentDate.format("jYYYY/jM/jD");
}
}
and use it in component template
<div>loadedData.date|jalali</div>
Typescript
import * as moment from 'jalali-moment';
let todayJalali = moment().format('jYYYY/jM/jD');
API
This plugin tries to mimic momentjs
api. Basically, when you want to format or parse a string, just add a j
to the format token like 'jYYYY' or 'jM'. For example:
m = moment('1360/5/26', 'jYYYY/jM/jD')
m.format('jYYYY/jM/jD [is] YYYY/M/D')
m.jYear()
m.jMonth()
m.jDate()
m.jDayOfYear()
m.jWeek()
m.jWeekYear()
m.add(1, 'jYear')
m.add(2, 'jMonth')
m.add(3, 'day')
m.format('jYYYY/jM/jD')
m.jMonth(11)
m.startOf('jMonth')
m.format('jYYYY/jM/jD')
m.jYear(1392)
m.startOf('jYear')
m.format('jYYYY/jM/jD')
m.subtract(1, 'jYear')
m.subtract(1, 'jMonth')
m.format('jYYYY/jM/jD')
moment('1391/12/30', 'jYYYY/jMM/jDD').isValid()
moment('1392/12/30', 'jYYYY/jMM/jDD').isValid()
moment.jIsLeapYear(1391)
moment.jIsLeapYear(1392)
moment.jDaysInMonth(1395, 11)
moment.jDaysInMonth(1394, 11)
moment('1392/6/3 16:40', 'jYYYY/jM/jD HH:mm').format('YYYY-M-D HH:mm:ss')
moment('2013-8-25 16:40:00', 'YYYY-M-D HH:mm:ss').endOf('jMonth').format('jYYYY/jM/jD HH:mm:ss')
moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD')
To add Persian language, use loadPersian method:
moment.loadPersian()
Related Projects
jalali-angular-datepicker ( angular2 or more)
A highly configurable date picker built for Angular 2 applications using jalali-moment
is fingerpich/jalali-angular-datepicker created by @Fingerpich.
In this I needed a plugin on moment.js to have Jalali date so at first I had been using moment-jalaali but I can't so I forked it and add some new feature to it.
License
MIT