moment-jalaali
Advanced tools
Comparing version 0.1.9 to 0.2.0
{ | ||
"name": "moment-jalaali", | ||
"version": "0.1.9", | ||
"description": "A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.", | ||
"version": "0.2.0", | ||
"description": "Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.", | ||
"author": { | ||
@@ -21,6 +21,5 @@ "name": "Behrang Noruzi Niya", | ||
], | ||
"main": "moment-jalaali.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "grunt test", | ||
"prepublish": "grunt test" | ||
"test": "make test" | ||
}, | ||
@@ -36,39 +35,10 @@ "homepage": "https://github.com/behrang/moment-jalaali", | ||
"devDependencies": { | ||
"mocha": "~1.12.0", | ||
"chai": "~1.8.0", | ||
"grunt": "~0.4.1", | ||
"grunt-cli": "~0.1.9", | ||
"grunt-contrib-watch": "~0.5.2", | ||
"grunt-contrib-uglify": "~0.2.2", | ||
"grunt-contrib-jshint": "~0.7.2", | ||
"grunt-shell": "~0.4.0", | ||
"bower": "~1.2.6" | ||
"component": "^1.0.0-rc5", | ||
"eslint": "^0.6.2", | ||
"mocha": "~1.12.0" | ||
}, | ||
"dependencies": { | ||
"moment": "~2.1.0" | ||
}, | ||
"jshintConfig": { | ||
"camelcase": true, | ||
"eqeqeq": true, | ||
"forin": true, | ||
"freeze": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": "nofunc", | ||
"newcap": true, | ||
"noarg": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"plusplus": true, | ||
"quotmark": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"asi": true, | ||
"eqnull": true, | ||
"laxbreak": true, | ||
"laxcomma": true, | ||
"node": true | ||
"moment": "^2.7.0" | ||
} | ||
} |
@@ -6,5 +6,3 @@ moment-jalaali | ||
[![Build Status](https://travis-ci.org/behrang/moment-jalaali.png?branch=master)](https://travis-ci.org/behrang/moment-jalaali) | ||
[![Dependency Status](https://gemnasium.com/behrang/moment-jalaali.png)](https://gemnasium.com/behrang/moment-jalaali) | ||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/behrang/moment-jalaali/trend.png)](https://bitdeli.com/free "Bitdeli Badge") | ||
[![Build Status](https://travis-ci.org/jalaali/moment-jalaali.png?branch=master)](https://travis-ci.org/behrang/moment-jalaali) | ||
@@ -20,4 +18,2 @@ About | ||
Gzipped minified version is about 2kb. | ||
Where to use it | ||
@@ -36,4 +32,4 @@ --------------- | ||
```js | ||
var moment = require('moment-jalaali'); | ||
moment().format('jYYYY/jM/jD'); | ||
var moment = require('moment-jalaali') | ||
moment().format('jYYYY/jM/jD') | ||
``` | ||
@@ -43,22 +39,9 @@ | ||
<script src="moment.js"></script> | ||
It is recommended to use [`component`](https://github.com/component/component). Otherwise, you may use the `build/moment-jalaali.js` file which is a larger file and includes `moment.js`. | ||
<script src="moment-jalaali.js"></script> | ||
<script> | ||
moment().format('jYYYY/jM/jD'); | ||
moment().format('jYYYY/jM/jD') | ||
</script> | ||
### Require.js | ||
```js | ||
require.config({ | ||
paths: { | ||
"moment": "path/to/moment", | ||
"moment-jalaali": "path/to/moment-jalaali" | ||
} | ||
}); | ||
define(["moment-jalaali"], function (moment) { | ||
moment().format('jYYYY/jM/jD'); | ||
}); | ||
``` | ||
API | ||
@@ -70,35 +53,39 @@ --- | ||
```js | ||
m = moment('1360/5/26', 'jYYYY/jM/jD'); // Parse a Jalaali date. | ||
m.format('jYYYY/jM/jD [is] YYYY/M/D'); // 1360/5/26 is 1981/8/17 | ||
m = moment('1360/5/26', 'jYYYY/jM/jD') // Parse a Jalaali date. | ||
m.format('jYYYY/jM/jD [is] YYYY/M/D') // 1360/5/26 is 1981/8/17 | ||
m.jYear(); // 1360 | ||
m.jMonth(); // 4 | ||
m.jDate(); // 26 | ||
m.jDayOfYear(); // 150 | ||
m.jWeek(); // 22 | ||
m.jWeekYear(); // 1360 | ||
m.jYear() // 1360 | ||
m.jMonth() // 4 | ||
m.jDate() // 26 | ||
m.jDayOfYear() // 150 | ||
m.jWeek() // 22 | ||
m.jWeekYear() // 1360 | ||
m.add(1, 'jYear'); | ||
m.add(2, 'jMonth'); | ||
m.format('jYYYY/jM/jD'); // 1361/7/26 | ||
m.add(1, 'jYear') | ||
m.add(2, 'jMonth') | ||
m.format('jYYYY/jM/jD') // 1361/7/26 | ||
m.jMonth(11); | ||
m.startOf('jMonth'); | ||
m.format('jYYYY/jM/jD'); // 1361/12/1 | ||
m.jMonth(11) | ||
m.startOf('jMonth') | ||
m.format('jYYYY/jM/jD') // 1361/12/1 | ||
m.jYear(1392); | ||
m.startOf('jYear'); | ||
m.format('jYYYY/jM/jD'); // 1392/1/1 | ||
m.jYear(1392) | ||
m.startOf('jYear') | ||
m.format('jYYYY/jM/jD') // 1392/1/1 | ||
moment('1391/12/30', 'jYYYY/jMM/jDD').isValid(); // true (leap year) | ||
moment('1392/12/30', 'jYYYY/jMM/jDD').isValid(); // false (common year) | ||
moment.jIsLeapYear(1391); // true | ||
moment.jIsLeapYear(1392); // false | ||
m.subtract(1, 'jYear') | ||
m.subtract(1, 'jMonth') | ||
m.format('jYYYY/jM/jD') // 1390/12/1 | ||
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('1391/12/30', 'jYYYY/jMM/jDD').isValid() // true (leap year) | ||
moment('1392/12/30', 'jYYYY/jMM/jDD').isValid() // false (common year) | ||
moment.jIsLeapYear(1391) // true | ||
moment.jIsLeapYear(1392) // false | ||
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('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 | ||
// Complex parse: | ||
moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD'); // 1981/07/17 | ||
moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD') // 1981/07/17 | ||
``` | ||
@@ -105,0 +92,0 @@ |
180
test.js
@@ -1,5 +0,4 @@ | ||
'use strict'; | ||
var chai = require('chai') | ||
, moment = require('./moment-jalaali') | ||
, moment = require('./index') | ||
@@ -83,3 +82,3 @@ chai.should() | ||
it('should parse with complex format', function() { | ||
var m = moment('17 26 50 1981 50 8 50', 'D jD jYYYY YYYY M M jM') | ||
var m = moment('17 26 50 1981 50 8 12', 'D jD jYYYY YYYY M M jM') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-08-17') | ||
@@ -89,5 +88,5 @@ }) | ||
it('should parse format result', function() { | ||
var format = 'jYYYY/jM/jD hh:mm:ss.SSS a' | ||
var f = 'jYYYY/jM/jD hh:mm:ss.SSS a' | ||
, m = moment() | ||
moment(m.format(format), format).isSame(m).should.be['true'] | ||
moment(m.format(f), f).isSame(m).should.be.true | ||
}) | ||
@@ -599,13 +598,16 @@ | ||
it('should return true when a valid date is parsed and false otherwise', function() { | ||
moment('1981-08-17', 'YYYY-MM-DD').isValid().should.be['true'] | ||
moment('1981-08-31', 'YYYY-MM-DD').isValid().should.be['true'] | ||
moment('1981-09-31', 'YYYY-MM-DD').isValid().should.be['false'] | ||
moment('1360 mordaad 26', 'jYYYY jMMMM jD').isValid().should.be['false'] | ||
moment('1360-05-26', 'jYYYY-jMM-jDD').isValid().should.be['true'] | ||
moment('1360-05-31', 'jYYYY-jMM-jDD').isValid().should.be['true'] | ||
moment('1360-07-30', 'jYYYY-jMM-jDD').isValid().should.be['true'] | ||
moment('1360-07-31', 'jYYYY-jMM-jDD').isValid().should.be['false'] | ||
moment('1360-12-29', 'jYYYY-jMM-jDD').isValid().should.be['true'] | ||
moment('1360-12-30', 'jYYYY-jMM-jDD').isValid().should.be['false'] | ||
moment('1360-12-31', 'jYYYY-jMM-jDD').isValid().should.be['false'] | ||
var jf = 'jYYYY/jMM/jDD' | ||
, gf = 'YYYY-MM-DD' | ||
moment('1981-08-17', gf).isValid().should.be.true | ||
moment('1981-08-31', gf).isValid().should.be.true | ||
moment('1981-09-31', gf).isValid().should.be.false | ||
moment('1360 mordaad 26', 'jYYYY jMMMM jD').isValid().should.be.false | ||
moment('1360/05/26', jf).isValid().should.be.true | ||
moment('1360/05/31', jf).isValid().should.be.true | ||
moment('1360/07/30', jf).isValid().should.be.true | ||
moment('1360/07/31', jf).isValid().should.be.false | ||
moment('1360/12/29', jf).isValid().should.be.true | ||
moment('1360/12/30', jf).isValid().should.be.false | ||
moment('1360/12/31', jf).isValid().should.be.false | ||
moment('1360/13/01', jf).isValid().should.be.false | ||
}) | ||
@@ -625,18 +627,134 @@ }) | ||
describe('#add', function () { | ||
it('should add gregorian dates correctly', function () { | ||
var gf = 'YYYY-M-D' | ||
, m = moment('1981-8-17', 'YYYY-M-D') | ||
moment(m).add(1, 'day').format(gf).should.be.equal('1981-8-18') | ||
moment(m).add(10, 'days').format(gf).should.be.equal('1981-8-27') | ||
moment(m).add(30, 'days').format(gf).should.be.equal('1981-9-16') | ||
moment(m).add(60, 'days').format(gf).should.be.equal('1981-10-16') | ||
moment(m).add(1, 'month').format(gf).should.be.equal('1981-9-17') | ||
moment(m).add(2, 'months').format(gf).should.be.equal('1981-10-17') | ||
moment(m).add(10, 'months').format(gf).should.be.equal('1982-6-17') | ||
moment(m).add(20, 'months').format(gf).should.be.equal('1983-4-17') | ||
moment(m).add(1, 'year').format(gf).should.be.equal('1982-8-17') | ||
moment(m).add(2, 'years').format(gf).should.be.equal('1983-8-17') | ||
moment(m).add(10, 'years').format(gf).should.be.equal('1991-8-17') | ||
moment(m).add(20, 'years').format(gf).should.be.equal('2001-8-17') | ||
}) | ||
it('should add jalaali dates correctly', function () { | ||
var jf = 'jYYYY/jM/jD' | ||
, m = moment('1360/5/26', 'jYYYY/jM/jD') | ||
moment(m).add(1, 'day').format(jf).should.be.equal('1360/5/27') | ||
moment(m).add(4, 'days').format(jf).should.be.equal('1360/5/30') | ||
moment(m).add(10, 'days').format(jf).should.be.equal('1360/6/5') | ||
moment(m).add(30, 'days').format(jf).should.be.equal('1360/6/25') | ||
moment(m).add(60, 'days').format(jf).should.be.equal('1360/7/24') | ||
moment(m).add(365, 'days').format(jf).should.be.equal('1361/5/26') | ||
moment(m).add(1, 'jmonth').format(jf).should.be.equal('1360/6/26') | ||
moment(m).add(2, 'jmonths').format(jf).should.be.equal('1360/7/26') | ||
moment(m).add(10, 'jmonths').format(jf).should.be.equal('1361/3/26') | ||
moment(m).add(20, 'jmonths').format(jf).should.be.equal('1362/1/26') | ||
moment(m).add(1, 'jyear').format(jf).should.be.equal('1361/5/26') | ||
moment(m).add(2, 'jyears').format(jf).should.be.equal('1362/5/26') | ||
moment(m).add(3, 'jyears').format(jf).should.be.equal('1363/5/26') | ||
moment(m).add(4, 'jyears').format(jf).should.be.equal('1364/5/26') | ||
moment(m).add(10, 'jyears').format(jf).should.be.equal('1370/5/26') | ||
moment(m).add(20, 'jyears').format(jf).should.be.equal('1380/5/26') | ||
}) | ||
it('should retain last day of month when adding months or years', function () { | ||
var jf = 'jYYYY/jM/jD' | ||
, m = moment('1393/6/31', jf) | ||
moment(m).add(1, 'jmonth').format(jf).should.be.equal('1393/7/30') | ||
moment(m).add(5, 'jmonth').format(jf).should.be.equal('1393/11/30') | ||
moment(m).add(6, 'jmonth').format(jf).should.be.equal('1393/12/29') | ||
m = moment('1391/12/30', jf) | ||
moment(m).add(1, 'jyear').format(jf).should.be.equal('1392/12/29') | ||
moment(m).add(2, 'jyear').format(jf).should.be.equal('1393/12/29') | ||
moment(m).add(3, 'jyear').format(jf).should.be.equal('1394/12/29') | ||
moment(m).add(4, 'jyear').format(jf).should.be.equal('1395/12/30') | ||
}) | ||
}) | ||
describe('#subtract', function () { | ||
it('should subtract gregorian dates correctly', function () { | ||
var gf = 'YYYY-M-D' | ||
, m = moment('1981-8-17', 'YYYY-M-D') | ||
moment(m).subtract(1, 'day').format(gf).should.be.equal('1981-8-16') | ||
moment(m).subtract(10, 'days').format(gf).should.be.equal('1981-8-7') | ||
moment(m).subtract(30, 'days').format(gf).should.be.equal('1981-7-18') | ||
moment(m).subtract(60, 'days').format(gf).should.be.equal('1981-6-18') | ||
moment(m).subtract(1, 'month').format(gf).should.be.equal('1981-7-17') | ||
moment(m).subtract(2, 'months').format(gf).should.be.equal('1981-6-17') | ||
moment(m).subtract(10, 'months').format(gf).should.be.equal('1980-10-17') | ||
moment(m).subtract(20, 'months').format(gf).should.be.equal('1979-12-17') | ||
moment(m).subtract(1, 'year').format(gf).should.be.equal('1980-8-17') | ||
moment(m).subtract(2, 'years').format(gf).should.be.equal('1979-8-17') | ||
moment(m).subtract(10, 'years').format(gf).should.be.equal('1971-8-17') | ||
moment(m).subtract(20, 'years').format(gf).should.be.equal('1961-8-17') | ||
}) | ||
it('should subtract jalaali dates correctly', function () { | ||
var jf = 'jYYYY/jM/jD' | ||
, m = moment('1360/5/26', 'jYYYY/jM/jD') | ||
moment(m).subtract(1, 'day').format(jf).should.be.equal('1360/5/25') | ||
moment(m).subtract(4, 'days').format(jf).should.be.equal('1360/5/22') | ||
moment(m).subtract(10, 'days').format(jf).should.be.equal('1360/5/16') | ||
moment(m).subtract(30, 'days').format(jf).should.be.equal('1360/4/27') | ||
moment(m).subtract(60, 'days').format(jf).should.be.equal('1360/3/28') | ||
moment(m).subtract(365, 'days').format(jf).should.be.equal('1359/5/26') | ||
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1360/4/26') | ||
moment(m).subtract(2, 'jmonths').format(jf).should.be.equal('1360/3/26') | ||
moment(m).subtract(10, 'jmonths').format(jf).should.be.equal('1359/7/26') | ||
moment(m).subtract(20, 'jmonths').format(jf).should.be.equal('1358/9/26') | ||
moment(m).subtract(1, 'jyear').format(jf).should.be.equal('1359/5/26') | ||
moment(m).subtract(2, 'jyears').format(jf).should.be.equal('1358/5/26') | ||
moment(m).subtract(3, 'jyears').format(jf).should.be.equal('1357/5/26') | ||
moment(m).subtract(4, 'jyears').format(jf).should.be.equal('1356/5/26') | ||
moment(m).subtract(10, 'jyears').format(jf).should.be.equal('1350/5/26') | ||
moment(m).subtract(20, 'jyears').format(jf).should.be.equal('1340/5/26') | ||
}) | ||
it('should retain last day of month when subtracting months or years', function () { | ||
var jf = 'jYYYY/jM/jD' | ||
, m = moment('1393/1/31', jf) | ||
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/29') | ||
moment(m).subtract(6, 'jmonth').format(jf).should.be.equal('1392/7/30') | ||
moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/31') | ||
m = moment('1391/12/30', jf) | ||
moment(m).subtract(1, 'jyear').format(jf).should.be.equal('1390/12/29') | ||
moment(m).subtract(2, 'jyear').format(jf).should.be.equal('1389/12/29') | ||
moment(m).subtract(3, 'jyear').format(jf).should.be.equal('1388/12/29') | ||
moment(m).subtract(4, 'jyear').format(jf).should.be.equal('1387/12/30') | ||
}) | ||
}) | ||
describe('.jIsLeapYear', function() { | ||
it('should return true for Jalaali leap years and false otherwise', function() { | ||
moment.jIsLeapYear(1391).should.be['true'] | ||
moment.jIsLeapYear(1392).should.be['false'] | ||
moment.jIsLeapYear(1393).should.be['false'] | ||
moment.jIsLeapYear(1394).should.be['false'] | ||
moment.jIsLeapYear(1395).should.be['true'] | ||
moment.jIsLeapYear(1396).should.be['false'] | ||
moment.jIsLeapYear(1397).should.be['false'] | ||
moment.jIsLeapYear(1398).should.be['false'] | ||
moment.jIsLeapYear(1399).should.be['true'] | ||
moment.jIsLeapYear(1400).should.be['false'] | ||
moment.jIsLeapYear(1401).should.be['false'] | ||
moment.jIsLeapYear(1402).should.be['false'] | ||
moment.jIsLeapYear(1403).should.be['true'] | ||
moment.jIsLeapYear(1404).should.be['false'] | ||
moment.jIsLeapYear(1391).should.be.true | ||
moment.jIsLeapYear(1392).should.be.false | ||
moment.jIsLeapYear(1393).should.be.false | ||
moment.jIsLeapYear(1394).should.be.false | ||
moment.jIsLeapYear(1395).should.be.true | ||
moment.jIsLeapYear(1396).should.be.false | ||
moment.jIsLeapYear(1397).should.be.false | ||
moment.jIsLeapYear(1398).should.be.false | ||
moment.jIsLeapYear(1399).should.be.true | ||
moment.jIsLeapYear(1400).should.be.false | ||
moment.jIsLeapYear(1401).should.be.false | ||
moment.jIsLeapYear(1402).should.be.false | ||
moment.jIsLeapYear(1403).should.be.true | ||
moment.jIsLeapYear(1404).should.be.false | ||
}) | ||
@@ -650,3 +768,3 @@ }) | ||
moment.loadPersian() | ||
m = moment('1981/08/17') | ||
m = moment('1981-08-17') | ||
m.format('D MMMM YYYY').should.be.equal('17 اوت 1981') | ||
@@ -653,0 +771,0 @@ m.format('jD jMMMM jYYYY').should.be.equal('26 امرداد 1360') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
171976
4
11
4779
98
1
1
+ Addedmoment@2.30.1(transitive)
- Removedmoment@2.1.0(transitive)
Updatedmoment@^2.7.0