Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jalali-moment

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jalali-moment

Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.3K
increased by0.57%
Maintainers
1
Weekly downloads
 
Created
Source

jalali-moment

A Jalali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js. DEMO

MIT License Build Status NPM version Package Quality dependencies Quality dev dependencies Quality Codacy Badge Codacy Badge

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

Install via bower

bower install jalali-moment --save

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');

ES5

<!--<script src="bower_components/jalali-moment/dist/jalali-moment.browser.js"></script>-->
<!--<script src="node_modules/jalali-moment/dist/jalali-moment.browser.js"></script>-->
<script src="thisRepository/jalali-moment/dist/jalali-moment.browser.js"></script>
<script>
  moment().format('jYYYY/jM/jD')
</script>

Plunker

<script src='https://unpkg.com/jalali-moment/dist/jalali-moment.browser.js'></script>
<script>
  moment().format('jYYYY/jM/jD')
</script>

Plunker and Typescript

You could use systemjs to import this library into your project like this

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:

const m = moment('1367/11/4', 'jYYYY/jM/jD');
m.format('jYYYY/jM/jD [is] YYYY/M/D'); //1367/11/4 is 1989/1/24
m.jYear(); //1367
m.jMonth(); //10
m.jDate(); //4
m.jDayOfYear(); //310
m.jWeek(); //45
m.jWeekYear(); //1367
moment.jIsLeapYear(m.jYear()); //false

moment('1392/6/3 16:40', 'jYYYY/jM/jD HH:mm').format('YYYY-M-D HH:mm:ss'); // 2013-8-25 16:40:00

moment('2013-8-25 16:40:00', 'YYYY-M-D HH:mm:ss').endOf('jMonth').format('jYYYY/jM/jD HH:mm:ss'); // 1392/6/31 23:59:59

moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD'); // 1981/07/17
Load Persian

To add Persian language, use loadPersian method:

moment().format('jYYYY/jMMMM/jD'); // 1367/Bahman/4
moment.loadPersian();
moment().format('jYYYY/jMMMM/jD'); // 1367/بهمن/4
moment.loadPersian(true);
moment().format('jYYYY/jMMMM/jD'); // ۱۳۶۷/بهمن/۴
moment.unloadPersian();
moment().format('jYYYY/jMMMM/jD'); // 1367/Bahman/4

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.

License

MIT

Keywords

FAQs

Package last updated on 07 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc