jalali-moment
Advanced tools
Comparing version 2.0.2 to 2.0.4
@@ -867,2 +867,18 @@ | ||
jMoment.fn.isBefore = function (other, units) { | ||
units = normalizeUnits(units); | ||
if (units === "jyear" || units === "jmonth") { | ||
return moment.fn.isBefore.call(this.clone().startOf(units), other.clone().startOf(units)); | ||
} | ||
return moment.fn.isBefore.call(this, other, units); | ||
}; | ||
jMoment.fn.isAfter = function (other, units) { | ||
units = normalizeUnits(units); | ||
if (units === "jyear" || units === "jmonth") { | ||
return moment.fn.isAfter.call(this.clone().startOf(units), other.clone().startOf(units)); | ||
} | ||
return moment.fn.isAfter.call(this, other, units); | ||
}; | ||
jMoment.fn.clone = function () { | ||
@@ -869,0 +885,0 @@ return jMoment(this); |
{ | ||
"name": "jalali-moment", | ||
"version": "2.0.2", | ||
"description": "Jalali (Persian, Khorshidi, Shamsi) calendar system to use in javascript or typescript.", | ||
"version": "2.0.4", | ||
"description": "Display, parse, manipulate ,validate and convert jalali (Persian, Khorshidi, Shamsi) date and time", | ||
"author": { | ||
@@ -11,2 +11,4 @@ "name": "Mojtaba Zarei (Fingerpich)", | ||
"keywords": [ | ||
"manipulate", | ||
"validate", | ||
"jalali", | ||
@@ -13,0 +15,0 @@ "convert", |
111
README.md
@@ -1,6 +0,8 @@ | ||
# jalali-moment | ||
# Jalali Moment | ||
It adds jalali (Persian, Khorshidi, Shamsi) calendar system to [moment.js](http://momentjs.com) library. | ||
[DEMO](https://fingerpich.github.io/jalali-moment) | ||
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) | ||
Read this in other languages: [فارسی](./README.fa.md) | ||
[![MIT License][license-image]][license-url] | ||
@@ -15,8 +17,12 @@ [![Build Status][travis-image]][travis-url] | ||
jalali calendar is a solar calendar. It gains approximately 1 day on the Julian calendar every 128 years. [Read more on Wikipedia](http://en.wikipedia.org/wiki/Jalali_calendar). | ||
## Introduction | ||
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). | ||
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. | ||
### Install | ||
This plugin adds Jalali (Persian, Khorshidi, Shamsi) calendar system to [moment.js](http://momentjs.com) library. | ||
## Install | ||
Install via **npm** | ||
@@ -37,3 +43,3 @@ ```shell | ||
install it via npm or yarn and following code will work | ||
Install it via npm or yarn then use it as the following code | ||
@@ -65,3 +71,3 @@ ```js | ||
#### Angular | ||
#### Angular 2 or 4 | ||
@@ -71,3 +77,3 @@ ```ts | ||
``` | ||
add a jalali pipe | ||
Add a pipe | ||
```ts | ||
@@ -91,3 +97,3 @@ @Pipe({ | ||
####ES5 | ||
#### ES5 | ||
@@ -102,7 +108,7 @@ ```HTML | ||
####Typescript or es6 | ||
#### Typescript or es6 | ||
You could use systemjs to import this library into your project like [this](https://embed.plnkr.co/Gggh1u/) | ||
# API | ||
## API | ||
@@ -115,3 +121,23 @@ This plugin tries to mimic [moment.js](https://momentjs.com/) api. | ||
now = moment(); //get the current date and time, | ||
m = moment('1367/11/4', 'jYYYY/jM/jD'); | ||
``` | ||
#### 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 | ||
``` | ||
#### 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 | ||
@@ -121,3 +147,8 @@ m.jDayOfYear(); // 310 | ||
m.jWeekYear(); // 1367 | ||
moment.jIsLeapYear(m.jYear()); // false | ||
``` | ||
#### 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 | ||
@@ -132,17 +163,32 @@ // If the range is exceeded, it will bubble up to the year. | ||
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 | ||
``` | ||
#### 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') | ||
.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 | ||
``` | ||
all features are documented in [here](https://momentjs.com/docs/). | ||
#### Load Persian | ||
## Load Persian | ||
To add Persian language, use loadPersian method: | ||
@@ -166,11 +212,11 @@ | ||
```js | ||
moment().format('YYYY/MMMM/D'); // 1989/January/24 | ||
moment.useJalaliSystemPrimarily(); | ||
moment().format('YYYY/MMMM/D'); // 1367/Bahman/4 | ||
moment().subtract(1,'year').format('YYYY/MMMM/D'); // 1366/bahman/4 | ||
moment().subtract(1,'month').format('YYYY/MMMM/D'); // 1367/dey/4 | ||
moment.useJalaliSystemSecondary(); | ||
moment().format('YYYY/MMMM/D'); // 1989/January/24 | ||
moment().format('YYYY/MMMM/D'); // 1989/January/24 | ||
moment.useJalaliSystemPrimarily(); | ||
moment().format('YYYY/MMMM/D'); // 1367/Bahman/4 | ||
moment().subtract(1,'year').format('YYYY/MMMM/D'); // 1366/bahman/4 | ||
moment().subtract(1,'month').format('YYYY/MMMM/D'); // 1367/dey/4 | ||
moment.useJalaliSystemSecondary(); | ||
moment().format('YYYY/MMMM/D'); // 1989/January/24 | ||
``` | ||
@@ -183,5 +229,2 @@ | ||
#### jalaali-moment | ||
A Jalaali calendar system plugin for moment.js. | ||
#### jalali-angular-datepicker ( angular2 or more) | ||
@@ -191,2 +234,6 @@ | ||
#### jalaali-moment | ||
A Jalaali calendar system plugin for moment.js is [jalaali-moment](https://github.com/jalaali/moment-jalaali). | ||
## License | ||
@@ -193,0 +240,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1562895
18
17869
253