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 - npm Package Compare versions

Comparing version 3.0.2 to 3.0.3

pkg/bower.json

271

Document.md

@@ -1,229 +0,60 @@

## Introduction
# Jalali Moment
jalali(Persian) calendar is a solar calendar system. It gains approximately 1 day on the Julian calendar every 128 years. [Read more on Wikipedia](http://en.wikipedia.org/wiki/Jalali_calendar).
Display, parse, manipulate and validate jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times and also
convert Jalali (Persian, Khorshidi, Shamsi) date to Gregorian (Miladi) or vice versa in javascript or typescript. [DEMO](https://fingerpich.github.io/jalali-moment)
Calendar conversion is based on the [algorithm provided by Kazimierz M. Borkowski](http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm) and has a very good performance.
Read this in other languages: [فارسی](./README.fa.md)
This plugin adds Jalali (Persian, Khorshidi, Shamsi) calendar system to [moment.js](http://momentjs.com) library.
[![MIT License][license-image]][license-url]
[![Build Status][travis-image]][travis-url]
[![NPM version][npm-version-image]][npm-url]
[![Package Quality][packageQuality-image]][packageQuality-url]
[![dependencies Quality][dependencies-quality]][dependencies-quality-url]
[![dev dependencies Quality][dev-dependencies-quality]][dev-dependencies-quality-url]
[![Codacy Badge][codacy-quality]][codacy-quality-url]
[![Codacy Badge][codacy-coverage]][codacy-coverage-url]
## Install
## Table Of Content
- [Install](#install)
- Use jalali moment in
- [Node.js](#using-in-nodejs)
- [Typescript](#typescript)
- [Angular](#angular-2-or-4)
- [Aurelia](#aurelia)
- [Es5](#es5)
- [Plunker](#using-in-plunker)
- [Use API](#api)
Install via **npm**
```shell
npm install jalali-moment -S
```
Install via **yarn**
```shell
yarn add jalali-moment
```
Install via **bower**
```shell
bower install jalali-moment --save
```
This plugin provides using jalali and gregorian calendar system together
on [momentjs](https://momentjs.com/docs/) api.
## Using in Node.js
```.locale('fa');``` it will use jalali calendar system
Install it via npm or yarn then use it as the following code
```.locale('any other locale');``` it will use gregorian calendar system
```js
var moment = require('jalali-moment');
moment().format('jYYYY/jM/jD');
```
#### Usage
## Using in browser
#### ES5
```HTML
<!--<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="thisRepositoryPath/dist/jalali-moment.browser.js"></script>
<script>
moment().format('jYYYY/jM/jD');
</script>
```
#### Typescript
```ts
import * as moment from 'jalali-moment';
let todayJalali = moment().format('jYYYY/jM/jD');
```
#### Angular 2 or 4
```ts
import * as moment from 'jalali-moment';
```
Add a pipe
```ts
@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
```HTML
<div>{{ loadedData.date | jalali }}</div>
```
#### Aurelia
You can create a value converters like following:
``` typescript
import { valueConverter } from 'aurelia-framework';
var moment = require('jalali-moment');
@valueConverter("date")
export class DateValueConverter {
toView(value: string, format: string = "YYYY/MM/DD", locale: string = "en") {
if (!value)
return null;
let m2 = moment(value).locale(locale);
return m2.format(format);
}
}
```
then use this value converter in your ```html``` files:
```html
<require from="path_to_your_date_value_converter"></require>
<h1 style="direction:ltr">
<span>
${myDate|date:myFormat:options.locale}
</span>
</h1>
```
also, for aurelia developers, there is a plugin, [aurelia-time](https://github.com/shahabganji/aurelia-time), in which there are value converters for jalali-moment and other time and date libraries.
## API
This plugin tries to mimic [moment.js](https://momentjs.com/) 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:
```js
now = moment(); //get the current date and time,
```
#### Parse
Create a instance of moment from a Jalali (Persian) or Miladi date and time as string.[more](https://momentjs.com/docs/#/parsing/)
```js
m = moment('1367/11/4', 'jYYYY/jM/jD');// parse a jalali (persian) date
m = moment('1989/1/24', 'YYYY/M/D');// parse a gregorian (miladi) date
moment.locale('fa');
m = moment('1367/11/4', 'YYYY/M/D');// parse a jalali (persian) date
```
#### Display jalali or miladi date
Display moment instance as a string.[more](https://momentjs.com/docs/#/displaying/)
```js
m.format('jYYYY/jM/jD');// 1367/11/4
m.format('jMM'); // 11 display jalali month
m.format('M'); // 1 display miladi month
m.format('MM'); // 01 display month by two digit
m.format('MMMM'); // January
m.format('jMMMM'); // Bahman
m.format('jDD'); // 04 display day by two digit
m.format('jYYYY/jM/jD [is] YYYY/M/D'); // 1367/11/4 is 1989/1/24
m.jDayOfYear(); // 310
m.jWeek(); // 45
m.jWeekYear(); // 1367
```
#### Manipulate
There are a number of methods to modify date and time.[more](https://momentjs.com/docs/#/manipulating/)
```js
m.jYear(1368); // set jalali year
// If the range is exceeded, it will bubble up to the year.
m.jMonth(3); // month will be 4 and m.format("M")=='4' , jMonth Accepts numbers from 0 to 11.
m.jDate(10); // set a date
m.format("jYYYY/jMM/jD"); // 1368/4/10
m.subtract(1, "jyear"); // add a Jalali Year
m.format("jYYYY/jMM/jD"); // 1367/4/10
m.add(2, "jmonth"); // add Jalali Month
m.format("jYYYY/jMM/jD"); // 1367/6/10
m.endOf('jMonth').format("jYYYY/jMM/jD"); // 1367/6/31
m.startOf('jYear').format("jYYYY/jMM/jD"); // 1367/1/1
```
#### Validate
Check a date and time.[more](https://momentjs.com/docs/#/query/)
```js
m = moment('1367/11/4', 'jYYYY/jM/jD');
m.jIsLeapYear(); // false
m.isLeapYear(); // false
m.isSame('1989-01-01', 'year'); // true
m.isSame(moment('1367-01-01','jYYYY-MM-DD'), 'jyear'); // true
m.isBefore(moment('1367-01-01','jYYYY-MM-DD'), 'jyear'); // false
m.isAfter(moment('1367-01-01','jYYYY-MM-DD'), 'jyear'); // false
m.isValid(); // true
moment('1396/7/31','jYYYY/jM/jD').isValid(); // false
```
[validation demo in plunker](https://plnkr.co/caWsmd)
#### Convert persian(Jalali , Shamsi, khorshidi) to gregorian (miladi) calendar system
```js
moment('1392/6/3 16:40', 'jYYYY/jM/jD HH:mm')
.format('YYYY-M-D HH:mm:ss'); // 2013-8-25 16:40:00
```
#### Convert gregorian (miladi) to jalali (Shamsi, persian)
```js
moment('2013-8-25 16:40:00', 'YYYY-M-D HH:mm:ss')
.format('jYYYY/jM/jD HH:mm:ss'); // 1392/6/31 23:59:59
```
### Change calendar system on changing its locale
```js
moment.bindCalendarSystemAndLocale();
```
### An example usage:
To make a datePicker work with jalali(shamsi) calendar system you could use this ability.
## Using in Plunker
#### ES5
```HTML
<script src='https://unpkg.com/jalali-moment/dist/jalali-moment.browser.js'></script>
<script>
moment().format('jYYYY/jM/jD');
</script>
```
[es5 demo in plunker](https://plnkr.co/caWsmd)
#### Typescript or es6
You could use systemjs to import this library into your project like [this](https://embed.plnkr.co/Gggh1u/)
## Related Projects
#### jalali-angular-datepicker ( angular2 or more)
A highly configurable date picker built for Angular 4 or Angular 2 applications using `jalali-moment` is [fingerpich/jalali-angular-datepicker](https://github.com/fingerpich/jalali-angular-datepicker) created by [@Fingerpich](https://github.com/fingerpich).
#### jalaali-moment
A Jalaali calendar system plugin for moment.js is [jalaali-moment](https://github.com/jalaali/moment-jalaali).
#### aurelia-time
[aurelia-time](https://github.com/shahabganji/aurelia-time) Contains a set of value converters for [Aurelia](http://aurelia.io), one which uses jalali-moment.
- [Parse](#parse)
```js
moment.locale('fa'); // set fa locale for all new moment instances
var m1 = moment("1367/11/04","YYYY/MM/DD");
```
- [Display](#display-jalali-or-miladi-date)
```js
m1.format("YYYY/MM/DD"); // 1367/11/04
```
- [Manipulate](#manipulate)
```js
m1.add(1, "day").format("YYYY/MM/DD"); // 1367/11/05
```
- [Validate](#validate)
```js
m1.isSame(m1.clone()); // true
```
- [Convert](#convert-persianjalali--shamsi-khorshidi-to-gregorian-miladi-calendar-system)
```js
moment('1367/11/04', 'YYYY/MM/DD').locale('en').format('YYYY/MM/DD'); // 1989/01/24
moment.locale('en');
moment('1989/01/24').locale('fa').format('YYYY/MM/DD'); // 1367/11/04
//set en locale just for this instance
```
{
"name": "jalali-moment",
"version": "3.0.2",
"version": "3.0.3",
"description": "Display, parse, manipulate ,validate and convert jalali (Persian, Khorshidi, Shamsi) date and time",

@@ -30,3 +30,4 @@ "author": {

"build": "WEBPACK_ENV=build webpack;webpack --config webpack.browser.js",
"dev": "WEBPACK_ENV=dev webpack --progress --colors --watch"
"dev": "WEBPACK_ENV=dev webpack --progress --colors --watch",
"publish": "mkdir pkg;cp -r ./* ./pkg; cp Document.md ./pkg/README.md; cd ./pkg;npm run build;npm publish;cd ..;rm -rf pkg"
},

@@ -33,0 +34,0 @@ "homepage": "https://github.com/fingerpich/jalali-moment",

# Jalali Moment
Display, parse, manipulate and validate jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times and also
Display, parse, manipulate and validate jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times and also
convert Jalali (Persian, Khorshidi, Shamsi) date to Gregorian (Miladi) or vice versa in javascript or typescript. [DEMO](https://fingerpich.github.io/jalali-moment)

@@ -10,3 +10,3 @@

[![Build Status][travis-image]][travis-url]
[![NPM version][npm-version-image]][npm-url]
[![NPM version][npm-version-image]][npm-url]
[![Package Quality][packageQuality-image]][packageQuality-url]

@@ -18,13 +18,13 @@ [![dependencies Quality][dependencies-quality]][dependencies-quality-url]

## How to
- [Install](./Document.md#install)
## Table Of Content
- [Install](#install)
- Use jalali moment in
- [Node.js](./Document.md#using-in-nodejs)
- [Typescript](./Document.md#typescript)
- [Angular](./Document.md#angular-2-or-4)
- [Aurelia](./Document.md#aurelia)
- [Es5](./Document.md#es5)
- [Plunker](./Document.md#using-in-plunker)
- [Use API](./Document.md#api)
- [Node.js](#using-in-nodejs)
- [Typescript](#typescript)
- [Angular](#angular-2-or-4)
- [Aurelia](#aurelia)
- [Es5](#es5)
- [Plunker](#using-in-plunker)
- [Use API](#api)
This plugin provides using jalali and gregorian calendar system together

@@ -39,3 +39,3 @@ on [momentjs](https://momentjs.com/docs/) api.

- [Parse](./Document.md#parse)
- [Parse](#parse)
```js

@@ -45,15 +45,15 @@ moment.locale('fa'); // set fa locale for all new moment instances

```
- [Display](./Document.md#display-jalali-or-miladi-date)
- [Display](#display-jalali-or-miladi-date)
```js
m1.format("YYYY/MM/DD"); // 1367/11/04
```
- [Manipulate](./Document.md#manipulate)
- [Manipulate](#manipulate)
```js
m1.add(1, "day").format("YYYY/MM/DD"); // 1367/11/05
```
- [Validate](./Document.md#validate)
- [Validate](#validate)
```js
m1.isSame(m1.clone()); // true
```
- [Convert](./Document.md#convert-persianjalali--shamsi-khorshidi-to-gregorian-miladi-calendar-system)
- [Convert](#convert-persianjalali--shamsi-khorshidi-to-gregorian-miladi-calendar-system)
```js

@@ -65,25 +65,1 @@ moment('1367/11/04', 'YYYY/MM/DD').locale('en').format('YYYY/MM/DD'); // 1989/01/24

```
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE
[npm-url]: https://npmjs.org/package/jalali-moment
[npm-version-image]: http://img.shields.io/npm/v/jalali-moment.svg?style=flat
[travis-url]: https://travis-ci.org/fingerpich/jalali-moment
[travis-image]: https://travis-ci.org/fingerpich/jalali-moment.png?branch=master
[packageQuality-image]: http://npm.packagequality.com/shield/jalali-moment.svg
[packageQuality-url]: http://packagequality.com/#?package=jalali-moment
[dependencies-quality]: https://david-dm.org/fingerpich/jalali-moment.svg
[dependencies-quality-url]: https://david-dm.org/fingerpich/jalali-moment
[dev-dependencies-quality]: https://david-dm.org/fingerpich/jalali-moment/dev-status.svg
[dev-dependencies-quality-url]: https://david-dm.org/fingerpich/jalali-moment?type=dev
[codacy-quality]:https://api.codacy.com/project/badge/Grade/1aa5b7aadfc24238bdf825d58cb2cba1
[codacy-quality-url]:https://www.codacy.com/app/zarei-bs/jalali-moment?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=fingerpich/jalali-moment&amp;utm_campaign=Badge_Grade
[codacy-coverage]:https://api.codacy.com/project/badge/Coverage/1aa5b7aadfc24238bdf825d58cb2cba1
[codacy-coverage-url]:https://www.codacy.com/app/zarei-bs/jalali-moment?utm_source=github.com&utm_medium=referral&utm_content=fingerpich/jalali-moment&utm_campaign=Badge_Coverage
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