jalali-moment
Advanced tools
Comparing version 3.3.3 to 3.3.4
@@ -35,2 +35,6 @@ | ||
var CalendarSystems = { | ||
Jalali: 1, | ||
Gregorian: 2, | ||
} | ||
var formatTokenFunctions = { | ||
@@ -434,3 +438,3 @@ jM: function () { | ||
if (isNull(jy) && isNull(jm) && isNull(jd)){ | ||
return [0, 0, 1]; | ||
return; | ||
} | ||
@@ -571,3 +575,10 @@ jy = !isNull(jy) ? jy : 0; | ||
************************************/ | ||
function isJalali (momentObj) { | ||
return momentObj && | ||
(momentObj.calSystem === CalendarSystems.Jalali) || | ||
(moment.justUseJalali && momentObj.calSystem !== CalendarSystems.Gregorian); | ||
} | ||
function isInputJalali(format, momentObj, input) { | ||
return (moment.justUseJalali || (momentObj.calSystem === CalendarSystems.Jalali)) | ||
} | ||
function makeMoment(input, format, lang, strict, utc) { | ||
@@ -579,4 +590,5 @@ if (typeof lang === "boolean") { | ||
} | ||
var itsJalaliDate = (isJalali(this)); | ||
if(input && (typeof input === "string") && !format && itsJalaliDate && !moment.useGregorianParser) { | ||
const inputIsJalali = isInputJalali(format, this, input); | ||
// var itsJalaliDate = (isJalali(this)); | ||
if(input && (typeof input === "string") && !format && inputIsJalali && !moment.useGregorianParser) { | ||
input = input.replace(/\//g,"-"); | ||
@@ -605,3 +617,3 @@ if(/\d{4}\-\d{2}\-\d{2}/.test(input)) { | ||
} | ||
if (format && itsJalaliDate){ | ||
if (format && inputIsJalali){ | ||
format = toJalaliFormat(format); | ||
@@ -631,7 +643,9 @@ } | ||
removeParsedTokens(config); | ||
format = "YYYY-MM-DD-" + config._f; | ||
input = leftZeroFill(date[0], 4) + "-" | ||
+ leftZeroFill(date[1] + 1, 2) + "-" | ||
+ leftZeroFill(date[2], 2) + "-" | ||
+ config._i; | ||
if (date) { | ||
format = "YYYY-MM-DD-" + config._f; | ||
input = leftZeroFill(date[0], 4) + "-" | ||
+ leftZeroFill(date[1] + 1, 2) + "-" | ||
+ leftZeroFill(date[2], 2) + "-" | ||
+ config._i; | ||
} | ||
} | ||
@@ -692,4 +706,5 @@ } | ||
jMoment.fn.format = function (format) { | ||
format = format || jMoment.defaultFormat; | ||
if (format) { | ||
if(isJalali(this)) { | ||
if (isJalali(this)) { | ||
format = toJalaliFormat(format); | ||
@@ -811,6 +826,2 @@ } | ||
}; | ||
function isJalali (momentObj) { | ||
var calSystem = momentObj ? momentObj.calSystem : 1; | ||
return calSystem === 1 || (moment.justUseJalali && calSystem !== 2); | ||
} | ||
@@ -923,7 +934,7 @@ jMoment.fn.weekYear = function (input) { | ||
jMoment.fn.doAsJalali = function () { | ||
this.calSystem = 1; | ||
this.calSystem = CalendarSystems.Jalali; | ||
return this; | ||
}; | ||
jMoment.fn.doAsGregorian = function () { | ||
this.calSystem = 2; | ||
this.calSystem = CalendarSystems.Gregorian; | ||
return this; | ||
@@ -930,0 +941,0 @@ }; |
{ | ||
"name": "jalali-moment", | ||
"version": "3.3.3", | ||
"version": "3.3.4", | ||
"description": "Manipulate and convert Jalali and Gregorian date easily", | ||
@@ -5,0 +5,0 @@ "author": { |
674
test.js
var chai = require("chai") | ||
, moment = require("./jalali-moment.js"); | ||
var chai = require("chai"); | ||
var jalaliMoment = require("./jalali-moment.js"); | ||
var moment = require("moment"); | ||
chai.should(); | ||
moment.updateLocale("en" | ||
jalaliMoment.updateLocale("en" | ||
, { week: | ||
@@ -25,3 +26,3 @@ { dow: 6 | ||
it("should parse gregorian dates", function() { | ||
var m = moment("1981/8/17 07:10:20", "YYYY/M/D hh:mm:ss"); | ||
var m = jalaliMoment("1981/8/17 07:10:20", "YYYY/M/D hh:mm:ss"); | ||
m.format("YYYY-MM-DD hh:mm:ss").should.be.equal("1981-08-17 07:10:20"); | ||
@@ -31,25 +32,26 @@ m.milliseconds().should.be.equal(0); | ||
it("parse persian dates", function () { | ||
moment.locale("fa"); | ||
var m1 = moment("1367/11/04", "YYYY/M/D"); | ||
jalaliMoment.locale("fa"); | ||
var m1 = jalaliMoment("1367/11/04", "YYYY/M/D"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
m1 = moment("1367/11/4", "YYYY/M/D"); | ||
m1 = jalaliMoment("1367/11/4", "YYYY/M/D"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
m1 = moment("1367/1/4", "YYYY/M/D"); | ||
m1 = jalaliMoment("1367/1/4", "YYYY/M/D"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1367/01/04"); | ||
var m1 = moment("13671124", "YYYYMMDD"); | ||
var m1 = jalaliMoment("13671124", "YYYYMMDD"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1367/11/24"); | ||
// var m1 = moment("1367/245"); | ||
// var m1 = jalaliMoment("1367/245"); | ||
// m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
moment.locale("en"); | ||
jalaliMoment.locale("en"); | ||
}); | ||
it("should parse correctly when input is only time", function() { | ||
var jm = jalaliMoment("07:10:20", "hh:mm:ss"); | ||
var m = moment("07:10:20", "hh:mm:ss"); | ||
m.format("YYYY-MM-DD hh:mm:ss").should.be.equal("0000-01-01 07:10:20"); | ||
jm.format("YYYY-MM-DD hh:mm:ss").should.be.equal(m.format("YYYY-MM-DD hh:mm:ss")) | ||
}); | ||
it("should parse when only Jalaali year is in the format", function() { | ||
var m = moment("08 1360 17", "MM jYYYY DD"); | ||
var m = jalaliMoment("08 1360 17", "MM jYYYY DD"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
m = moment("08 60 17", "MM jYY DD"); | ||
m = jalaliMoment("08 60 17", "MM jYY DD"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
@@ -59,3 +61,3 @@ }); | ||
it("should parse when only Jalaali month is in the format", function() { | ||
var m = moment("1981 5 17", "YYYY jM D"); | ||
var m = jalaliMoment("1981 5 17", "YYYY jM D"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
@@ -65,5 +67,5 @@ }); | ||
it("should parse when only Jalaali month string is in the format", function() { | ||
var m = moment("1981 Amo 17", "YYYY jMMM D"); | ||
var m = jalaliMoment("1981 Amo 17", "YYYY jMMM D"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
m = moment("1981 Mordaad 17", "YYYY jMMMM D"); | ||
m = jalaliMoment("1981 Mordaad 17", "YYYY jMMMM D"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
@@ -73,3 +75,3 @@ }); | ||
it("should parse when only Jalaali date is in the format", function() { | ||
var m = moment("1981 26 8", "YYYY jD M"); | ||
var m = jalaliMoment("1981 26 8", "YYYY jD M"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-15"); | ||
@@ -79,5 +81,5 @@ }); | ||
it("should parse when Jalaali year and month are in the format", function() { | ||
var m = moment("17 1360 5", "D jYYYY jM"); | ||
var m = jalaliMoment("17 1360 5", "D jYYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
m = moment("1392 7", "jYYYY jM"); | ||
m = jalaliMoment("1392 7", "jYYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("2013-09-23"); | ||
@@ -87,3 +89,3 @@ }); | ||
it("should parse when Jalaali year and date are in the format", function() { | ||
var m = moment("26 1360 8", "jD jYYYY M"); | ||
var m = jalaliMoment("26 1360 8", "jD jYYYY M"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-15"); | ||
@@ -93,3 +95,4 @@ }); | ||
it("should parse when Jalaali month and date are in the format", function() { | ||
var m = moment("26 1981 5", "jD YYYY jM"); | ||
jalaliMoment.locale('en'); | ||
var m = jalaliMoment("26 1981 5", "jD YYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
@@ -99,3 +102,3 @@ }); | ||
it("should parse when Jalaali year, month and date are in the format", function() { | ||
var m = moment("26 1360 5", "jD jYYYY jM"); | ||
var m = jalaliMoment("26 1360 5", "jD jYYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
@@ -105,3 +108,3 @@ }); | ||
it("should parse with complex format", function() { | ||
var m = moment("17 26 50 1981 50 8 12", "D jD jYYYY YYYY M M jM"); | ||
var m = jalaliMoment("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"); | ||
@@ -112,8 +115,8 @@ }); | ||
var f = "jYYYY/jM/jD hh:mm:ss.SSS a" | ||
, m = moment(); | ||
moment(m.format(f), f).isSame(m).should.be.equal(true); | ||
, m = jalaliMoment(); | ||
jalaliMoment(m.format(f), f).isSame(m).should.be.equal(true); | ||
}); | ||
it("should be able to parse in utc", function() { | ||
var m = moment.utc("1360/5/26 07:10:20", "jYYYY/jM/jD hh:mm:ss"); | ||
var m = jalaliMoment.utc("1360/5/26 07:10:20", "jYYYY/jM/jD hh:mm:ss"); | ||
m.format("YYYY-MM-DD hh:mm:ss Z").should.be.equal("1981-08-17 07:10:20 +00:00"); | ||
@@ -127,23 +130,23 @@ }); | ||
, m; | ||
m = moment("60 11 12", ["D YY M", "M D YY", "YY M D"]); | ||
m = jalaliMoment("60 11 12", ["D YY M", "M D YY", "YY M D"]); | ||
m.format("YY-MM-DD").should.be.equal("60-11-12"); | ||
m = moment("10 11 12", [p1, p2, p3]); | ||
m = jalaliMoment("10 11 12", [p1, p2, p3]); | ||
m.format("jYY-jMM-jDD").should.be.equal("10-11-12"); | ||
m = moment("10 11 12", [p2, p3, p1]); | ||
m = jalaliMoment("10 11 12", [p2, p3, p1]); | ||
m.format("jYY-jMM-jDD").should.be.equal("12-10-11"); | ||
m = moment("10 11 12", [p3, p1, p2]); | ||
m = jalaliMoment("10 11 12", [p3, p1, p2]); | ||
m.format("jYY-jMM-jDD").should.be.equal("11-12-10"); | ||
m = moment("10 11 12", [p3, p2, p1]); | ||
m = jalaliMoment("10 11 12", [p3, p2, p1]); | ||
m.format("jYY-jMM-jDD").should.be.equal("11-12-10"); | ||
m = moment("60-11-12", [p3, p2, p1]); | ||
m = jalaliMoment("60-11-12", [p3, p2, p1]); | ||
m.format("jYY-jMM-jDD").should.be.equal("60-11-12"); | ||
m = moment("60 11 12", [p3, p2, p1]); | ||
m = jalaliMoment("60 11 12", [p3, p2, p1]); | ||
m.format("jYY-jMM-jDD").should.be.equal("60-11-12"); | ||
m = moment("60 8 31", ["YY M D", "jYY jM jD"]); | ||
m = jalaliMoment("60 8 31", ["YY M D", "jYY jM jD"]); | ||
m.format("YY-MM-DD").should.be.equal("60-08-31"); | ||
m = moment("60 8 31", ["jYY jM jD", "YY M D"]); | ||
m = jalaliMoment("60 8 31", ["jYY jM jD", "YY M D"]); | ||
m.format("YY-MM-DD").should.be.equal("60-08-31"); | ||
m = moment("60 5 31", ["YY M D", "jYY jM jD"]); | ||
m = jalaliMoment("60 5 31", ["YY M D", "jYY jM jD"]); | ||
m.format("YY-MM-DD").should.be.equal("60-05-31"); | ||
m = moment("60 5 31", ["jYY jM jD", "YY M D"]); | ||
m = jalaliMoment("60 5 31", ["jYY jM jD", "YY M D"]); | ||
m.format("jYY-jMM-jDD").should.be.equal("60-05-31"); | ||
@@ -155,3 +158,3 @@ }); | ||
it("should work normally when there is no Jalaali token", function() { | ||
var m = moment("1981-08-17 07:10:20", "YYYY-MM-DD hh:mm:ss"); | ||
var m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD hh:mm:ss"); | ||
m.format("YYYY-MM-DD hh:mm:ss").should.be.equal("1981-08-17 07:10:20"); | ||
@@ -161,3 +164,3 @@ }); | ||
it("should format to Jalaali with Jalaali tokens", function() { | ||
var m = moment("1981-08-17 07:10:20", "YYYY-MM-DD hh:mm:ss"); | ||
var m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD hh:mm:ss"); | ||
m.format("jYYYY-jMM-jDD hh:mm:ss").should.be.equal("1360-05-26 07:10:20"); | ||
@@ -167,3 +170,3 @@ }); | ||
it("should format with escaped and unescaped tokens", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("[My] birt\\h y[ea]r [is] jYYYY or YYYY").should.be.equal("My birth year is 1360 or 1981"); | ||
@@ -173,3 +176,3 @@ }); | ||
it("should format with mixed tokens", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jYYYY/jMM/jDD = YYYY-MM-DD").should.be.equal("1360/05/26 = 1981-08-17"); | ||
@@ -179,3 +182,3 @@ }); | ||
it("should format with jMo", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jMo").should.be.equal("5th"); | ||
@@ -185,3 +188,3 @@ }); | ||
it("should format with jM", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jM").should.be.equal("5"); | ||
@@ -191,3 +194,3 @@ }); | ||
it("should format with jMM", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jMM").should.be.equal("05"); | ||
@@ -197,3 +200,3 @@ }); | ||
it("should format with jMMM", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jMMM").should.be.equal("Amo"); | ||
@@ -203,3 +206,3 @@ }); | ||
it("should format with jMMMM", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jMMMM").should.be.equal("Mordaad"); | ||
@@ -209,3 +212,3 @@ }); | ||
it("should format with jDo", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jDo").should.be.equal("26th"); | ||
@@ -215,3 +218,3 @@ }); | ||
it("should format with jD", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jD").should.be.equal("26"); | ||
@@ -221,5 +224,5 @@ }); | ||
it("should format with jDD", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jDD").should.be.equal("26"); | ||
m = moment("1981-08-23", "YYYY-MM-DD"); | ||
m = jalaliMoment("1981-08-23", "YYYY-MM-DD"); | ||
m.format("jDD").should.be.equal("01"); | ||
@@ -229,3 +232,3 @@ }); | ||
it("should format with jDDD", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jDDD").should.be.equal("150"); | ||
@@ -235,3 +238,3 @@ }); | ||
it("should format with jDDDo", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jDDDo").should.be.equal("150th"); | ||
@@ -241,5 +244,5 @@ }); | ||
it("should format with jDDDD", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jDDDD").should.be.equal("150"); | ||
m = moment("1981-03-21", "YYYY-MM-DD"); | ||
m = jalaliMoment("1981-03-21", "YYYY-MM-DD"); | ||
m.format("jDDDD").should.be.equal("001"); | ||
@@ -249,3 +252,3 @@ }); | ||
it("should format with jwo", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jwo").should.be.equal("22nd"); | ||
@@ -255,3 +258,3 @@ }); | ||
it("should format with jw", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jw").should.be.equal("22"); | ||
@@ -261,5 +264,5 @@ }); | ||
it("should format with jww", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jww").should.be.equal("22"); | ||
m = moment("1981-04-23", "YYYY-MM-DD"); | ||
m = jalaliMoment("1981-04-23", "YYYY-MM-DD"); | ||
m.format("jww").should.be.equal("05"); | ||
@@ -269,3 +272,3 @@ }); | ||
it("should format with jYY", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jYY").should.be.equal("60"); | ||
@@ -275,3 +278,3 @@ }); | ||
it("should format with jYYYY", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jYYYY").should.be.equal("1360"); | ||
@@ -281,3 +284,3 @@ }); | ||
it("should format with jYYYYY", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jYYYYY").should.be.equal("01360"); | ||
@@ -287,3 +290,3 @@ }); | ||
it("should format with jgg", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jgg").should.be.equal("60"); | ||
@@ -293,3 +296,3 @@ }); | ||
it("should format with jgggg", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jgggg").should.be.equal("1360"); | ||
@@ -299,3 +302,3 @@ }); | ||
it("should format with jggggg", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("jggggg").should.be.equal("01360"); | ||
@@ -305,3 +308,3 @@ }); | ||
it("should work with long date formats too", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.format("LT").should.be.equal("12:00 AM"); | ||
@@ -319,3 +322,3 @@ m.format("L").should.be.equal("1360/05/26"); | ||
it("should format another", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
// m.format("Z").should.be.equal("+03:30"); its depend on where it executed | ||
@@ -333,3 +336,3 @@ // m.format("X").should.be.equal("366841800"); | ||
it("should return Jalaali year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jYear().should.be.equal(1360); | ||
@@ -339,6 +342,6 @@ }); | ||
it("should set Jalaali year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jYear(1392); | ||
m.format("jYYYY/jM/jD").should.be.equal("1392/5/26"); | ||
m = moment("2013-03-20", "YYYY-MM-DD"); | ||
m = jalaliMoment("2013-03-20", "YYYY-MM-DD"); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/30"); | ||
@@ -350,3 +353,3 @@ m.jYear(1392); | ||
it("should also has jYears alias", function() { | ||
moment.fn.jYear.should.be.equal(moment.fn.jYears); | ||
jalaliMoment.fn.jYear.should.be.equal(jalaliMoment.fn.jYears); | ||
}); | ||
@@ -357,3 +360,3 @@ }); | ||
it("should return Jalaali month", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jMonth().should.be.equal(4); | ||
@@ -363,10 +366,10 @@ }); | ||
it("should set Jalaali month", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jMonth(7); | ||
m.format("jYYYY/jM/jD").should.be.equal("1360/8/26"); | ||
m = moment("2012-08-21", "YYYY-MM-DD"); | ||
m = jalaliMoment("2012-08-21", "YYYY-MM-DD"); | ||
m.format("jYY/jM/jD").should.be.equal("91/5/31"); | ||
m.jMonth(11); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/30"); | ||
m = moment("2013-08-22"); | ||
m = jalaliMoment("2013-08-22"); | ||
m.format("jYY/jM/jD").should.be.equal("92/5/31"); | ||
@@ -378,3 +381,3 @@ m.jMonth(11); | ||
it("should also has jMonths alias", function() { | ||
moment.fn.jMonth.should.be.equal(moment.fn.jMonths); | ||
jalaliMoment.fn.jMonth.should.be.equal(jalaliMoment.fn.jMonths); | ||
}); | ||
@@ -385,3 +388,3 @@ }); | ||
it("should return Jalaali week day name", function() { | ||
var m = moment("1989-01-24", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1989-01-24", "YYYY-MM-DD"); | ||
m.jDay().should.be.equal(3); | ||
@@ -391,3 +394,3 @@ }); | ||
it("should set Jalaali month", function() { | ||
var m = moment("1989-01-24", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1989-01-24", "YYYY-MM-DD"); | ||
m.jDay(5); | ||
@@ -397,6 +400,20 @@ m.format("jYYYY/jM/jD").should.be.equal("1367/11/6"); | ||
}); | ||
describe("#jDaysInMonth", function() { | ||
it("should return Jalaali days count in month", function() { | ||
const md = jalaliMoment.from('1398/12/01', 'fa', 'YYYY/MM/DD').jDaysInMonth() | ||
md.should.be.equal(29); | ||
}); | ||
it("should return ordibehesht days count", function() { | ||
const md = jalaliMoment.from('1398/01/01', 'fa', 'jYYYY/jMM/jDD').jDaysInMonth(); | ||
md.should.be.equal(31); | ||
}); | ||
it("should return leap year esfand days count", function() { | ||
const md = jalaliMoment.jDaysInMonth(1398, 11); // esfand 98 | ||
md.should.be.equal(29); | ||
}); | ||
}); | ||
describe("#jDate", function() { | ||
it("should return Jalaali date", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jDate().should.be.equal(26); | ||
@@ -406,6 +423,6 @@ }); | ||
it("should set Jalaali date", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jDate(30); | ||
m.format("jYYYY/jM/jD").should.be.equal("1360/5/30"); | ||
m = moment("2013-03-01", "YYYY-MM-DD"); | ||
m = jalaliMoment("2013-03-01", "YYYY-MM-DD"); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/11"); | ||
@@ -425,3 +442,3 @@ m.jDate(29); | ||
it("should also has jDates alias", function() { | ||
moment.fn.jDate.should.be.equal(moment.fn.jDates); | ||
jalaliMoment.fn.jDate.should.be.equal(jalaliMoment.fn.jDates); | ||
}); | ||
@@ -432,9 +449,9 @@ }); | ||
it("should return Jalaali date of year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jDayOfYear().should.be.equal(150); | ||
m = moment("1981-03-21", "YYYY-MM-DD"); | ||
m = jalaliMoment("1981-03-21", "YYYY-MM-DD"); | ||
m.jDayOfYear().should.be.equal(1); | ||
m = moment("1982-03-20", "YYYY-MM-DD"); | ||
m = jalaliMoment("1982-03-20", "YYYY-MM-DD"); | ||
m.jDayOfYear().should.be.equal(365); | ||
m = moment("1984-03-20", "YYYY-MM-DD"); | ||
m = jalaliMoment("1984-03-20", "YYYY-MM-DD"); | ||
m.jDayOfYear().should.be.equal(366); | ||
@@ -444,3 +461,3 @@ }); | ||
it("should set Jalaali date of year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jDayOfYear(30); | ||
@@ -465,4 +482,4 @@ m.format("jYYYY/jM/jD").should.be.equal("1360/1/30"); | ||
it("jweek with both locale", function() { | ||
var m = moment("1396/01/05","jYYYY/jMM/jDD"); | ||
moment.locale("en"); | ||
var m = jalaliMoment("1396/01/05","jYYYY/jMM/jDD"); | ||
jalaliMoment.locale("en"); | ||
m.locale("en"); | ||
@@ -475,9 +492,9 @@ m.format("jYY/jM/jD").should.be.equal("96/1/5"); | ||
it("should return Jalaali week of year", function() { | ||
var m = moment("1396/01/04","jYYYY/jMM/jDD"); | ||
var m = jalaliMoment("1396/01/04","jYYYY/jMM/jDD"); | ||
m.format("jYY/jM/jD").should.be.equal("96/1/4"); | ||
m.jWeek().should.be.equal(1); | ||
m = moment("1396/01/05","jYYYY/jMM/jDD"); | ||
m = jalaliMoment("1396/01/05","jYYYY/jMM/jDD"); | ||
m.format("jYY/jM/jD").should.be.equal("96/1/5"); | ||
m.jWeek().should.be.equal(2); | ||
m = moment("1981-08-17", "YYYY-MM-DD"); | ||
m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jWeek().should.be.equal(22); | ||
@@ -559,3 +576,3 @@ m.jDayOfYear(1); | ||
it("should set Jalaali week of year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jWeek(1); | ||
@@ -580,3 +597,3 @@ m.format("jYY/jM/jD").should.be.equal("60/1/3"); | ||
it("should return Jalaali week year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jWeekYear().should.be.equal(1360); | ||
@@ -640,3 +657,3 @@ m.jDayOfYear(1); | ||
it("should set Jalaali week year", function() { | ||
var m = moment("1981-08-17", "YYYY-MM-DD"); | ||
var m = jalaliMoment("1981-08-17", "YYYY-MM-DD"); | ||
m.jWeekYear(1361); | ||
@@ -657,9 +674,9 @@ m.format("jYY/jM/jD").should.be.equal("61/5/26"); | ||
it("should work as expected without jYear and jMonth", function() { | ||
var m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
var m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("year").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-01-01 00:00:00"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("month").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-01 00:00:00"); | ||
m = moment("1981-08-17 07:10:20"); | ||
m = jalaliMoment("1981-08-17 07:10:20"); | ||
m.startOf("day").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-17 00:00:00"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("week").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-15 00:00:00"); | ||
@@ -669,9 +686,9 @@ }); | ||
it("should return start of Jalaali year, month and date", function() { | ||
var m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
var m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("jYear").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-01-01 00:00:00"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("jMonth").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-01 00:00:00"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("day").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-26 00:00:00"); | ||
m = moment("2017-12-14 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("2017-12-14 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.startOf("jweek").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1396-09-18 00:00:00"); | ||
@@ -684,9 +701,9 @@ m.locale("fa").startOf("week").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1396-09-18 00:00:00"); | ||
it("should work as expected without jYear and jMonth", function() { | ||
var m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
var m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("year").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-12-31 23:59:59"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("month").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-31 23:59:59"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("day").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-17 23:59:59"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("week").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-21 23:59:59"); | ||
@@ -696,9 +713,9 @@ }); | ||
it("should return end of Jalaali year, month and date", function() { | ||
var m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
var m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("jYear").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-12-29 23:59:59"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("jMonth").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-31 23:59:59"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("day").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-26 23:59:59"); | ||
m = moment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m = jalaliMoment("1981-08-17 07:10:20", "YYYY-MM-DD HH:mm:ss"); | ||
m.endOf("week").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-30 23:59:59"); | ||
@@ -712,15 +729,15 @@ }); | ||
, gf = "YYYY-MM-DD"; | ||
moment("1981-08-17", gf).isValid().should.be.equal(true); | ||
moment("1981-08-31", gf).isValid().should.be.equal(true); | ||
moment("1981-09-31", gf).isValid().should.be.equal(false); | ||
moment("1360 Mordaad 26", "jYYYY jMMMM jD").isValid().should.be.equal(true); | ||
moment("1360/05/26", jf).isValid().should.be.equal(true); | ||
moment("1360/05/31", jf).isValid().should.be.equal(true); | ||
moment("1360/07/30", jf).isValid().should.be.equal(true); | ||
moment("1360/07/31", jf).isValid().should.be.equal(false); | ||
moment("1360/12/29", jf).isValid().should.be.equal(true); | ||
moment("1360/12/30", jf).isValid().should.be.equal(false); | ||
moment("1360/12/31", jf).isValid().should.be.equal(false); | ||
moment("1360/13/01", jf).isValid().should.be.equal(false); | ||
moment("1393/11/00", jf).isValid().should.be.equal(false); | ||
jalaliMoment("1981-08-17", gf).isValid().should.be.equal(true); | ||
jalaliMoment("1981-08-31", gf).isValid().should.be.equal(true); | ||
jalaliMoment("1981-09-31", gf).isValid().should.be.equal(false); | ||
jalaliMoment("1360 Mordaad 26", "jYYYY jMMMM jD").isValid().should.be.equal(true); | ||
jalaliMoment("1360/05/26", jf).isValid().should.be.equal(true); | ||
jalaliMoment("1360/05/31", jf).isValid().should.be.equal(true); | ||
jalaliMoment("1360/07/30", jf).isValid().should.be.equal(true); | ||
jalaliMoment("1360/07/31", jf).isValid().should.be.equal(false); | ||
jalaliMoment("1360/12/29", jf).isValid().should.be.equal(true); | ||
jalaliMoment("1360/12/30", jf).isValid().should.be.equal(false); | ||
jalaliMoment("1360/12/31", jf).isValid().should.be.equal(false); | ||
jalaliMoment("1360/13/01", jf).isValid().should.be.equal(false); | ||
jalaliMoment("1393/11/00", jf).isValid().should.be.equal(false); | ||
}); | ||
@@ -732,6 +749,6 @@ }); | ||
var gf = "YYYY-MM-DD"; | ||
moment("1981-08-17", gf).isValid().should.be.equal(true); | ||
moment("1981-08-31", gf).isValid().should.be.equal(true); | ||
moment("1981-08-311", gf).isValid().should.be.equal(true); | ||
moment("1981-08-311", gf, true).isValid().should.be.equal(false); | ||
jalaliMoment("1981-08-17", gf).isValid().should.be.equal(true); | ||
jalaliMoment("1981-08-31", gf).isValid().should.be.equal(true); | ||
jalaliMoment("1981-08-311", gf).isValid().should.be.equal(true); | ||
jalaliMoment("1981-08-311", gf, true).isValid().should.be.equal(false); | ||
}); | ||
@@ -741,5 +758,5 @@ | ||
var jf = "jYYYY/jMM/jDD"; | ||
moment("1360/05/26", jf).isValid().should.be.equal(true); | ||
moment("1360/05/31", jf).isValid().should.be.equal(true); | ||
moment("1360/05/311", jf, true).isValid().should.be.equal(false); | ||
jalaliMoment("1360/05/26", jf).isValid().should.be.equal(true); | ||
jalaliMoment("1360/05/31", jf).isValid().should.be.equal(true); | ||
jalaliMoment("1360/05/311", jf, true).isValid().should.be.equal(false); | ||
}); | ||
@@ -750,3 +767,3 @@ }); | ||
it("should return a cloned instance", function() { | ||
var m = moment("1360/5/26", "jYYYY/jM/jD") | ||
var m = jalaliMoment("1360/5/26", "jYYYY/jM/jD") | ||
, c = m.clone(); | ||
@@ -759,3 +776,3 @@ m.add(1, "jYear"); | ||
it("clone of an invalid date is invalid", function () { | ||
var m1 = moment("hello","jYYYY/jMM/jDD"); | ||
var m1 = jalaliMoment("hello","jYYYY/jMM/jDD"); | ||
m1.isValid().should.be.equal(false); | ||
@@ -769,17 +786,17 @@ m1.clone().isValid().should.be.equal(false); | ||
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"); | ||
, m = jalaliMoment("1981-8-17", "YYYY-M-D"); | ||
jalaliMoment(m).add(1, "day").format(gf).should.be.equal("1981-8-18"); | ||
jalaliMoment(m).add(10, "days").format(gf).should.be.equal("1981-8-27"); | ||
jalaliMoment(m).add(30, "days").format(gf).should.be.equal("1981-9-16"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).add(1, "month").format(gf).should.be.equal("1981-9-17"); | ||
jalaliMoment(m).add(2, "months").format(gf).should.be.equal("1981-10-17"); | ||
jalaliMoment(m).add(10, "months").format(gf).should.be.equal("1982-6-17"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).add(1, "year").format(gf).should.be.equal("1982-8-17"); | ||
jalaliMoment(m).add(2, "years").format(gf).should.be.equal("1983-8-17"); | ||
jalaliMoment(m).add(10, "years").format(gf).should.be.equal("1991-8-17"); | ||
jalaliMoment(m).add(20, "years").format(gf).should.be.equal("2001-8-17"); | ||
}); | ||
@@ -789,21 +806,21 @@ | ||
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"); | ||
, m = jalaliMoment("1360/5/26", "jYYYY/jM/jD"); | ||
jalaliMoment(m).add(1, "day").format(jf).should.be.equal("1360/5/27"); | ||
jalaliMoment(m).add(4, "days").format(jf).should.be.equal("1360/5/30"); | ||
jalaliMoment(m).add(10, "days").format(jf).should.be.equal("1360/6/5"); | ||
jalaliMoment(m).add(30, "days").format(jf).should.be.equal("1360/6/25"); | ||
jalaliMoment(m).add(60, "days").format(jf).should.be.equal("1360/7/24"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).add(1, "jmonth").format(jf).should.be.equal("1360/6/26"); | ||
jalaliMoment(m).add(2, "jmonths").format(jf).should.be.equal("1360/7/26"); | ||
jalaliMoment(m).add(10, "jmonths").format(jf).should.be.equal("1361/3/26"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).add(1, "jyear").format(jf).should.be.equal("1361/5/26"); | ||
jalaliMoment(m).add(2, "jyears").format(jf).should.be.equal("1362/5/26"); | ||
jalaliMoment(m).add(3, "jyears").format(jf).should.be.equal("1363/5/26"); | ||
jalaliMoment(m).add(4, "jyears").format(jf).should.be.equal("1364/5/26"); | ||
jalaliMoment(m).add(10, "jyears").format(jf).should.be.equal("1370/5/26"); | ||
jalaliMoment(m).add(20, "jyears").format(jf).should.be.equal("1380/5/26"); | ||
}); | ||
@@ -813,12 +830,12 @@ | ||
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 = jalaliMoment("1393/6/31", jf); | ||
jalaliMoment(m).add(1, "jmonth").format(jf).should.be.equal("1393/7/30"); | ||
jalaliMoment(m).add(5, "jmonth").format(jf).should.be.equal("1393/11/30"); | ||
jalaliMoment(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"); | ||
m = jalaliMoment("1391/12/30", jf); | ||
jalaliMoment(m).add(1, "jyear").format(jf).should.be.equal("1392/12/29"); | ||
jalaliMoment(m).add(2, "jyear").format(jf).should.be.equal("1393/12/29"); | ||
jalaliMoment(m).add(3, "jyear").format(jf).should.be.equal("1394/12/29"); | ||
jalaliMoment(m).add(4, "jyear").format(jf).should.be.equal("1395/12/30"); | ||
}); | ||
@@ -830,17 +847,17 @@ }); | ||
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"); | ||
, m = jalaliMoment("1981-8-17", "YYYY-M-D"); | ||
jalaliMoment(m).subtract(1, "day").format(gf).should.be.equal("1981-8-16"); | ||
jalaliMoment(m).subtract(10, "days").format(gf).should.be.equal("1981-8-7"); | ||
jalaliMoment(m).subtract(30, "days").format(gf).should.be.equal("1981-7-18"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).subtract(1, "month").format(gf).should.be.equal("1981-7-17"); | ||
jalaliMoment(m).subtract(2, "months").format(gf).should.be.equal("1981-6-17"); | ||
jalaliMoment(m).subtract(10, "months").format(gf).should.be.equal("1980-10-17"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).subtract(1, "year").format(gf).should.be.equal("1980-8-17"); | ||
jalaliMoment(m).subtract(2, "years").format(gf).should.be.equal("1979-8-17"); | ||
jalaliMoment(m).subtract(10, "years").format(gf).should.be.equal("1971-8-17"); | ||
jalaliMoment(m).subtract(20, "years").format(gf).should.be.equal("1961-8-17"); | ||
}); | ||
@@ -850,21 +867,21 @@ | ||
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"); | ||
, m = jalaliMoment("1360/5/26", "jYYYY/jM/jD"); | ||
jalaliMoment(m).subtract(1, "day").format(jf).should.be.equal("1360/5/25"); | ||
jalaliMoment(m).subtract(4, "days").format(jf).should.be.equal("1360/5/22"); | ||
jalaliMoment(m).subtract(10, "days").format(jf).should.be.equal("1360/5/16"); | ||
jalaliMoment(m).subtract(30, "days").format(jf).should.be.equal("1360/4/27"); | ||
jalaliMoment(m).subtract(60, "days").format(jf).should.be.equal("1360/3/28"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).subtract(1, "jmonth").format(jf).should.be.equal("1360/4/26"); | ||
jalaliMoment(m).subtract(2, "jmonths").format(jf).should.be.equal("1360/3/26"); | ||
jalaliMoment(m).subtract(10, "jmonths").format(jf).should.be.equal("1359/7/26"); | ||
jalaliMoment(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"); | ||
jalaliMoment(m).subtract(1, "jyear").format(jf).should.be.equal("1359/5/26"); | ||
jalaliMoment(m).subtract(2, "jyears").format(jf).should.be.equal("1358/5/26"); | ||
jalaliMoment(m).subtract(3, "jyears").format(jf).should.be.equal("1357/5/26"); | ||
jalaliMoment(m).subtract(4, "jyears").format(jf).should.be.equal("1356/5/26"); | ||
jalaliMoment(m).subtract(10, "jyears").format(jf).should.be.equal("1350/5/26"); | ||
jalaliMoment(m).subtract(20, "jyears").format(jf).should.be.equal("1340/5/26"); | ||
}); | ||
@@ -874,12 +891,12 @@ | ||
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 = jalaliMoment("1393/1/31", jf); | ||
jalaliMoment(m).subtract(1, "jmonth").format(jf).should.be.equal("1392/12/29"); | ||
jalaliMoment(m).subtract(6, "jmonth").format(jf).should.be.equal("1392/7/30"); | ||
jalaliMoment(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"); | ||
m = jalaliMoment("1391/12/30", jf); | ||
jalaliMoment(m).subtract(1, "jyear").format(jf).should.be.equal("1390/12/29"); | ||
jalaliMoment(m).subtract(2, "jyear").format(jf).should.be.equal("1389/12/29"); | ||
jalaliMoment(m).subtract(3, "jyear").format(jf).should.be.equal("1388/12/29"); | ||
jalaliMoment(m).subtract(4, "jyear").format(jf).should.be.equal("1387/12/30"); | ||
}); | ||
@@ -889,25 +906,25 @@ | ||
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(2, "jmonth").format(jf).should.be.equal("1392/11/30"); | ||
moment(m).subtract(7, "jmonth").format(jf).should.be.equal("1392/6/31"); | ||
moment(m).subtract(12, "jmonth").format(jf).should.be.equal("1392/1/31"); | ||
moment(m).subtract(13, "jmonth").format(jf).should.be.equal("1391/12/30"); | ||
moment(m).subtract(25, "jmonth").format(jf).should.be.equal("1390/12/29"); | ||
, m = jalaliMoment("1393/1/31", jf); | ||
jalaliMoment(m).subtract(1, "jmonth").format(jf).should.be.equal("1392/12/29"); | ||
jalaliMoment(m).subtract(2, "jmonth").format(jf).should.be.equal("1392/11/30"); | ||
jalaliMoment(m).subtract(7, "jmonth").format(jf).should.be.equal("1392/6/31"); | ||
jalaliMoment(m).subtract(12, "jmonth").format(jf).should.be.equal("1392/1/31"); | ||
jalaliMoment(m).subtract(13, "jmonth").format(jf).should.be.equal("1391/12/30"); | ||
jalaliMoment(m).subtract(25, "jmonth").format(jf).should.be.equal("1390/12/29"); | ||
m = moment("1393/1/1", jf); | ||
moment(m).subtract(1, "jmonth").format(jf).should.be.equal("1392/12/1"); | ||
moment(m).subtract(2, "jmonth").format(jf).should.be.equal("1392/11/1"); | ||
moment(m).subtract(7, "jmonth").format(jf).should.be.equal("1392/6/1"); | ||
moment(m).subtract(12, "jmonth").format(jf).should.be.equal("1392/1/1"); | ||
moment(m).subtract(13, "jmonth").format(jf).should.be.equal("1391/12/1"); | ||
moment(m).subtract(25, "jmonth").format(jf).should.be.equal("1390/12/1"); | ||
m = jalaliMoment("1393/1/1", jf); | ||
jalaliMoment(m).subtract(1, "jmonth").format(jf).should.be.equal("1392/12/1"); | ||
jalaliMoment(m).subtract(2, "jmonth").format(jf).should.be.equal("1392/11/1"); | ||
jalaliMoment(m).subtract(7, "jmonth").format(jf).should.be.equal("1392/6/1"); | ||
jalaliMoment(m).subtract(12, "jmonth").format(jf).should.be.equal("1392/1/1"); | ||
jalaliMoment(m).subtract(13, "jmonth").format(jf).should.be.equal("1391/12/1"); | ||
jalaliMoment(m).subtract(25, "jmonth").format(jf).should.be.equal("1390/12/1"); | ||
m = moment("1393/1/10", jf); | ||
moment(m).subtract(1, "jmonth").format(jf).should.be.equal("1392/12/10"); | ||
moment(m).subtract(2, "jmonth").format(jf).should.be.equal("1392/11/10"); | ||
moment(m).subtract(7, "jmonth").format(jf).should.be.equal("1392/6/10"); | ||
moment(m).subtract(12, "jmonth").format(jf).should.be.equal("1392/1/10"); | ||
moment(m).subtract(13, "jmonth").format(jf).should.be.equal("1391/12/10"); | ||
moment(m).subtract(25, "jmonth").format(jf).should.be.equal("1390/12/10"); | ||
m = jalaliMoment("1393/1/10", jf); | ||
jalaliMoment(m).subtract(1, "jmonth").format(jf).should.be.equal("1392/12/10"); | ||
jalaliMoment(m).subtract(2, "jmonth").format(jf).should.be.equal("1392/11/10"); | ||
jalaliMoment(m).subtract(7, "jmonth").format(jf).should.be.equal("1392/6/10"); | ||
jalaliMoment(m).subtract(12, "jmonth").format(jf).should.be.equal("1392/1/10"); | ||
jalaliMoment(m).subtract(13, "jmonth").format(jf).should.be.equal("1391/12/10"); | ||
jalaliMoment(m).subtract(25, "jmonth").format(jf).should.be.equal("1390/12/10"); | ||
}); | ||
@@ -918,16 +935,16 @@ }); | ||
it("should return true for Jalaali leap years and false otherwise", function() { | ||
moment.jIsLeapYear(1391).should.be.equal(true); | ||
moment.jIsLeapYear(1392).should.be.equal(false); | ||
moment.jIsLeapYear(1393).should.be.equal(false); | ||
moment.jIsLeapYear(1394).should.be.equal(false); | ||
moment.jIsLeapYear(1395).should.be.equal(true); | ||
moment.jIsLeapYear(1396).should.be.equal(false); | ||
moment.jIsLeapYear(1397).should.be.equal(false); | ||
moment.jIsLeapYear(1398).should.be.equal(false); | ||
moment.jIsLeapYear(1399).should.be.equal(true); | ||
moment.jIsLeapYear(1400).should.be.equal(false); | ||
moment.jIsLeapYear(1401).should.be.equal(false); | ||
moment.jIsLeapYear(1402).should.be.equal(false); | ||
moment.jIsLeapYear(1403).should.be.equal(true); | ||
moment.jIsLeapYear(1404).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1391).should.be.equal(true); | ||
jalaliMoment.jIsLeapYear(1392).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1393).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1394).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1395).should.be.equal(true); | ||
jalaliMoment.jIsLeapYear(1396).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1397).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1398).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1399).should.be.equal(true); | ||
jalaliMoment.jIsLeapYear(1400).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1401).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1402).should.be.equal(false); | ||
jalaliMoment.jIsLeapYear(1403).should.be.equal(true); | ||
jalaliMoment.jIsLeapYear(1404).should.be.equal(false); | ||
}); | ||
@@ -937,5 +954,5 @@ }); | ||
describe(".unix", function () { | ||
it("should create a moment with unix epoch", function () { | ||
var unix = moment("1360/5/26", "jYYYY/jM/jD").unix(); | ||
moment.unix(unix).format("jYYYY/jM/jD").should.be.equal("1360/5/26"); | ||
it("should create a jalaliMoment with unix epoch", function () { | ||
var unix = jalaliMoment("1360/5/26", "jYYYY/jM/jD").unix(); | ||
jalaliMoment.unix(unix).format("jYYYY/jM/jD").should.be.equal("1360/5/26"); | ||
}); | ||
@@ -945,6 +962,6 @@ }); | ||
it("should work correctly for same year", function () { | ||
var m1 = moment("2016-02-04", "YYYY-MM-DD"); | ||
var m2 = moment("2016-01-01", "YYYY-MM-DD"); | ||
var m3 = moment("2015-12-31", "YYYY-MM-DD"); | ||
var m4 = moment("2017-01-01", "YYYY-MM-DD"); | ||
var m1 = jalaliMoment("2016-02-04", "YYYY-MM-DD"); | ||
var m2 = jalaliMoment("2016-01-01", "YYYY-MM-DD"); | ||
var m3 = jalaliMoment("2015-12-31", "YYYY-MM-DD"); | ||
var m4 = jalaliMoment("2017-01-01", "YYYY-MM-DD"); | ||
m1.isSame(m2, "year").should.be.equal(true); | ||
@@ -956,10 +973,10 @@ m1.isSame(m3, "year").should.be.equal(false); | ||
m3.isSame(m4, "year").should.be.equal(false); | ||
m1.isSame(moment("2016-02-04", "YYYY-MM-DD"), "day").should.be.equal(true); | ||
m1.isSame(jalaliMoment("2016-02-04", "YYYY-MM-DD"), "day").should.be.equal(true); | ||
}); | ||
it("should work correctly for same month", function () { | ||
var m1 = moment("2016-02-04", "YYYY-MM-DD"); | ||
var m2 = moment("2016-02-01", "YYYY-MM-DD"); | ||
var m3 = moment("2016-01-01", "YYYY-MM-DD"); | ||
var m4 = moment("2016-03-01", "YYYY-MM-DD"); | ||
var m1 = jalaliMoment("2016-02-04", "YYYY-MM-DD"); | ||
var m2 = jalaliMoment("2016-02-01", "YYYY-MM-DD"); | ||
var m3 = jalaliMoment("2016-01-01", "YYYY-MM-DD"); | ||
var m4 = jalaliMoment("2016-03-01", "YYYY-MM-DD"); | ||
m1.isSame(m2, "month").should.be.equal(true); | ||
@@ -971,10 +988,10 @@ m1.isSame(m3, "month").should.be.equal(false); | ||
m3.isSame(m4, "month").should.be.equal(false); | ||
m1.isSame(moment("2016-02-04", "YYYY-MM-DD"), "day").should.be.equal(true); | ||
m1.isSame(jalaliMoment("2016-02-04", "YYYY-MM-DD"), "day").should.be.equal(true); | ||
}); | ||
it("should work correctly for same day", function () { | ||
var m1 = moment("2016-02-04 06:00", "YYYY-MM-DD HH:mm"); | ||
var m2 = moment("2016-02-04 07:00", "YYYY-MM-DD HH:mm"); | ||
var m3 = moment("2016-02-03 06:00", "YYYY-MM-DD HH:mm"); | ||
var m4 = moment("2016-02-05 06:00", "YYYY-MM-DD HH:mm"); | ||
var m1 = jalaliMoment("2016-02-04 06:00", "YYYY-MM-DD HH:mm"); | ||
var m2 = jalaliMoment("2016-02-04 07:00", "YYYY-MM-DD HH:mm"); | ||
var m3 = jalaliMoment("2016-02-03 06:00", "YYYY-MM-DD HH:mm"); | ||
var m4 = jalaliMoment("2016-02-05 06:00", "YYYY-MM-DD HH:mm"); | ||
m1.isSame(m2, "day").should.be.equal(true); | ||
@@ -989,6 +1006,6 @@ m1.isSame(m3, "day").should.be.equal(false); | ||
it("should work correctly for same jyear", function () { | ||
var m1 = moment("1394/11/15", "jYYYY/jMM/jDD"); | ||
var m2 = moment("1394/01/01", "jYYYY/jMM/jDD"); | ||
var m3 = moment("1393/11/15", "jYYYY/jMM/jDD"); | ||
var m4 = moment("1395/11/15", "jYYYY/jMM/jDD"); | ||
var m1 = jalaliMoment("1394/11/15", "jYYYY/jMM/jDD"); | ||
var m2 = jalaliMoment("1394/01/01", "jYYYY/jMM/jDD"); | ||
var m3 = jalaliMoment("1393/11/15", "jYYYY/jMM/jDD"); | ||
var m4 = jalaliMoment("1395/11/15", "jYYYY/jMM/jDD"); | ||
m1.isSame(m2, "jyear").should.be.equal(true); | ||
@@ -1003,6 +1020,6 @@ m1.isSame(m3, "jyear").should.be.equal(false); | ||
it("should work correctly for same jmonth", function () { | ||
var m1 = moment("1394/11/15", "jYYYY/jMM/jDD"); | ||
var m2 = moment("1394/11/01", "jYYYY/jMM/jDD"); | ||
var m3 = moment("1394/10/15", "jYYYY/jMM/jDD"); | ||
var m4 = moment("1394/12/15", "jYYYY/jMM/jDD"); | ||
var m1 = jalaliMoment("1394/11/15", "jYYYY/jMM/jDD"); | ||
var m2 = jalaliMoment("1394/11/01", "jYYYY/jMM/jDD"); | ||
var m3 = jalaliMoment("1394/10/15", "jYYYY/jMM/jDD"); | ||
var m4 = jalaliMoment("1394/12/15", "jYYYY/jMM/jDD"); | ||
m1.isSame(m2, "jmonth").should.be.equal(true); | ||
@@ -1016,6 +1033,6 @@ m1.isSame(m3, "jmonth").should.be.equal(false); | ||
it("it absolutely should work correctly for same jday", function () { | ||
var m1 = moment("2016-02-04 06:00", "YYYY-MM-DD HH:mm"); | ||
var m2 = moment("2016-02-04 07:00", "YYYY-MM-DD HH:mm"); | ||
var m3 = moment("2016-02-03 06:00", "YYYY-MM-DD HH:mm"); | ||
var m4 = moment("2016-02-05 06:00", "YYYY-MM-DD HH:mm"); | ||
var m1 = jalaliMoment("2016-02-04 06:00", "YYYY-MM-DD HH:mm"); | ||
var m2 = jalaliMoment("2016-02-04 07:00", "YYYY-MM-DD HH:mm"); | ||
var m3 = jalaliMoment("2016-02-03 06:00", "YYYY-MM-DD HH:mm"); | ||
var m4 = jalaliMoment("2016-02-05 06:00", "YYYY-MM-DD HH:mm"); | ||
m1.isSame(m2, "jday").should.be.equal(true); | ||
@@ -1031,7 +1048,7 @@ m1.isSame(m3, "jday").should.be.equal(false); | ||
it("fill date with another locale", function () { | ||
moment.locale("en"); | ||
var m1 = moment.from("1367/11/04", "fa", "YYYY/MM/DD"); | ||
jalaliMoment.locale("en"); | ||
var m1 = jalaliMoment.from("1367/11/04", "fa", "YYYY/MM/DD"); | ||
m1.format("jYYYY/jMM/jDD").should.be.equal("1367/11/04"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1989/01/24"); | ||
var m2 = moment.from("11/1367/04", "fa", "MM/YYYY/DD"); | ||
var m2 = jalaliMoment.from("11/1367/04", "fa", "MM/YYYY/DD"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1989/01/24"); | ||
@@ -1042,11 +1059,11 @@ }); | ||
it("gregorian is default system", function () { | ||
var m1 = moment("1989/01/24","YYYY/MM/DD"); | ||
var m1 = jalaliMoment("1989/01/24","YYYY/MM/DD"); | ||
m1.format("jYYYY/jMM/jDD").should.be.equal("1367/11/04"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1989/01/24"); | ||
// moment().isBetween(moment().subtract(1, "day"), moment().add(1, "day"), "day", "[]").should.be.equal(true); | ||
// moment().subtract(2, "d").isBetween(moment().subtract(1, "day"), moment().add(1, "day"), "day", "[]").should.be.equal(false); | ||
// jalaliMoment().isBetween(jalaliMoment().subtract(1, "day"), jalaliMoment().add(1, "day"), "day", "[]").should.be.equal(true); | ||
// jalaliMoment().subtract(2, "d").isBetween(jalaliMoment().subtract(1, "day"), jalaliMoment().add(1, "day"), "day", "[]").should.be.equal(false); | ||
}); | ||
it("change locale globally should change the whole instances system", function () { | ||
moment.locale("fa"); | ||
var m1 = moment("1367/11/04","YYYY/MM/DD"); | ||
jalaliMoment.locale("fa"); | ||
var m1 = jalaliMoment("1367/11/04","YYYY/MM/DD"); | ||
@@ -1058,3 +1075,3 @@ m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
it("test changeSystemByItsLocale ", function () { | ||
var m1 = moment("1367/11/04","jYYYY/jMM/jDD"); | ||
var m1 = jalaliMoment("1367/11/04","jYYYY/jMM/jDD"); | ||
m1.locale("fa"); | ||
@@ -1068,4 +1085,4 @@ m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
it("instance locale and clone", function () { | ||
moment.locale("en"); | ||
var m1 = moment("1367/11/04","jYYYY/jMM/jDD"); | ||
jalaliMoment.locale("en"); | ||
var m1 = jalaliMoment("1367/11/04","jYYYY/jMM/jDD"); | ||
m1.locale("fa"); | ||
@@ -1080,4 +1097,4 @@ m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
it("global locale and clone", function () { | ||
moment.locale("fa"); | ||
var m1 = moment("1367/11/04","YYYY/MM/DD"); | ||
jalaliMoment.locale("fa"); | ||
var m1 = jalaliMoment("1367/11/04","YYYY/MM/DD"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1367/11/04"); | ||
@@ -1092,5 +1109,5 @@ var m2 = m1.clone(); | ||
it("instance locale and clone", function () { | ||
moment.locale("en"); | ||
jalaliMoment.locale("en"); | ||
var m1 = moment("1395/12/30","jYYYY/jMM/jDD").locale("fa"); | ||
var m1 = jalaliMoment("1395/12/30","jYYYY/jMM/jDD").locale("fa"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1395/12/30"); | ||
@@ -1106,5 +1123,5 @@ | ||
describe("test utc time", function () { | ||
it("utc moment", function () { | ||
moment.locale("en"); | ||
var m1 = moment("1395/12/30", "jYYYY/jMM/jDD", "fa", true).locale("fa"); | ||
it("utc jalaliMoment", function () { | ||
jalaliMoment.locale("en"); | ||
var m1 = jalaliMoment("1395/12/30", "jYYYY/jMM/jDD", "fa", true).locale("fa"); | ||
m1.format("YYYY/MM/DD").should.be.equal("1395/12/30"); | ||
@@ -1115,14 +1132,14 @@ }); | ||
it("en locale", function () { | ||
moment().localeData().jMonths().should.have.lengthOf(12); | ||
moment().localeData().jMonthsShort().should.have.lengthOf(12); | ||
jalaliMoment().localeData().jMonths().should.have.lengthOf(12); | ||
jalaliMoment().localeData().jMonthsShort().should.have.lengthOf(12); | ||
}); | ||
it("fa locale", function () { | ||
moment().locale("fa").localeData().jMonths().should.have.lengthOf(12); | ||
moment().locale("fa").localeData().jMonthsShort().should.have.lengthOf(12); | ||
jalaliMoment().locale("fa").localeData().jMonths().should.have.lengthOf(12); | ||
jalaliMoment().locale("fa").localeData().jMonthsShort().should.have.lengthOf(12); | ||
}); | ||
}); | ||
describe("getting year and month in both locale", function () { | ||
moment.locale("en"); | ||
it("en locale", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("en"); | ||
var now = jalaliMoment(); | ||
now.locale("en"); | ||
@@ -1135,3 +1152,4 @@ var month = +now.format("M"); | ||
it("fa locale", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("en"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1145,4 +1163,4 @@ var month = +now.format("M"); | ||
describe("getting day of year in both locale", function () { | ||
moment.locale("en"); | ||
var now = moment(); | ||
jalaliMoment.locale("en"); | ||
var now = jalaliMoment(); | ||
it("day of year with en locale", function () { | ||
@@ -1160,4 +1178,4 @@ now.locale("en"); | ||
describe("getting week fa locale", function () { | ||
moment.locale("en"); | ||
var now = moment(); | ||
jalaliMoment.locale("en"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1172,4 +1190,4 @@ it("week with fa locale", function () { | ||
describe("getting week fa locale", function () { | ||
moment.locale("en"); | ||
var now = moment(); | ||
jalaliMoment.locale("en"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1184,5 +1202,5 @@ it("week with fa locale", function () { | ||
describe("getting from now with fa locale", function () { | ||
moment.locale("fa"); | ||
it("just now", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("fa"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1192,3 +1210,4 @@ now.fromNow().should.be.equal("چند ثانیه پیش"); | ||
it("10 seconds ago", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("fa"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1199,3 +1218,4 @@ now.subtract(10, "s"); | ||
it("100 seconds ago", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("fa"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1206,3 +1226,4 @@ now.subtract(100, "s"); | ||
it("5 days ago", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("fa"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1213,3 +1234,4 @@ now.subtract(5, "d"); | ||
it("1 month ago", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("fa"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1220,3 +1242,4 @@ now.subtract(1, "months"); | ||
it("3 years ago", function () { | ||
var now = moment(); | ||
jalaliMoment.locale("fa"); | ||
var now = jalaliMoment(); | ||
now.locale("fa"); | ||
@@ -1229,11 +1252,26 @@ now.subtract(3, "year"); | ||
it("use jalali calendar when useGregorianParser is false in fa locale", function () { | ||
moment.locale("fa", { useGregorianParser: false }); | ||
moment("1370-10-17").format("YYYY-MM-DD").should.be.equal("1370-10-17"); | ||
jalaliMoment.locale("fa", { useGregorianParser: false }); | ||
jalaliMoment("1370-10-17").format("YYYY-MM-DD").should.be.equal("1370-10-17"); | ||
}); | ||
it("parse using gregorian calendar in fa locale", function () { | ||
moment.locale("fa", { useGregorianParser: true }); | ||
moment("2019-01-17T08:19:19.975Z").format("YYYY-MM-DD").should.be.equal("1397-10-27"); | ||
moment("2019-02-23").format("YYYY-MM-DD").should.be.equal("1397-12-04"); | ||
jalaliMoment.locale("fa", { useGregorianParser: true }); | ||
jalaliMoment("2019-01-17T08:19:19.975Z").format("YYYY-MM-DD").should.be.equal("1397-10-27"); | ||
jalaliMoment("2019-02-23").format("YYYY-MM-DD").should.be.equal("1397-12-04"); | ||
}); | ||
}); | ||
describe("compare jalaliMoment and moment", function () { | ||
it("utc should be the same", function () { | ||
const a = jalaliMoment.utc("09:30", "HH:mm"); | ||
const b = moment.utc("09:30", "HH:mm"); | ||
a.locale('en').format('YYMMDD-HH:mm').should.be.equal(b.format('YYMMDD-HH:mm')); | ||
}); | ||
}); | ||
describe("test diff", function () { | ||
it("diff locale fa", function () { | ||
//https://github.com/fingerpich/jalali-moment/issues/78 | ||
const d1 = moment('2019-10-26').locale('fa').diff(moment('2019-10-28').locale('fa'), 'month') | ||
const d2 = moment('2019-10-26').locale('en').diff(moment('2019-10-28').locale('en'), 'month') | ||
d1.should.be.equal(d2); | ||
}); | ||
}); | ||
}); |
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 not supported yet
1304180
4106