jalali-moment
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -318,3 +318,5 @@ | ||
} | ||
function isNull(variable) { | ||
return variable === null || variable === undefined; | ||
} | ||
function addTimeToArrayFromToken(token, input, config) { | ||
@@ -327,3 +329,3 @@ var a | ||
case 'jMM': | ||
datePartArray[1] = input == null ? 0 : ~~input - 1; | ||
datePartArray[1] = isNull(input)? 0 : ~~input - 1; | ||
break; | ||
@@ -333,3 +335,3 @@ case 'jMMM': | ||
a = moment.localeData(config._l).jMonthsParse(input); | ||
if (a != null) | ||
if (!isNull(a)) | ||
datePartArray[1] = a; | ||
@@ -343,3 +345,3 @@ else | ||
case 'jDDDD': | ||
if (input != null) | ||
if (!isNull(input)) | ||
datePartArray[2] = ~~input; | ||
@@ -354,3 +356,3 @@ break; | ||
} | ||
if (input == null) | ||
if (isNull(input)) | ||
config._isValid = false | ||
@@ -366,7 +368,7 @@ } | ||
if ((jy == null) && (jm == null) && (jd == null)) | ||
if (isNull(jy) && isNull(jm) && isNull(jd)) | ||
return [0, 0, 1]; | ||
jy = jy != null ? jy : 0; | ||
jm = jm != null ? jm : 0; | ||
jd = jd != null ? jd : 1; | ||
jy = !isNull(jy) ? jy : 0; | ||
jm = !isNull(jm) ? jm : 0; | ||
jd = !isNull(jd) ? jd : 1; | ||
if (jd < 1 || jd > jMoment.jDaysInMonth(jy, jm) || jm < 0 || jm > 11) | ||
@@ -433,3 +435,3 @@ config._isValid = false; | ||
currentScore += tempMoment._il.length; | ||
if (scoreToBeat == null || currentScore < scoreToBeat) { | ||
if (isNull(scoreToBeat) || currentScore < scoreToBeat) { | ||
scoreToBeat = currentScore; | ||
@@ -575,3 +577,2 @@ bestMoment = tempMoment | ||
jMoment.fn.format = function (format) { | ||
if (format) { | ||
@@ -608,3 +609,3 @@ format = fixFormat(format, this); | ||
, g; | ||
if (input != null) { | ||
if (!isNull(input)) { | ||
if (typeof input === 'string') { | ||
@@ -648,3 +649,3 @@ input = this.lang().jMonthsParse(input); | ||
var dayOfYear = Math.round((jMoment(this).startOf('day') - jMoment(this).startOf('jYear')) / 864e5) + 1; | ||
return input == null ? dayOfYear : this.add(input - dayOfYear, 'd'); | ||
return isNull(input) ? dayOfYear : this.add(input - dayOfYear, 'd'); | ||
}; | ||
@@ -654,3 +655,3 @@ | ||
var week = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).week; | ||
return input == null ? week : this.add((input - week) * 7, 'd'); | ||
return isNull(input) ? week : this.add((input - week) * 7, 'd'); | ||
}; | ||
@@ -660,3 +661,3 @@ | ||
var year = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year; | ||
return input == null ? year : this.add(input - year, 'y'); | ||
return isNull(input) ? year : this.add(input - year, 'y'); | ||
}; | ||
@@ -666,3 +667,3 @@ | ||
var temp; | ||
if (units !== null && !isNaN(+units)) { | ||
if (!isNull(units) && !isNaN(+units)) { | ||
temp = val; | ||
@@ -685,3 +686,3 @@ val = units; | ||
var temp; | ||
if (units !== null && !isNaN(+units)) { | ||
if (!isNull(units) && !isNaN(+units)) { | ||
temp = val; | ||
@@ -688,0 +689,0 @@ val = units; |
{ | ||
"name": "jalali-moment", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.", | ||
@@ -11,3 +11,3 @@ "author": { | ||
"keywords": [ | ||
"jalaali", | ||
"date", | ||
"jalali", | ||
@@ -39,3 +39,3 @@ "typescript", | ||
"chai": "^2.2.0", | ||
"eslint": "^0.18.0", | ||
"eslint": "^3.19.0", | ||
"mocha": "^2.2.1", | ||
@@ -42,0 +42,0 @@ "path": "^0.12.7", |
# jalali-moment | ||
A Jalali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js. | ||
A Jalali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js. [DEMO](https://fingerpich.github.io/jalali-moment) | ||
@@ -54,3 +54,3 @@ [![MIT License][license-image]][license-url] | ||
and use it in component template | ||
``` | ||
```HTML | ||
<div>loadedData.date|jalali</div> | ||
@@ -65,2 +65,20 @@ ``` | ||
### Browser(es5) | ||
```HTML | ||
<script src="thisRepo/dist/jalali-moment.js"></script> | ||
<script> | ||
moment().format('jYYYY/jM/jD') | ||
</script> | ||
``` | ||
### Plunker | ||
```HTML | ||
<script src='https://unpkg.com/jalali-moment/dist/jalali-moment.js'></script> | ||
<script> | ||
moment().format('jYYYY/jM/jD') | ||
</script> | ||
``` | ||
[for example](https://embed.plnkr.co/Gggh1u/) | ||
## API | ||
@@ -71,37 +89,12 @@ | ||
```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 | ||
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 | ||
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.add(3, 'day') | ||
m.format('jYYYY/jM/jD') // 1361/7/29 | ||
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.subtract(1, 'jYear') | ||
m.subtract(1, 'jMonth') | ||
m.format('jYYYY/jM/jD') // 1390/12/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 | ||
moment.jDaysInMonth(1395, 11) // 30 | ||
moment.jDaysInMonth(1394, 11) // 29 | ||
moment('1392/6/3 16:40', 'jYYYY/jM/jD HH:mm').format('YYYY-M-D HH:mm:ss') // 2013-8-25 16:40:00 | ||
@@ -111,3 +104,2 @@ | ||
// Complex parse: | ||
moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD') // 1981/07/17 | ||
@@ -114,0 +106,0 @@ ``` |
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
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
344669
12
2174
131