jalali-moment
Advanced tools
Comparing version 1.0.8 to 1.0.9
module.exports = jMoment; | ||
var moment = require('moment') | ||
, jalaali = require('jalaali-js'); | ||
var moment = require("moment") | ||
, jalaali = require("jalaali-js"); | ||
@@ -19,3 +19,3 @@ /************************************ | ||
, parseTokenSixDigits = /[+\-]?\d{1,6}/ | ||
, parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i | ||
, parseTokenWord = /[0-9]*["a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i | ||
, parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i | ||
@@ -26,6 +26,6 @@ , parseTokenT = /T/i | ||
, unitAliases = | ||
{ jm: 'jmonth' | ||
, jmonths: 'jmonth' | ||
, jy: 'jyear' | ||
, jyears: 'jyear' | ||
{ jm: "jmonth" | ||
, jmonths: "jmonth" | ||
, jy: "jyear" | ||
, jyears: "jyear" | ||
} | ||
@@ -35,41 +35,41 @@ | ||
, ordinalizeTokens = 'DDD w M D'.split(' ') | ||
, paddedTokens = 'M D w'.split(' ') | ||
, ordinalizeTokens = "DDD w M D".split(" ") | ||
, paddedTokens = "M D w".split(" ") | ||
, formatTokenFunctions = | ||
{ jM: function () { | ||
return this.jMonth() + 1 | ||
return this.jMonth() + 1; | ||
} | ||
, jMMM: function (format) { | ||
return this.localeData().jMonthsShort(this, format) | ||
return this.localeData().jMonthsShort(this, format); | ||
} | ||
, jMMMM: function (format) { | ||
return this.localeData().jMonths(this, format) | ||
return this.localeData().jMonths(this, format); | ||
} | ||
, jD: function () { | ||
return this.jDate() | ||
return this.jDate(); | ||
} | ||
, jDDD: function () { | ||
return this.jDayOfYear() | ||
return this.jDayOfYear(); | ||
} | ||
, jw: function () { | ||
return this.jWeek() | ||
return this.jWeek(); | ||
} | ||
, jYY: function () { | ||
return leftZeroFill(this.jYear() % 100, 2) | ||
return leftZeroFill(this.jYear() % 100, 2); | ||
} | ||
, jYYYY: function () { | ||
return leftZeroFill(this.jYear(), 4) | ||
return leftZeroFill(this.jYear(), 4); | ||
} | ||
, jYYYYY: function () { | ||
return leftZeroFill(this.jYear(), 5) | ||
return leftZeroFill(this.jYear(), 5); | ||
} | ||
, jgg: function () { | ||
return leftZeroFill(this.jWeekYear() % 100, 2) | ||
return leftZeroFill(this.jWeekYear() % 100, 2); | ||
} | ||
, jgggg: function () { | ||
return this.jWeekYear() | ||
return this.jWeekYear(); | ||
} | ||
, jggggg: function () { | ||
return leftZeroFill(this.jWeekYear(), 5) | ||
return leftZeroFill(this.jWeekYear(), 5); | ||
} | ||
@@ -80,9 +80,9 @@ }; | ||
return function (a) { | ||
return leftZeroFill(func.call(this, a), count) | ||
} | ||
return leftZeroFill(func.call(this, a), count); | ||
}; | ||
} | ||
function ordinalizeToken(func, period) { | ||
return function (a) { | ||
return this.localeData().ordinal(func.call(this, a), period) | ||
} | ||
return this.localeData().ordinal(func.call(this, a), period); | ||
}; | ||
} | ||
@@ -94,9 +94,9 @@ | ||
i = ordinalizeTokens.pop(); | ||
formatTokenFunctions['j' + i + 'o'] = ordinalizeToken(formatTokenFunctions['j' + i], i) | ||
formatTokenFunctions["j" + i + "o"] = ordinalizeToken(formatTokenFunctions["j" + i], i); | ||
} | ||
while (paddedTokens.length) { | ||
i = paddedTokens.pop(); | ||
formatTokenFunctions['j' + i + i] = padToken(formatTokenFunctions['j' + i], 2) | ||
formatTokenFunctions["j" + i + i] = padToken(formatTokenFunctions["j" + i], 2); | ||
} | ||
formatTokenFunctions.jDDDD = padToken(formatTokenFunctions.jDDD, 3) | ||
formatTokenFunctions.jDDDD = padToken(formatTokenFunctions.jDDD, 3); | ||
}()); | ||
@@ -111,16 +111,18 @@ | ||
for (key in b) | ||
if (b.hasOwnProperty(key)) | ||
if (b.hasOwnProperty(key)){ | ||
a[key] = b[key]; | ||
return a | ||
} | ||
return a; | ||
} | ||
function leftZeroFill(number, targetLength) { | ||
var output = number + ''; | ||
while (output.length < targetLength) | ||
output = '0' + output; | ||
return output | ||
var output = number + ""; | ||
while (output.length < targetLength){ | ||
output = "0" + output; | ||
} | ||
return output; | ||
} | ||
function isArray(input) { | ||
return Object.prototype.toString.call(input) === '[object Array]' | ||
return Object.prototype.toString.call(input) === "[object Array]"; | ||
} | ||
@@ -142,5 +144,5 @@ | ||
var lowered = units.toLowerCase(); | ||
units = unitAliases[lowered] || lowered | ||
units = unitAliases[lowered] || lowered; | ||
} | ||
return units | ||
return units; | ||
} | ||
@@ -157,3 +159,3 @@ | ||
m._d = new Date(year, month, date, | ||
d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()) | ||
d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()); | ||
} | ||
@@ -165,12 +167,15 @@ } | ||
F.prototype = parent; | ||
return new F() | ||
return new F(); | ||
} | ||
function getPrototypeOf(object) { | ||
if (Object.getPrototypeOf) | ||
if (Object.getPrototypeOf){ | ||
return Object.getPrototypeOf(object); | ||
else if (''.__proto__) | ||
} | ||
else if ("".__proto__){ | ||
return object.__proto__; | ||
else | ||
return object.constructor.prototype | ||
} | ||
else{ | ||
return object.constructor.prototype; | ||
} | ||
} | ||
@@ -182,34 +187,34 @@ | ||
extend(getPrototypeOf(moment.localeData()), | ||
{ _jMonths: [ 'Farvardin' | ||
, 'Ordibehesht' | ||
, 'Khordaad' | ||
, 'Tir' | ||
, 'Amordaad' | ||
, 'Shahrivar' | ||
, 'Mehr' | ||
, 'Aabaan' | ||
, 'Aazar' | ||
, 'Dey' | ||
, 'Bahman' | ||
, 'Esfand' | ||
{ _jMonths: [ "Farvardin" | ||
, "Ordibehesht" | ||
, "Khordaad" | ||
, "Tir" | ||
, "Amordaad" | ||
, "Shahrivar" | ||
, "Mehr" | ||
, "Aabaan" | ||
, "Aazar" | ||
, "Dey" | ||
, "Bahman" | ||
, "Esfand" | ||
] | ||
, jMonths: function (m) { | ||
return this._jMonths[m.jMonth()] | ||
return this._jMonths[m.jMonth()]; | ||
} | ||
, _jMonthsShort: [ 'Far' | ||
, 'Ord' | ||
, 'Kho' | ||
, 'Tir' | ||
, 'Amo' | ||
, 'Sha' | ||
, 'Meh' | ||
, 'Aab' | ||
, 'Aaz' | ||
, 'Dey' | ||
, 'Bah' | ||
, 'Esf' | ||
, _jMonthsShort: [ "Far" | ||
, "Ord" | ||
, "Kho" | ||
, "Tir" | ||
, "Amo" | ||
, "Sha" | ||
, "Meh" | ||
, "Aab" | ||
, "Aaz" | ||
, "Dey" | ||
, "Bah" | ||
, "Esf" | ||
] | ||
, jMonthsShort: function (m) { | ||
return this._jMonthsShort[m.jMonth()] | ||
return this._jMonthsShort[m.jMonth()]; | ||
} | ||
@@ -221,14 +226,16 @@ | ||
, regex; | ||
if (!this._jMonthsParse) | ||
if (!this._jMonthsParse){ | ||
this._jMonthsParse = []; | ||
} | ||
for (i = 0; i < 12; i += 1) { | ||
// Make the regex if we don't have it already. | ||
// Make the regex if we don"t have it already. | ||
if (!this._jMonthsParse[i]) { | ||
mom = jMoment([2000, (2 + i) % 12, 25]); | ||
regex = '^' + this.jMonths(mom, '') + '|^' + this.jMonthsShort(mom, ''); | ||
this._jMonthsParse[i] = new RegExp(regex.replace('.', ''), 'i') | ||
regex = "^" + this.jMonths(mom, "") + "|^" + this.jMonthsShort(mom, ""); | ||
this._jMonthsParse[i] = new RegExp(regex.replace(".", ""), "i"); | ||
} | ||
// Test the regex. | ||
if (this._jMonthsParse[i].test(monthName)) | ||
return i | ||
if (this._jMonthsParse[i].test(monthName)){ | ||
return i; | ||
} | ||
} | ||
@@ -248,12 +255,14 @@ } | ||
for (i = 0; i < length; i += 1) | ||
if (formatTokenFunctions[array[i]]) | ||
for (i = 0; i < length; i += 1){ | ||
if (formatTokenFunctions[array[i]]){ | ||
array[i] = formatTokenFunctions[array[i]]; | ||
} | ||
} | ||
return function (mom) { | ||
var output = ''; | ||
for (i = 0; i < length; i += 1) | ||
output += array[i] instanceof Function ? '[' + array[i].call(mom, format) + ']' : array[i] | ||
return output | ||
} | ||
var output = ""; | ||
for (i = 0; i < length; i += 1){ | ||
output += array[i] instanceof Function ? "[" + array[i].call(mom, format) + "]" : array[i]; | ||
} | ||
return output; | ||
}; | ||
} | ||
@@ -267,63 +276,63 @@ | ||
switch (token) { | ||
case 'jDDDD': | ||
case "jDDDD": | ||
return parseTokenThreeDigits; | ||
case 'jYYYY': | ||
case "jYYYY": | ||
return parseTokenFourDigits; | ||
case 'jYYYYY': | ||
case "jYYYYY": | ||
return parseTokenSixDigits; | ||
case 'jDDD': | ||
case "jDDD": | ||
return parseTokenOneToThreeDigits; | ||
case 'jMMM': | ||
case 'jMMMM': | ||
case "jMMM": | ||
case "jMMMM": | ||
return parseTokenWord; | ||
case 'jMM': | ||
case 'jDD': | ||
case 'jYY': | ||
case 'jM': | ||
case 'jD': | ||
case "jMM": | ||
case "jDD": | ||
case "jYY": | ||
case "jM": | ||
case "jD": | ||
return parseTokenOneOrTwoDigits; | ||
case 'DDDD': | ||
case "DDDD": | ||
return parseTokenThreeDigits; | ||
case 'YYYY': | ||
case "YYYY": | ||
return parseTokenFourDigits; | ||
case 'YYYYY': | ||
case "YYYYY": | ||
return parseTokenSixDigits; | ||
case 'S': | ||
case 'SS': | ||
case 'SSS': | ||
case 'DDD': | ||
case "S": | ||
case "SS": | ||
case "SSS": | ||
case "DDD": | ||
return parseTokenOneToThreeDigits; | ||
case 'MMM': | ||
case 'MMMM': | ||
case 'dd': | ||
case 'ddd': | ||
case 'dddd': | ||
case "MMM": | ||
case "MMMM": | ||
case "dd": | ||
case "ddd": | ||
case "dddd": | ||
return parseTokenWord; | ||
case 'a': | ||
case 'A': | ||
case "a": | ||
case "A": | ||
return moment.localeData(config._l)._meridiemParse; | ||
case 'X': | ||
case "X": | ||
return parseTokenTimestampMs; | ||
case 'Z': | ||
case 'ZZ': | ||
case "Z": | ||
case "ZZ": | ||
return parseTokenTimezone; | ||
case 'T': | ||
case "T": | ||
return parseTokenT; | ||
case 'MM': | ||
case 'DD': | ||
case 'YY': | ||
case 'HH': | ||
case 'hh': | ||
case 'mm': | ||
case 'ss': | ||
case 'M': | ||
case 'D': | ||
case 'd': | ||
case 'H': | ||
case 'h': | ||
case 'm': | ||
case 's': | ||
case "MM": | ||
case "DD": | ||
case "YY": | ||
case "HH": | ||
case "hh": | ||
case "mm": | ||
case "ss": | ||
case "M": | ||
case "D": | ||
case "d": | ||
case "H": | ||
case "h": | ||
case "m": | ||
case "s": | ||
return parseTokenOneOrTwoDigits; | ||
default: | ||
return new RegExp(token.replace('\\', '')) | ||
return new RegExp(token.replace("\\", "")); | ||
} | ||
@@ -339,30 +348,34 @@ } | ||
switch (token) { | ||
case 'jM': | ||
case 'jMM': | ||
case "jM": | ||
case "jMM": | ||
datePartArray[1] = isNull(input)? 0 : ~~input - 1; | ||
break; | ||
case 'jMMM': | ||
case 'jMMMM': | ||
case "jMMM": | ||
case "jMMMM": | ||
a = moment.localeData(config._l).jMonthsParse(input); | ||
if (!isNull(a)) | ||
if (!isNull(a)){ | ||
datePartArray[1] = a; | ||
else | ||
} | ||
else{ | ||
config._isValid = false; | ||
} | ||
break; | ||
case 'jD': | ||
case 'jDD': | ||
case 'jDDD': | ||
case 'jDDDD': | ||
if (!isNull(input)) | ||
case "jD": | ||
case "jDD": | ||
case "jDDD": | ||
case "jDDDD": | ||
if (!isNull(input)){ | ||
datePartArray[2] = ~~input; | ||
} | ||
break; | ||
case 'jYY': | ||
case "jYY": | ||
datePartArray[0] = ~~input + (~~input > 47 ? 1300 : 1400); | ||
break; | ||
case 'jYYYY': | ||
case 'jYYYYY': | ||
datePartArray[0] = ~~input | ||
case "jYYYY": | ||
case "jYYYYY": | ||
datePartArray[0] = ~~input; | ||
} | ||
if (isNull(input)) | ||
config._isValid = false | ||
if (isNull(input)){ | ||
config._isValid = false; | ||
} | ||
} | ||
@@ -377,19 +390,24 @@ | ||
if (isNull(jy) && isNull(jm) && isNull(jd)) | ||
if (isNull(jy) && isNull(jm) && isNull(jd)){ | ||
return [0, 0, 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) | ||
if (jd < 1 || jd > jMoment.jDaysInMonth(jy, jm) || jm < 0 || jm > 11){ | ||
config._isValid = false; | ||
} | ||
g = toGregorian(jy, jm, jd); | ||
j = toJalaali(g.gy, g.gm, g.gd); | ||
config._jDiff = 0; | ||
if (~~j.jy !== jy) | ||
if (~~j.jy !== jy){ | ||
config._jDiff += 1; | ||
if (~~j.jm !== jm) | ||
} | ||
if (~~j.jm !== jm){ | ||
config._jDiff += 1; | ||
if (~~j.jd !== jd) | ||
} | ||
if (~~j.jd !== jd){ | ||
config._jDiff += 1; | ||
return [g.gy, g.gm, g.gd] | ||
} | ||
return [g.gy, g.gm, g.gd]; | ||
} | ||
@@ -399,3 +417,3 @@ | ||
var tokens = config._f.match(formattingTokens) | ||
, string = config._i + '' | ||
, string = config._i + "" | ||
, len = tokens.length | ||
@@ -411,10 +429,13 @@ , i | ||
parsedInput = (getParseRegexForToken(token, config).exec(string) || [])[0]; | ||
if (parsedInput) | ||
if (parsedInput){ | ||
string = string.slice(string.indexOf(parsedInput) + parsedInput.length); | ||
if (formatTokenFunctions[token]) | ||
addTimeToArrayFromToken(token, parsedInput, config) | ||
} | ||
if (formatTokenFunctions[token]){ | ||
addTimeToArrayFromToken(token, parsedInput, config); | ||
} | ||
} | ||
if (string) | ||
if (string){ | ||
config._il = string; | ||
return dateFromArray(config) | ||
} | ||
return dateFromArray(config); | ||
} | ||
@@ -432,3 +453,3 @@ | ||
if (len === 0) { | ||
return makeMoment(new Date(NaN)) | ||
return makeMoment(new Date(NaN)); | ||
} | ||
@@ -441,21 +462,24 @@ | ||
if (!tempMoment.isValid()) continue; | ||
if (!tempMoment.isValid()){ | ||
continue; | ||
} | ||
// currentScore = compareArrays(tempMoment._a, tempMoment.toArray()) | ||
currentScore += tempMoment._jDiff; | ||
if (tempMoment._il) | ||
if (tempMoment._il){ | ||
currentScore += tempMoment._il.length; | ||
} | ||
if (isNull(scoreToBeat) || currentScore < scoreToBeat) { | ||
scoreToBeat = currentScore; | ||
bestMoment = tempMoment | ||
bestMoment = tempMoment; | ||
} | ||
} | ||
return bestMoment | ||
return bestMoment; | ||
} | ||
function removeParsedTokens(config) { | ||
var string = config._i + '' | ||
, input = '' | ||
, format = '' | ||
var string = config._i + "" | ||
, input = "" | ||
, format = "" | ||
, array = config._f.match(formattingTokens) | ||
@@ -470,12 +494,14 @@ , len = array.length | ||
parsed = (getParseRegexForToken(match, config).exec(string) || [])[0]; | ||
if (parsed) | ||
if (parsed){ | ||
string = string.slice(string.indexOf(parsed) + parsed.length); | ||
} | ||
if (!(formatTokenFunctions[match] instanceof Function)) { | ||
format += match; | ||
if (parsed) | ||
input += parsed | ||
if (parsed){ | ||
input += parsed; | ||
} | ||
} | ||
} | ||
config._i = input; | ||
config._f = format | ||
config._f = format; | ||
} | ||
@@ -493,11 +519,11 @@ | ||
if (daysToDayOfWeek > end) { | ||
daysToDayOfWeek -= 7 | ||
daysToDayOfWeek -= 7; | ||
} | ||
if (daysToDayOfWeek < end - 7) { | ||
daysToDayOfWeek += 7 | ||
daysToDayOfWeek += 7; | ||
} | ||
adjustedMoment = jMoment(mom).add(daysToDayOfWeek, 'd'); | ||
adjustedMoment = jMoment(mom).add(daysToDayOfWeek, "d"); | ||
return { week: Math.ceil(adjustedMoment.jDayOfYear() / 7) | ||
, year: adjustedMoment.jYear() | ||
} | ||
}; | ||
} | ||
@@ -510,10 +536,11 @@ | ||
function makeMoment(input, format, lang, strict, utc) { | ||
if (typeof lang === 'boolean') { | ||
if (typeof lang === "boolean") { | ||
utc = strict; | ||
strict = lang; | ||
lang = undefined | ||
lang = undefined; | ||
} | ||
if (format && typeof format === 'string') | ||
if (format && typeof format === "string"){ | ||
format = fixFormat(format, moment); | ||
} | ||
@@ -534,19 +561,22 @@ var config = | ||
if (isArray(format)) { | ||
return makeDateFromStringAndArray(config, utc) | ||
return makeDateFromStringAndArray(config, utc); | ||
} else { | ||
date = makeDateFromStringAndFormat(config); | ||
removeParsedTokens(config); | ||
format = 'YYYY-MM-DD-' + config._f; | ||
input = leftZeroFill(date[0], 4) + '-' | ||
+ leftZeroFill(date[1] + 1, 2) + '-' | ||
+ leftZeroFill(date[2], 2) + '-' | ||
+ config._i | ||
format = "YYYY-MM-DD-" + config._f; | ||
input = leftZeroFill(date[0], 4) + "-" | ||
+ leftZeroFill(date[1] + 1, 2) + "-" | ||
+ leftZeroFill(date[2], 2) + "-" | ||
+ config._i; | ||
} | ||
} | ||
if (utc) | ||
if (utc){ | ||
m = moment.utc(input, format, lang, strict); | ||
else | ||
} | ||
else{ | ||
m = moment(input, format, lang, strict); | ||
if (config._isValid === false) | ||
} | ||
if (config._isValid === false){ | ||
m._isValid = false; | ||
} | ||
m._jDiff = config._jDiff || 0; | ||
@@ -556,9 +586,9 @@ jm = objectCreate(jMoment.fn); | ||
if (strict && jm.isValid()) { | ||
jm._isValid = jm.format(origFormat) === origInput | ||
jm._isValid = jm.format(origFormat) === origInput; | ||
} | ||
return jm | ||
return jm; | ||
} | ||
function jMoment(input, format, lang, strict) { | ||
return makeMoment(input, format, lang, strict, false) | ||
return makeMoment(input, format, lang, strict, false); | ||
} | ||
@@ -570,7 +600,7 @@ | ||
jMoment.utc = function (input, format, lang, strict) { | ||
return makeMoment(input, format, lang, strict, true) | ||
return makeMoment(input, format, lang, strict, true); | ||
}; | ||
jMoment.unix = function (input) { | ||
return makeMoment(input * 1000) | ||
return makeMoment(input * 1000); | ||
}; | ||
@@ -585,9 +615,9 @@ | ||
var replace = function (input) { | ||
return _moment.localeData().longDateFormat(input) || input | ||
return _moment.localeData().longDateFormat(input) || input; | ||
}; | ||
while (i > 0 && localFormattingTokens.test(format)) { | ||
i -= 1; | ||
format = format.replace(localFormattingTokens, replace) | ||
format = format.replace(localFormattingTokens, replace); | ||
} | ||
return format | ||
return format; | ||
} | ||
@@ -604,3 +634,3 @@ | ||
} | ||
return moment.fn.format.call(this, format) | ||
return moment.fn.format.call(this, format); | ||
}; | ||
@@ -612,3 +642,3 @@ | ||
, g; | ||
if (typeof input === 'number') { | ||
if (typeof input === "number") { | ||
j = toJalaali(this.year(), this.month(), this.date()); | ||
@@ -619,3 +649,3 @@ lastDay = Math.min(j.jd, jMoment.jDaysInMonth(input, j.jm)); | ||
moment.updateOffset(this); | ||
return this | ||
return this; | ||
} else { | ||
@@ -631,6 +661,7 @@ return toJalaali(this.year(), this.month(), this.date()).jy; | ||
if (!isNull(input)) { | ||
if (typeof input === 'string') { | ||
if (typeof input === "string") { | ||
input = this.lang().jMonthsParse(input); | ||
if (typeof input !== 'number') | ||
if (typeof input !== "number"){ | ||
return this; | ||
} | ||
} | ||
@@ -657,3 +688,3 @@ j = toJalaali(this.year(), this.month(), this.date()); | ||
, g; | ||
if (typeof input === 'number') { | ||
if (typeof input === "number") { | ||
j = toJalaali(this.year(), this.month(), this.date()); | ||
@@ -670,4 +701,4 @@ g = toGregorian(j.jy, j.jm, input); | ||
jMoment.fn.jDayOfYear = function (input) { | ||
var dayOfYear = Math.round((jMoment(this).startOf('day') - jMoment(this).startOf('jYear')) / 864e5) + 1; | ||
return isNull(input) ? dayOfYear : this.add(input - dayOfYear, 'd'); | ||
var dayOfYear = Math.round((jMoment(this).startOf("day") - jMoment(this).startOf("jYear")) / 864e5) + 1; | ||
return isNull(input) ? dayOfYear : this.add(input - dayOfYear, "d"); | ||
}; | ||
@@ -677,3 +708,3 @@ | ||
var week = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).week; | ||
return isNull(input) ? week : this.add((input - week) * 7, 'd'); | ||
return isNull(input) ? week : this.add((input - week) * 7, "d"); | ||
}; | ||
@@ -683,3 +714,3 @@ | ||
var year = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year; | ||
return isNull(input) ? year : this.add(input - year, 'y'); | ||
return isNull(input) ? year : this.add(input - year, "y"); | ||
}; | ||
@@ -695,5 +726,5 @@ | ||
units = normalizeUnits(units); | ||
if (units === 'jyear') { | ||
if (units === "jyear") { | ||
this.jYear(this.jYear() + val); | ||
} else if (units === 'jmonth') { | ||
} else if (units === "jmonth") { | ||
this.jMonth(this.jMonth() + val); | ||
@@ -714,5 +745,5 @@ } else { | ||
units = normalizeUnits(units); | ||
if (units === 'jyear') { | ||
if (units === "jyear") { | ||
this.jYear(this.jYear() - val); | ||
} else if (units === 'jmonth') { | ||
} else if (units === "jmonth") { | ||
this.jMonth(this.jMonth() - val); | ||
@@ -727,4 +758,4 @@ } else { | ||
units = normalizeUnits(units); | ||
if (units === 'jyear' || units === 'jmonth') { | ||
if (units === 'jyear') { | ||
if (units === "jyear" || units === "jmonth") { | ||
if (units === "jyear") { | ||
this.jMonth(0); | ||
@@ -745,6 +776,6 @@ } | ||
units = normalizeUnits(units); | ||
if (units === undefined || units === 'milisecond') { | ||
if (units === undefined || units === "milisecond") { | ||
return this; | ||
} | ||
return this.startOf(units).add(1, (units === 'isoweek' ? 'week' : units)).subtract(1, 'ms'); | ||
return this.startOf(units).add(1, (units === "isoweek" ? "week" : units)).subtract(1, "ms"); | ||
}; | ||
@@ -754,3 +785,3 @@ | ||
units = normalizeUnits(units); | ||
if (units === 'jyear' || units === 'jmonth') { | ||
if (units === "jyear" || units === "jmonth") { | ||
return moment.fn.isSame.call(this.clone().startOf(units), other.clone().startOf(units)); | ||
@@ -795,39 +826,39 @@ } | ||
jMoment.loadPersian = function () { | ||
moment.locale('fa', { | ||
months: ('ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر').split('_') | ||
, monthsShort: ('ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر').split('_') | ||
, weekdays: ('یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_آدینه_شنبه').split('_') | ||
, weekdaysShort: ('یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_آدینه_شنبه').split('_') | ||
, weekdaysMin: 'ی_د_س_چ_پ_آ_ش'.split('_') | ||
moment.locale("fa", { | ||
months: ("ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر").split("_") | ||
, monthsShort: ("ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر").split("_") | ||
, weekdays: ("یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_آدینه_شنبه").split("_") | ||
, weekdaysShort: ("یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_آدینه_شنبه").split("_") | ||
, weekdaysMin: "ی_د_س_چ_پ_آ_ش".split("_") | ||
, longDateFormat: | ||
{ LT: 'HH:mm' | ||
, L: 'jYYYY/jMM/jDD' | ||
, LL: 'jD jMMMM jYYYY' | ||
, LLL: 'jD jMMMM jYYYY LT' | ||
, LLLL: 'dddd، jD jMMMM jYYYY LT' | ||
{ LT: "HH:mm" | ||
, L: "jYYYY/jMM/jDD" | ||
, LL: "jD jMMMM jYYYY" | ||
, LLL: "jD jMMMM jYYYY LT" | ||
, LLLL: "dddd، jD jMMMM jYYYY LT" | ||
} | ||
, calendar: | ||
{ sameDay: '[امروز ساعت] LT' | ||
, nextDay: '[فردا ساعت] LT' | ||
, nextWeek: 'dddd [ساعت] LT' | ||
, lastDay: '[دیروز ساعت] LT' | ||
, lastWeek: 'dddd [ی پیش ساعت] LT' | ||
, sameElse: 'L' | ||
{ sameDay: "[امروز ساعت] LT" | ||
, nextDay: "[فردا ساعت] LT" | ||
, nextWeek: "dddd [ساعت] LT" | ||
, lastDay: "[دیروز ساعت] LT" | ||
, lastWeek: "dddd [ی پیش ساعت] LT" | ||
, sameElse: "L" | ||
} | ||
, relativeTime: | ||
{ future: 'در %s' | ||
, past: '%s پیش' | ||
, s: 'چند ثانیه' | ||
, m: '1 دقیقه' | ||
, mm: '%d دقیقه' | ||
, h: '1 ساعت' | ||
, hh: '%d ساعت' | ||
, d: '1 روز' | ||
, dd: '%d روز' | ||
, M: '1 ماه' | ||
, MM: '%d ماه' | ||
, y: '1 سال' | ||
, yy: '%d سال' | ||
{ future: "در %s" | ||
, past: "%s پیش" | ||
, s: "چند ثانیه" | ||
, m: "1 دقیقه" | ||
, mm: "%d دقیقه" | ||
, h: "1 ساعت" | ||
, hh: "%d ساعت" | ||
, d: "1 روز" | ||
, dd: "%d روز" | ||
, M: "1 ماه" | ||
, MM: "%d ماه" | ||
, y: "1 سال" | ||
, yy: "%d سال" | ||
} | ||
, ordinal: '%dم' | ||
, ordinal: "%dم" | ||
, week: | ||
@@ -838,6 +869,6 @@ { dow: 6 // Saturday is the first day of the week. | ||
, meridiem: function (hour) { | ||
return hour < 12 ? 'ق.ظ' : 'ب.ظ' | ||
return hour < 12 ? "ق.ظ" : "ب.ظ"; | ||
} | ||
, jMonths: ('فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند').split('_') | ||
, jMonthsShort: 'فرو_ارد_خرد_تیر_مرد_شهر_مهر_آبا_آذر_دی_بهم_اسف'.split('_') | ||
, jMonths: ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_") | ||
, jMonthsShort: "فرو_ارد_خرد_تیر_مرد_شهر_مهر_آبا_آذر_دی_بهم_اسف".split("_") | ||
} | ||
@@ -858,3 +889,3 @@ ); | ||
j.jm -= 1; | ||
return j | ||
return j; | ||
} | ||
@@ -865,3 +896,3 @@ | ||
g.gm -= 1; | ||
return g | ||
return g; | ||
} | ||
@@ -874,7 +905,7 @@ | ||
function div(a, b) { | ||
return ~~(a / b) | ||
return ~~(a / b); | ||
} | ||
function mod(a, b) { | ||
return a - ~~(a / b) * b | ||
return a - ~~(a / b) * b; | ||
} |
{ | ||
"name": "jalali-moment", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.", | ||
@@ -24,2 +24,3 @@ "author": { | ||
"scripts": { | ||
"report-coverage": "export CODACY_PROJECT_TOKEN=7f46b99d0c1e4e0e9f176d98d70f972c; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && rm -rf ./coverage", | ||
"test": "mocha --reporter spec --ui bdd --colors --check-leaks test.js", | ||
@@ -38,14 +39,17 @@ "build": "WEBPACK_ENV=build webpack", | ||
"devDependencies": { | ||
"chai": "^2.2.0", | ||
"chai": "^2.3.0", | ||
"codacy-coverage": "^2.0.2", | ||
"eslint": "^3.19.0", | ||
"mocha": "^2.2.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^2.5.3", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"path": "^0.12.7", | ||
"uglifyjs-webpack-plugin": "^0.4.3", | ||
"webpack": "^2.5.1" | ||
"webpack": "^2.6.1" | ||
}, | ||
"dependencies": { | ||
"jalaali-js": "^0.2.0", | ||
"moment": "^2.12.0" | ||
"moment": "^2.18.1" | ||
}, | ||
"typings": "./jalali-moment.d.ts" | ||
} |
@@ -9,2 +9,5 @@ # jalali-moment | ||
[![Package Quality][packageQuality-image]][packageQuality-url] | ||
[![dependencies Quality][dependencies-quality]][dependencies-quality-url] | ||
[![Codacy Badge][codacy-quality]][codacy-quality-url] | ||
[![Codacy Badge][codacy-coverage]][codacy-coverage-url] | ||
@@ -29,2 +32,6 @@ 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). | ||
Install via bower | ||
```shell | ||
bower install jalali-moment --save | ||
``` | ||
@@ -68,3 +75,3 @@ ### Node.js | ||
```HTML | ||
<script src="thisRepo/dist/jalali-moment.js"></script> | ||
<script src="bower_components/jalali-moment/dist/jalali-moment.js"></script> | ||
<script> | ||
@@ -90,17 +97,17 @@ moment().format('jYYYY/jM/jD') | ||
```js | ||
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 | ||
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 | ||
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('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 | ||
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 | ||
moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD'); // 1981/07/17 | ||
``` | ||
@@ -135,2 +142,11 @@ | ||
[packageQuality-image]: http://npm.packagequality.com/shield/jalali-moment.svg | ||
[packageQuality-url]: http://packagequality.com/#?package=jalali-moment | ||
[packageQuality-url]: http://packagequality.com/#?package=jalali-moment | ||
[dependencies-quality]: https://david-dm.org/fingerpich/jalali-moment.svg | ||
[dependencies-quality-url]: https://github.com/fingerpich/jalali-moment | ||
[codacy-quality]:https://api.codacy.com/project/badge/Grade/1aa5b7aadfc24238bdf825d58cb2cba1 | ||
[codacy-quality-url]:https://www.codacy.com/app/zarei-bs/jalali-moment?utm_source=github.com&utm_medium=referral&utm_content=fingerpich/jalali-moment&utm_campaign=Badge_Grade | ||
[codacy-coverage]:https://api.codacy.com/project/badge/Coverage/1aa5b7aadfc24238bdf825d58cb2cba1 | ||
[codacy-coverage-url]:https://www.codacy.com/app/zarei-bs/jalali-moment?utm_source=github.com&utm_medium=referral&utm_content=fingerpich/jalali-moment&utm_campaign=Badge_Coverage |
1588
test.js
var chai = require('chai') | ||
, moment = require('./jalali-moment.js') | ||
var chai = require("chai") | ||
, moment = require("./jalali-moment.js"); | ||
chai.should() | ||
chai.should(); | ||
moment.updateLocale('en' | ||
moment.updateLocale("en" | ||
, { week: | ||
@@ -13,883 +13,883 @@ { dow: 6 | ||
, longDateFormat: | ||
{ LT: 'h:mm A' | ||
, L: 'jYYYY/jMM/jDD' | ||
, LL: 'jD jMMMM jYYYY' | ||
, LLL: 'jD jMMMM jYYYY LT' | ||
, LLLL: 'dddd, jD jMMMM jYYYY LT' | ||
{ LT: "h:mm A" | ||
, L: "jYYYY/jMM/jDD" | ||
, LL: "jD jMMMM jYYYY" | ||
, LLL: "jD jMMMM jYYYY LT" | ||
, LLLL: "dddd, jD jMMMM jYYYY LT" | ||
} | ||
} | ||
) | ||
); | ||
describe('moment', function() { | ||
describe('#parse', function() { | ||
it('should parse gregorian dates', function() { | ||
var m = moment('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') | ||
m.milliseconds().should.be.equal(0) | ||
}) | ||
describe("moment", function() { | ||
describe("#parse", function() { | ||
it("should parse gregorian dates", function() { | ||
var m = moment("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"); | ||
m.milliseconds().should.be.equal(0); | ||
}); | ||
it('should parse correctly when input is only time', function() { | ||
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') | ||
}) | ||
it("should parse correctly when input is only time", function() { | ||
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"); | ||
}); | ||
it('should parse when only Jalaali year is in the format', function() { | ||
var m = moment('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.format('YYYY-MM-DD').should.be.equal('1981-08-17') | ||
}) | ||
it("should parse when only Jalaali year is in the format", function() { | ||
var m = moment("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.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
}); | ||
it('should parse when only Jalaali month is in the format', function() { | ||
var m = moment('1981 5 17', 'YYYY jM D') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-07-17') | ||
}) | ||
it("should parse when only Jalaali month is in the format", function() { | ||
var m = moment("1981 5 17", "YYYY jM D"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
}); | ||
it('should parse when only Jalaali month string is in the format', function() { | ||
var m = moment('1981 Amo 17', 'YYYY jMMM D') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-07-17') | ||
m = moment('1981 Amordaad 17', 'YYYY jMMMM D') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-07-17') | ||
}) | ||
it("should parse when only Jalaali month string is in the format", function() { | ||
var m = moment("1981 Amo 17", "YYYY jMMM D"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
m = moment("1981 Amordaad 17", "YYYY jMMMM D"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
}); | ||
it('should parse when only Jalaali date is in the format', function() { | ||
var m = moment('1981 26 8', 'YYYY jD M') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-08-15') | ||
}) | ||
it("should parse when only Jalaali date is in the format", function() { | ||
var m = moment("1981 26 8", "YYYY jD M"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-15"); | ||
}); | ||
it('should parse when Jalaali year and month are in the format', function() { | ||
var m = moment('17 1360 5', 'D jYYYY jM') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-07-17') | ||
m = moment('1392 7', 'jYYYY jM') | ||
m.format('YYYY-MM-DD').should.be.equal('2013-09-23') | ||
}) | ||
it("should parse when Jalaali year and month are in the format", function() { | ||
var m = moment("17 1360 5", "D jYYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-07-17"); | ||
m = moment("1392 7", "jYYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("2013-09-23"); | ||
}); | ||
it('should parse when Jalaali year and date are in the format', function() { | ||
var m = moment('26 1360 8', 'jD jYYYY M') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-08-15') | ||
}) | ||
it("should parse when Jalaali year and date are in the format", function() { | ||
var m = moment("26 1360 8", "jD jYYYY M"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-15"); | ||
}); | ||
it('should parse when Jalaali month and date are in the format', function() { | ||
var m = moment('26 1981 5', 'jD YYYY jM') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-08-17') | ||
}) | ||
it("should parse when Jalaali month and date are in the format", function() { | ||
var m = moment("26 1981 5", "jD YYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
}); | ||
it('should parse when Jalaali year, month and date are in the format', function() { | ||
var m = moment('26 1360 5', 'jD jYYYY jM') | ||
m.format('YYYY-MM-DD').should.be.equal('1981-08-17') | ||
}) | ||
it("should parse when Jalaali year, month and date are in the format", function() { | ||
var m = moment("26 1360 5", "jD jYYYY jM"); | ||
m.format("YYYY-MM-DD").should.be.equal("1981-08-17"); | ||
}); | ||
it('should parse with complex format', function() { | ||
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') | ||
}) | ||
it("should parse with complex format", function() { | ||
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"); | ||
}); | ||
it('should parse format result', function() { | ||
var f = 'jYYYY/jM/jD hh:mm:ss.SSS a' | ||
, m = moment() | ||
moment(m.format(f), f).isSame(m).should.be.true | ||
}) | ||
it("should parse format result", function() { | ||
var f = "jYYYY/jM/jD hh:mm:ss.SSS a" | ||
, m = moment(); | ||
moment(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') | ||
m.format('YYYY-MM-DD hh:mm:ss Z').should.be.equal('1981-08-17 07:10:20 +00:00') | ||
}) | ||
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"); | ||
m.format("YYYY-MM-DD hh:mm:ss Z").should.be.equal("1981-08-17 07:10:20 +00:00"); | ||
}); | ||
it('should parse with a format array', function() { | ||
var p1 = 'jYY jM jD' | ||
, p2 = 'jM jD jYY' | ||
, p3 = 'jD jYY jM' | ||
, m | ||
m = moment('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.format('jYY-jMM-jDD').should.be.equal('10-11-12') | ||
m = moment('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.format('jYY-jMM-jDD').should.be.equal('11-12-10') | ||
m = moment('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.format('jYY-jMM-jDD').should.be.equal('60-11-12') | ||
m = moment('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.format('YY-MM-DD').should.be.equal('60-08-31') | ||
m = moment('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.format('YY-MM-DD').should.be.equal('60-05-31') | ||
m = moment('60 5 31', ['jYY jM jD', 'YY M D']) | ||
m.format('jYY-jMM-jDD').should.be.equal('60-05-31') | ||
}) | ||
}) | ||
it("should parse with a format array", function() { | ||
var p1 = "jYY jM jD" | ||
, p2 = "jM jD jYY" | ||
, p3 = "jD jYY jM" | ||
, m; | ||
m = moment("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.format("jYY-jMM-jDD").should.be.equal("10-11-12"); | ||
m = moment("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.format("jYY-jMM-jDD").should.be.equal("11-12-10"); | ||
m = moment("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.format("jYY-jMM-jDD").should.be.equal("60-11-12"); | ||
m = moment("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.format("YY-MM-DD").should.be.equal("60-08-31"); | ||
m = moment("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.format("YY-MM-DD").should.be.equal("60-05-31"); | ||
m = moment("60 5 31", ["jYY jM jD", "YY M D"]); | ||
m.format("jYY-jMM-jDD").should.be.equal("60-05-31"); | ||
}); | ||
}); | ||
describe('#format', function() { | ||
it('should work normally when there is no Jalaali token', function() { | ||
var m = moment('1981-08-17 07:10:20') | ||
m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('1981-08-17 07:10:20') | ||
}) | ||
describe("#format", function() { | ||
it("should work normally when there is no Jalaali token", function() { | ||
var m = moment("1981-08-17 07:10:20"); | ||
m.format("YYYY-MM-DD hh:mm:ss").should.be.equal("1981-08-17 07:10:20"); | ||
}); | ||
it('should format to Jalaali with Jalaali tokens', function() { | ||
var m = moment('1981-08-17 07:10:20') | ||
m.format('jYYYY-jMM-jDD hh:mm:ss').should.be.equal('1360-05-26 07:10:20') | ||
}) | ||
it("should format to Jalaali with Jalaali tokens", function() { | ||
var m = moment("1981-08-17 07:10:20"); | ||
m.format("jYYYY-jMM-jDD hh:mm:ss").should.be.equal("1360-05-26 07:10:20"); | ||
}); | ||
it('should format with escaped and unescaped tokens', function() { | ||
var m = moment('1981-08-17') | ||
m.format('[My] birt\\h y[ea]r [is] jYYYY or YYYY').should.be.equal('My birth year is 1360 or 1981') | ||
}) | ||
it("should format with escaped and unescaped tokens", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("[My] birt\\h y[ea]r [is] jYYYY or YYYY").should.be.equal("My birth year is 1360 or 1981"); | ||
}); | ||
it('should format with mixed tokens', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jYYYY/jMM/jDD = YYYY-MM-DD').should.be.equal('1360/05/26 = 1981-08-17') | ||
}) | ||
it("should format with mixed tokens", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jYYYY/jMM/jDD = YYYY-MM-DD").should.be.equal("1360/05/26 = 1981-08-17"); | ||
}); | ||
it('should format with jMo', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jMo').should.be.equal('5th') | ||
}) | ||
it("should format with jMo", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jMo").should.be.equal("5th"); | ||
}); | ||
it('should format with jM', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jM').should.be.equal('5') | ||
}) | ||
it("should format with jM", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jM").should.be.equal("5"); | ||
}); | ||
it('should format with jMM', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jMM').should.be.equal('05') | ||
}) | ||
it("should format with jMM", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jMM").should.be.equal("05"); | ||
}); | ||
it('should format with jMMM', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jMMM').should.be.equal('Amo') | ||
}) | ||
it("should format with jMMM", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jMMM").should.be.equal("Amo"); | ||
}); | ||
it('should format with jMMMM', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jMMMM').should.be.equal('Amordaad') | ||
}) | ||
it("should format with jMMMM", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jMMMM").should.be.equal("Amordaad"); | ||
}); | ||
it('should format with jDo', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jDo').should.be.equal('26th') | ||
}) | ||
it("should format with jDo", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jDo").should.be.equal("26th"); | ||
}); | ||
it('should format with jD', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jD').should.be.equal('26') | ||
}) | ||
it("should format with jD", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jD").should.be.equal("26"); | ||
}); | ||
it('should format with jDD', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jDD').should.be.equal('26') | ||
m = moment('1981-08-23') | ||
m.format('jDD').should.be.equal('01') | ||
}) | ||
it("should format with jDD", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jDD").should.be.equal("26"); | ||
m = moment("1981-08-23"); | ||
m.format("jDD").should.be.equal("01"); | ||
}); | ||
it('should format with jDDD', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jDDD').should.be.equal('150') | ||
}) | ||
it("should format with jDDD", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jDDD").should.be.equal("150"); | ||
}); | ||
it('should format with jDDDo', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jDDDo').should.be.equal('150th') | ||
}) | ||
it("should format with jDDDo", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jDDDo").should.be.equal("150th"); | ||
}); | ||
it('should format with jDDDD', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jDDDD').should.be.equal('150') | ||
m = moment('1981-03-21') | ||
m.format('jDDDD').should.be.equal('001') | ||
}) | ||
it("should format with jDDDD", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jDDDD").should.be.equal("150"); | ||
m = moment("1981-03-21"); | ||
m.format("jDDDD").should.be.equal("001"); | ||
}); | ||
it('should format with jwo', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jwo').should.be.equal('22nd') | ||
}) | ||
it("should format with jwo", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jwo").should.be.equal("22nd"); | ||
}); | ||
it('should format with jw', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jw').should.be.equal('22') | ||
}) | ||
it("should format with jw", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jw").should.be.equal("22"); | ||
}); | ||
it('should format with jww', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jww').should.be.equal('22') | ||
m = moment('1981-04-23') | ||
m.format('jww').should.be.equal('05') | ||
}) | ||
it("should format with jww", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jww").should.be.equal("22"); | ||
m = moment("1981-04-23"); | ||
m.format("jww").should.be.equal("05"); | ||
}); | ||
it('should format with jYY', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jYY').should.be.equal('60') | ||
}) | ||
it("should format with jYY", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jYY").should.be.equal("60"); | ||
}); | ||
it('should format with jYYYY', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jYYYY').should.be.equal('1360') | ||
}) | ||
it("should format with jYYYY", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jYYYY").should.be.equal("1360"); | ||
}); | ||
it('should format with jYYYYY', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jYYYYY').should.be.equal('01360') | ||
}) | ||
it("should format with jYYYYY", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jYYYYY").should.be.equal("01360"); | ||
}); | ||
it('should format with jgg', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jgg').should.be.equal('60') | ||
}) | ||
it("should format with jgg", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jgg").should.be.equal("60"); | ||
}); | ||
it('should format with jgggg', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jgggg').should.be.equal('1360') | ||
}) | ||
it("should format with jgggg", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jgggg").should.be.equal("1360"); | ||
}); | ||
it('should format with jggggg', function() { | ||
var m = moment('1981-08-17') | ||
m.format('jggggg').should.be.equal('01360') | ||
}) | ||
it("should format with jggggg", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("jggggg").should.be.equal("01360"); | ||
}); | ||
it('should work with long date formats too', function() { | ||
var m = moment('1981-08-17') | ||
m.format('LT').should.be.equal('12:00 AM') | ||
m.format('L').should.be.equal('1360/05/26') | ||
m.format('l').should.be.equal('1360/5/26') | ||
m.format('LL').should.be.equal('26 Amordaad 1360') | ||
m.format('ll').should.be.equal('26 Amo 1360') | ||
m.format('LLL').should.be.equal('26 Amordaad 1360 12:00 AM') | ||
m.format('lll').should.be.equal('26 Amo 1360 12:00 AM') | ||
m.format('LLLL').should.be.equal('Monday, 26 Amordaad 1360 12:00 AM') | ||
m.format('llll').should.be.equal('Mon, 26 Amo 1360 12:00 AM') | ||
}) | ||
}) | ||
it("should work with long date formats too", function() { | ||
var m = moment("1981-08-17"); | ||
m.format("LT").should.be.equal("12:00 AM"); | ||
m.format("L").should.be.equal("1360/05/26"); | ||
m.format("l").should.be.equal("1360/5/26"); | ||
m.format("LL").should.be.equal("26 Amordaad 1360"); | ||
m.format("ll").should.be.equal("26 Amo 1360"); | ||
m.format("LLL").should.be.equal("26 Amordaad 1360 12:00 AM"); | ||
m.format("lll").should.be.equal("26 Amo 1360 12:00 AM"); | ||
m.format("LLLL").should.be.equal("Monday, 26 Amordaad 1360 12:00 AM"); | ||
m.format("llll").should.be.equal("Mon, 26 Amo 1360 12:00 AM"); | ||
}); | ||
}); | ||
describe('#jYear', function() { | ||
it('should return Jalaali year', function() { | ||
var m = moment('1981-08-17') | ||
m.jYear().should.be.equal(1360) | ||
}) | ||
describe("#jYear", function() { | ||
it("should return Jalaali year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jYear().should.be.equal(1360); | ||
}); | ||
it('should set Jalaali year', function() { | ||
var m = moment('1981-08-17') | ||
m.jYear(1392) | ||
m.format('jYYYY/jM/jD').should.be.equal('1392/5/26') | ||
m = moment('2013-03-20') | ||
m.format('jYY/jM/jD').should.be.equal('91/12/30') | ||
m.jYear(1392) | ||
m.format('jYY/jM/jD').should.be.equal('92/12/29') | ||
}) | ||
it("should set Jalaali year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jYear(1392); | ||
m.format("jYYYY/jM/jD").should.be.equal("1392/5/26"); | ||
m = moment("2013-03-20"); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/30"); | ||
m.jYear(1392); | ||
m.format("jYY/jM/jD").should.be.equal("92/12/29"); | ||
}); | ||
it('should also has jYears alias', function() { | ||
moment.fn.jYear.should.be.equal(moment.fn.jYears) | ||
}) | ||
}) | ||
it("should also has jYears alias", function() { | ||
moment.fn.jYear.should.be.equal(moment.fn.jYears); | ||
}); | ||
}); | ||
describe('#jMonth', function() { | ||
it('should return Jalaali month', function() { | ||
var m = moment('1981-08-17') | ||
m.jMonth().should.be.equal(4) | ||
}) | ||
describe("#jMonth", function() { | ||
it("should return Jalaali month", function() { | ||
var m = moment("1981-08-17"); | ||
m.jMonth().should.be.equal(4); | ||
}); | ||
it('should set Jalaali month', function() { | ||
var m = moment('1981-08-17') | ||
m.jMonth(7) | ||
m.format('jYYYY/jM/jD').should.be.equal('1360/8/26') | ||
m = moment('2012-08-21') | ||
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.format('jYY/jM/jD').should.be.equal('92/5/31') | ||
m.jMonth(11) | ||
m.format('jYY/jM/jD').should.be.equal('92/12/29') | ||
}) | ||
it("should set Jalaali month", function() { | ||
var m = moment("1981-08-17"); | ||
m.jMonth(7); | ||
m.format("jYYYY/jM/jD").should.be.equal("1360/8/26"); | ||
m = moment("2012-08-21"); | ||
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.format("jYY/jM/jD").should.be.equal("92/5/31"); | ||
m.jMonth(11); | ||
m.format("jYY/jM/jD").should.be.equal("92/12/29"); | ||
}); | ||
it('should also has jMonths alias', function() { | ||
moment.fn.jMonth.should.be.equal(moment.fn.jMonths) | ||
}) | ||
}) | ||
it("should also has jMonths alias", function() { | ||
moment.fn.jMonth.should.be.equal(moment.fn.jMonths); | ||
}); | ||
}); | ||
describe('#jDate', function() { | ||
it('should return Jalaali date', function() { | ||
var m = moment('1981-08-17') | ||
m.jDate().should.be.equal(26) | ||
}) | ||
describe("#jDate", function() { | ||
it("should return Jalaali date", function() { | ||
var m = moment("1981-08-17"); | ||
m.jDate().should.be.equal(26); | ||
}); | ||
it('should set Jalaali date', function() { | ||
var m = moment('1981-08-17') | ||
m.jDate(30) | ||
m.format('jYYYY/jM/jD').should.be.equal('1360/5/30') | ||
m = moment('2013-03-01') | ||
m.format('jYY/jM/jD').should.be.equal('91/12/11') | ||
m.jDate(29) | ||
m.format('jYY/jM/jD').should.be.equal('91/12/29') | ||
m.jDate(30) | ||
m.format('jYY/jM/jD').should.be.equal('91/12/30') | ||
m.jDate(30) | ||
m.format('jYY/jM/jD').should.be.equal('91/12/30') | ||
m.jDate(31) | ||
m.format('jYY/jM/jD').should.be.equal('92/1/1') | ||
m.jDate(90) | ||
m.format('jYY/jM/jD').should.be.equal('92/3/28') | ||
}) | ||
it("should set Jalaali date", function() { | ||
var m = moment("1981-08-17"); | ||
m.jDate(30); | ||
m.format("jYYYY/jM/jD").should.be.equal("1360/5/30"); | ||
m = moment("2013-03-01"); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/11"); | ||
m.jDate(29); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/29"); | ||
m.jDate(30); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/30"); | ||
m.jDate(30); | ||
m.format("jYY/jM/jD").should.be.equal("91/12/30"); | ||
m.jDate(31); | ||
m.format("jYY/jM/jD").should.be.equal("92/1/1"); | ||
m.jDate(90); | ||
m.format("jYY/jM/jD").should.be.equal("92/3/28"); | ||
}); | ||
it('should also has jDates alias', function() { | ||
moment.fn.jDate.should.be.equal(moment.fn.jDates) | ||
}) | ||
}) | ||
it("should also has jDates alias", function() { | ||
moment.fn.jDate.should.be.equal(moment.fn.jDates); | ||
}); | ||
}); | ||
describe('#jDayOfYear', function() { | ||
it('should return Jalaali date of year', function() { | ||
var m = moment('1981-08-17') | ||
m.jDayOfYear().should.be.equal(150) | ||
m = moment('1981-03-21') | ||
m.jDayOfYear().should.be.equal(1) | ||
m = moment('1982-03-20') | ||
m.jDayOfYear().should.be.equal(365) | ||
m = moment('1984-03-20') | ||
m.jDayOfYear().should.be.equal(366) | ||
}) | ||
describe("#jDayOfYear", function() { | ||
it("should return Jalaali date of year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jDayOfYear().should.be.equal(150); | ||
m = moment("1981-03-21"); | ||
m.jDayOfYear().should.be.equal(1); | ||
m = moment("1982-03-20"); | ||
m.jDayOfYear().should.be.equal(365); | ||
m = moment("1984-03-20"); | ||
m.jDayOfYear().should.be.equal(366); | ||
}); | ||
it('should set Jalaali date of year', function() { | ||
var m = moment('1981-08-17') | ||
m.jDayOfYear(30) | ||
m.format('jYYYY/jM/jD').should.be.equal('1360/1/30') | ||
m.jDayOfYear(364) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/28') | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/29') | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('61/1/1') | ||
m.jDayOfYear(1) | ||
m.format('jYY/jM/jD').should.be.equal('61/1/1') | ||
m.jDayOfYear(90) | ||
m.format('jYY/jM/jD').should.be.equal('61/3/28') | ||
m.jDayOfYear(365 + 366) | ||
m.format('jYY/jM/jD').should.be.equal('62/12/30') | ||
}) | ||
}) | ||
it("should set Jalaali date of year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jDayOfYear(30); | ||
m.format("jYYYY/jM/jD").should.be.equal("1360/1/30"); | ||
m.jDayOfYear(364); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/28"); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/29"); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("61/1/1"); | ||
m.jDayOfYear(1); | ||
m.format("jYY/jM/jD").should.be.equal("61/1/1"); | ||
m.jDayOfYear(90); | ||
m.format("jYY/jM/jD").should.be.equal("61/3/28"); | ||
m.jDayOfYear(365 + 366); | ||
m.format("jYY/jM/jD").should.be.equal("62/12/30"); | ||
}); | ||
}); | ||
describe('#jWeek', function() { | ||
it('should return Jalaali week of year', function() { | ||
var m = moment('1981-08-17') | ||
m.jWeek().should.be.equal(22) | ||
m.jDayOfYear(1) | ||
m.format('jYY/jM/jD').should.be.equal('60/1/1') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(8) | ||
m.format('jYY/jM/jD').should.be.equal('60/1/8') | ||
m.jWeek().should.be.equal(2) | ||
m.jDayOfYear(14) | ||
m.format('jYY/jM/jD').should.be.equal('60/1/14') | ||
m.jWeek().should.be.equal(2) | ||
m.jDayOfYear(364) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/28') | ||
m.jWeek().should.be.equal(52) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/29') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('61/1/1') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(363) | ||
m.format('jYY/jM/jD').should.be.equal('61/12/27') | ||
m.jWeek().should.be.equal(52) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('61/12/29') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('62/1/1') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('62/12/29') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('62/12/30') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(367) | ||
m.format('jYY/jM/jD').should.be.equal('63/1/1') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('63/12/29') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('64/1/1') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('64/12/29') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('65/1/1') | ||
m.jWeek().should.be.equal(1) | ||
m.jDayOfYear(358) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/22') | ||
m.jWeek().should.be.equal(52) | ||
m.jDayOfYear(359) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/23') | ||
m.jWeek().should.be.equal(53) | ||
m.jDayOfYear(360) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/24') | ||
m.jWeek().should.be.equal(53) | ||
m.jDayOfYear(361) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/25') | ||
m.jWeek().should.be.equal(53) | ||
m.jDayOfYear(362) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/26') | ||
m.jWeek().should.be.equal(53) | ||
m.jDayOfYear(363) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/27') | ||
m.jWeek().should.be.equal(53) | ||
m.jDayOfYear(364) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/28') | ||
m.jWeek().should.be.equal(53) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/29') | ||
m.jWeek().should.be.equal(53) | ||
}) | ||
describe("#jWeek", function() { | ||
it("should return Jalaali week of year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jWeek().should.be.equal(22); | ||
m.jDayOfYear(1); | ||
m.format("jYY/jM/jD").should.be.equal("60/1/1"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(8); | ||
m.format("jYY/jM/jD").should.be.equal("60/1/8"); | ||
m.jWeek().should.be.equal(2); | ||
m.jDayOfYear(14); | ||
m.format("jYY/jM/jD").should.be.equal("60/1/14"); | ||
m.jWeek().should.be.equal(2); | ||
m.jDayOfYear(364); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/28"); | ||
m.jWeek().should.be.equal(52); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/29"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("61/1/1"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(363); | ||
m.format("jYY/jM/jD").should.be.equal("61/12/27"); | ||
m.jWeek().should.be.equal(52); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("61/12/29"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("62/1/1"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("62/12/29"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("62/12/30"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(367); | ||
m.format("jYY/jM/jD").should.be.equal("63/1/1"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("63/12/29"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("64/1/1"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("64/12/29"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("65/1/1"); | ||
m.jWeek().should.be.equal(1); | ||
m.jDayOfYear(358); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/22"); | ||
m.jWeek().should.be.equal(52); | ||
m.jDayOfYear(359); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/23"); | ||
m.jWeek().should.be.equal(53); | ||
m.jDayOfYear(360); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/24"); | ||
m.jWeek().should.be.equal(53); | ||
m.jDayOfYear(361); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/25"); | ||
m.jWeek().should.be.equal(53); | ||
m.jDayOfYear(362); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/26"); | ||
m.jWeek().should.be.equal(53); | ||
m.jDayOfYear(363); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/27"); | ||
m.jWeek().should.be.equal(53); | ||
m.jDayOfYear(364); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/28"); | ||
m.jWeek().should.be.equal(53); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/29"); | ||
m.jWeek().should.be.equal(53); | ||
}); | ||
it('should set Jalaali week of year', function() { | ||
var m = moment('1981-08-17') | ||
m.jWeek(1) | ||
m.format('jYY/jM/jD').should.be.equal('60/1/3') | ||
m.jWeek(22) | ||
m.format('jYY/jM/jD').should.be.equal('60/5/26') | ||
m.jWeek(52) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/24') | ||
m.jWeek(53) | ||
m.format('jYY/jM/jD').should.be.equal('61/1/2') | ||
m.jWeek(1) | ||
m.format('jYY/jM/jD').should.be.equal('61/1/2') | ||
m.jWeek(0) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/24') | ||
m.jWeek(-1) | ||
m.format('jYY/jM/jD').should.be.equal('59/12/18') | ||
}) | ||
}) | ||
it("should set Jalaali week of year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jWeek(1); | ||
m.format("jYY/jM/jD").should.be.equal("60/1/3"); | ||
m.jWeek(22); | ||
m.format("jYY/jM/jD").should.be.equal("60/5/26"); | ||
m.jWeek(52); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/24"); | ||
m.jWeek(53); | ||
m.format("jYY/jM/jD").should.be.equal("61/1/2"); | ||
m.jWeek(1); | ||
m.format("jYY/jM/jD").should.be.equal("61/1/2"); | ||
m.jWeek(0); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/24"); | ||
m.jWeek(-1); | ||
m.format("jYY/jM/jD").should.be.equal("59/12/18"); | ||
}); | ||
}); | ||
describe('#jWeekYear', function() { | ||
it('should return Jalaali week year', function() { | ||
var m = moment('1981-08-17') | ||
m.jWeekYear().should.be.equal(1360) | ||
m.jDayOfYear(1) | ||
m.format('jYY/jM/jD').should.be.equal('60/1/1') | ||
m.jWeekYear().should.be.equal(1360) | ||
m.jDayOfYear(364) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/28') | ||
m.jWeekYear().should.be.equal(1360) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('60/12/29') | ||
m.jWeekYear().should.be.equal(1361) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('61/1/1') | ||
m.jWeekYear().should.be.equal(1361) | ||
m.jDayOfYear(363) | ||
m.format('jYY/jM/jD').should.be.equal('61/12/27') | ||
m.jWeekYear().should.be.equal(1361) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('61/12/29') | ||
m.jWeekYear().should.be.equal(1362) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('62/1/1') | ||
m.jWeekYear().should.be.equal(1362) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('62/12/29') | ||
m.jWeekYear().should.be.equal(1363) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('62/12/30') | ||
m.jWeekYear().should.be.equal(1363) | ||
m.jDayOfYear(367) | ||
m.format('jYY/jM/jD').should.be.equal('63/1/1') | ||
m.jWeekYear().should.be.equal(1363) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('63/12/29') | ||
m.jWeekYear().should.be.equal(1364) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('64/1/1') | ||
m.jWeekYear().should.be.equal(1364) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('64/12/29') | ||
m.jWeekYear().should.be.equal(1365) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('65/1/1') | ||
m.jWeekYear().should.be.equal(1365) | ||
m.jDayOfYear(358) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/22') | ||
m.jWeekYear().should.be.equal(1365) | ||
m.jDayOfYear(359) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/23') | ||
m.jWeekYear().should.be.equal(1365) | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('65/12/29') | ||
m.jWeekYear().should.be.equal(1365) | ||
m.jDayOfYear(366) | ||
m.format('jYY/jM/jD').should.be.equal('66/1/1') | ||
m.jWeekYear().should.be.equal(1366) | ||
}) | ||
describe("#jWeekYear", function() { | ||
it("should return Jalaali week year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jWeekYear().should.be.equal(1360); | ||
m.jDayOfYear(1); | ||
m.format("jYY/jM/jD").should.be.equal("60/1/1"); | ||
m.jWeekYear().should.be.equal(1360); | ||
m.jDayOfYear(364); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/28"); | ||
m.jWeekYear().should.be.equal(1360); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("60/12/29"); | ||
m.jWeekYear().should.be.equal(1361); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("61/1/1"); | ||
m.jWeekYear().should.be.equal(1361); | ||
m.jDayOfYear(363); | ||
m.format("jYY/jM/jD").should.be.equal("61/12/27"); | ||
m.jWeekYear().should.be.equal(1361); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("61/12/29"); | ||
m.jWeekYear().should.be.equal(1362); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("62/1/1"); | ||
m.jWeekYear().should.be.equal(1362); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("62/12/29"); | ||
m.jWeekYear().should.be.equal(1363); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("62/12/30"); | ||
m.jWeekYear().should.be.equal(1363); | ||
m.jDayOfYear(367); | ||
m.format("jYY/jM/jD").should.be.equal("63/1/1"); | ||
m.jWeekYear().should.be.equal(1363); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("63/12/29"); | ||
m.jWeekYear().should.be.equal(1364); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("64/1/1"); | ||
m.jWeekYear().should.be.equal(1364); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("64/12/29"); | ||
m.jWeekYear().should.be.equal(1365); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("65/1/1"); | ||
m.jWeekYear().should.be.equal(1365); | ||
m.jDayOfYear(358); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/22"); | ||
m.jWeekYear().should.be.equal(1365); | ||
m.jDayOfYear(359); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/23"); | ||
m.jWeekYear().should.be.equal(1365); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("65/12/29"); | ||
m.jWeekYear().should.be.equal(1365); | ||
m.jDayOfYear(366); | ||
m.format("jYY/jM/jD").should.be.equal("66/1/1"); | ||
m.jWeekYear().should.be.equal(1366); | ||
}); | ||
it('should set Jalaali week year', function() { | ||
var m = moment('1981-08-17') | ||
m.jWeekYear(1361) | ||
m.format('jYY/jM/jD').should.be.equal('61/5/26') | ||
m.jWeekYear(1364) | ||
m.format('jYY/jM/jD').should.be.equal('64/5/26') | ||
m.jDayOfYear(365) | ||
m.format('jYY/jM/jD').should.be.equal('64/12/29') | ||
m.jWeekYear(1364) | ||
m.format('jYY/jM/jD').should.be.equal('63/12/29') | ||
m.jWeekYear(1365) | ||
m.format('jYY/jM/jD').should.be.equal('64/12/29') | ||
}) | ||
}) | ||
it("should set Jalaali week year", function() { | ||
var m = moment("1981-08-17"); | ||
m.jWeekYear(1361); | ||
m.format("jYY/jM/jD").should.be.equal("61/5/26"); | ||
m.jWeekYear(1364); | ||
m.format("jYY/jM/jD").should.be.equal("64/5/26"); | ||
m.jDayOfYear(365); | ||
m.format("jYY/jM/jD").should.be.equal("64/12/29"); | ||
m.jWeekYear(1364); | ||
m.format("jYY/jM/jD").should.be.equal("63/12/29"); | ||
m.jWeekYear(1365); | ||
m.format("jYY/jM/jD").should.be.equal("64/12/29"); | ||
}); | ||
}); | ||
describe('#startOf', function() { | ||
it('should work as expected without jYear and jMonth', function() { | ||
var m = moment('1981-08-17 07:10:20') | ||
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') | ||
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.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') | ||
m.startOf('week').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1981-08-15 00:00:00') | ||
}) | ||
describe("#startOf", function() { | ||
it("should work as expected without jYear and jMonth", function() { | ||
var m = moment("1981-08-17 07:10:20"); | ||
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"); | ||
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.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"); | ||
m.startOf("week").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-15 00:00:00"); | ||
}); | ||
it('should return start of Jalaali year, month and date', function() { | ||
var m = moment('1981-08-17 07:10:20') | ||
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') | ||
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') | ||
m.startOf('day').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1360-05-26 00:00:00') | ||
m = moment('1981-08-17 07:10:20') | ||
m.startOf('week').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1360-05-24 00:00:00') | ||
}) | ||
}) | ||
it("should return start of Jalaali year, month and date", function() { | ||
var m = moment("1981-08-17 07:10:20"); | ||
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"); | ||
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"); | ||
m.startOf("day").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-26 00:00:00"); | ||
m = moment("1981-08-17 07:10:20"); | ||
m.startOf("week").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-24 00:00:00"); | ||
}); | ||
}); | ||
describe('#endOf', function() { | ||
it('should work as expected without jYear and jMonth', function() { | ||
var m = moment('1981-08-17 07:10:20') | ||
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') | ||
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') | ||
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') | ||
m.endOf('week').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1981-08-21 23:59:59') | ||
}) | ||
describe("#endOf", function() { | ||
it("should work as expected without jYear and jMonth", function() { | ||
var m = moment("1981-08-17 07:10:20"); | ||
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"); | ||
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"); | ||
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"); | ||
m.endOf("week").format("YYYY-MM-DD HH:mm:ss").should.be.equal("1981-08-21 23:59:59"); | ||
}); | ||
it('should return end of Jalaali year, month and date', function() { | ||
var m = moment('1981-08-17 07:10:20') | ||
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') | ||
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') | ||
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') | ||
m.endOf('week').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1360-05-30 23:59:59') | ||
}) | ||
}) | ||
it("should return end of Jalaali year, month and date", function() { | ||
var m = moment("1981-08-17 07:10:20"); | ||
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"); | ||
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"); | ||
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"); | ||
m.endOf("week").format("jYYYY-jMM-jDD HH:mm:ss").should.be.equal("1360-05-30 23:59:59"); | ||
}); | ||
}); | ||
describe('#isValid', function() { | ||
it('should return true when a valid date is parsed and false otherwise', function() { | ||
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 | ||
moment('1393/11/00', jf).isValid().should.be.false | ||
}) | ||
}) | ||
describe("#isValid", function() { | ||
it("should return true when a valid date is parsed and false otherwise", function() { | ||
var jf = "jYYYY/jMM/jDD" | ||
, 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(false); | ||
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); | ||
}); | ||
}); | ||
describe('#isValid-strict', function () { | ||
it('should return false when gregorian date is not strictly valid', function () { | ||
var gf = 'YYYY-MM-DD' | ||
moment('1981-08-17', gf).isValid().should.be.true | ||
moment('1981-08-31', gf).isValid().should.be.true | ||
moment('1981-08-311', gf).isValid().should.be.true | ||
moment('1981-08-311', gf, true).isValid().should.be.false | ||
}) | ||
describe("#isValid-strict", function () { | ||
it("should return false when gregorian date is not strictly valid", function () { | ||
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); | ||
}); | ||
it('should return false when jalaali date is not strictly valid', function () { | ||
var jf = 'jYYYY/jMM/jDD' | ||
moment('1360/05/26', jf).isValid().should.be.true | ||
moment('1360/05/31', jf).isValid().should.be.true | ||
moment('1360/05/311', jf, true).isValid().should.be.false | ||
}) | ||
}) | ||
it("should return false when jalaali date is not strictly valid", function () { | ||
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); | ||
}); | ||
}); | ||
describe('#clone', function() { | ||
it('should return a cloned instance', function() { | ||
var m = moment('1360/5/26', 'jYYYY/jM/jD') | ||
, c = m.clone() | ||
m.add(1, 'jYear') | ||
m.add(4, 'day') | ||
m.format('jYY/jM/jD').should.be.equal('61/5/30') | ||
c.format('jYY/jM/jD').should.be.equal('60/5/26') | ||
}) | ||
}) | ||
describe("#clone", function() { | ||
it("should return a cloned instance", function() { | ||
var m = moment("1360/5/26", "jYYYY/jM/jD") | ||
, c = m.clone(); | ||
m.add(1, "jYear"); | ||
m.add(4, "day"); | ||
m.format("jYY/jM/jD").should.be.equal("61/5/30"); | ||
c.format("jYY/jM/jD").should.be.equal("60/5/26"); | ||
}); | ||
}); | ||
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') | ||
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, "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') | ||
}) | ||
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') | ||
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, "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') | ||
}) | ||
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') | ||
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') | ||
}) | ||
}) | ||
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') | ||
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, "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') | ||
}) | ||
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') | ||
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, "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') | ||
}) | ||
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') | ||
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') | ||
}) | ||
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"); | ||
}); | ||
it('should subtract months correctly', 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(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') | ||
it("should subtract months correctly", 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(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 = 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 = 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 = 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 = 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"); | ||
}); | ||
}); | ||
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 | ||
}) | ||
}) | ||
describe(".jIsLeapYear", function() { | ||
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); | ||
}); | ||
}); | ||
describe('.loadPersian', function() { | ||
it('should load Persian lang', function() { | ||
describe(".loadPersian", function() { | ||
it("should load Persian lang", function() { | ||
var ol = moment.locale() | ||
, m | ||
moment.loadPersian() | ||
m = moment('1981-08-17') | ||
m.format('D MMMM YYYY').should.be.equal('17 اوت 1981') | ||
m.format('jD jMMMM jYYYY').should.be.equal('26 مرداد 1360') | ||
m.calendar().should.be.equal('1360/05/26') | ||
m.format('LLLL').should.be.equal('دوشنبه، 26 مرداد 1360 00:00') | ||
m.format('llll').should.be.equal('دوشنبه، 26 مرد 1360 00:00') | ||
moment.locale(ol) | ||
}) | ||
}) | ||
, m; | ||
moment.loadPersian(); | ||
m = moment("1981-08-17"); | ||
m.format("D MMMM YYYY").should.be.equal("17 اوت 1981"); | ||
m.format("jD jMMMM jYYYY").should.be.equal("26 مرداد 1360"); | ||
m.calendar().should.be.equal("1360/05/26"); | ||
m.format("LLLL").should.be.equal("دوشنبه، 26 مرداد 1360 00:00"); | ||
m.format("llll").should.be.equal("دوشنبه، 26 مرد 1360 00:00"); | ||
moment.locale(ol); | ||
}); | ||
}); | ||
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') | ||
}) | ||
}) | ||
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"); | ||
}); | ||
}); | ||
describe('#isSame', function () { | ||
it('should work correctly for same year', function () { | ||
var m1 = moment('2016-02-04') | ||
var m2 = moment('2016-01-01') | ||
var m3 = moment('2015-12-31') | ||
var m4 = moment('2017-01-01') | ||
m1.isSame(m2, 'year').should.be.true | ||
m1.isSame(m3, 'year').should.be.false | ||
m1.isSame(m4, 'year').should.be.false | ||
m2.isSame(m3, 'year').should.be.false | ||
m2.isSame(m4, 'year').should.be.false | ||
m3.isSame(m4, 'year').should.be.false | ||
m1.isSame(moment('2016-02-04'), 'day').should.be.true | ||
}) | ||
describe("#isSame", function () { | ||
it("should work correctly for same year", function () { | ||
var m1 = moment("2016-02-04"); | ||
var m2 = moment("2016-01-01"); | ||
var m3 = moment("2015-12-31"); | ||
var m4 = moment("2017-01-01"); | ||
m1.isSame(m2, "year").should.be.equal(true); | ||
m1.isSame(m3, "year").should.be.equal(false); | ||
m1.isSame(m4, "year").should.be.equal(false); | ||
m2.isSame(m3, "year").should.be.equal(false); | ||
m2.isSame(m4, "year").should.be.equal(false); | ||
m3.isSame(m4, "year").should.be.equal(false); | ||
m1.isSame(moment("2016-02-04"), "day").should.be.equal(true); | ||
}); | ||
it('should work correctly for same month', function () { | ||
var m1 = moment('2016-02-04') | ||
var m2 = moment('2016-02-01') | ||
var m3 = moment('2016-01-01') | ||
var m4 = moment('2016-03-01') | ||
m1.isSame(m2, 'month').should.be.true | ||
m1.isSame(m3, 'month').should.be.false | ||
m1.isSame(m4, 'month').should.be.false | ||
m2.isSame(m3, 'month').should.be.false | ||
m2.isSame(m4, 'month').should.be.false | ||
m3.isSame(m4, 'month').should.be.false | ||
m1.isSame(moment('2016-02-04'), 'day').should.be.true | ||
}) | ||
it("should work correctly for same month", function () { | ||
var m1 = moment("2016-02-04"); | ||
var m2 = moment("2016-02-01"); | ||
var m3 = moment("2016-01-01"); | ||
var m4 = moment("2016-03-01"); | ||
m1.isSame(m2, "month").should.be.equal(true); | ||
m1.isSame(m3, "month").should.be.equal(false); | ||
m1.isSame(m4, "month").should.be.equal(false); | ||
m2.isSame(m3, "month").should.be.equal(false); | ||
m2.isSame(m4, "month").should.be.equal(false); | ||
m3.isSame(m4, "month").should.be.equal(false); | ||
m1.isSame(moment("2016-02-04"), "day").should.be.equal(true); | ||
}); | ||
it('should work correctly for same day', function () { | ||
var m1 = moment('2016-02-04 06:00') | ||
var m2 = moment('2016-02-04 07:00') | ||
var m3 = moment('2016-02-03 06:00') | ||
var m4 = moment('2016-02-05 06:00') | ||
m1.isSame(m2, 'day').should.be.true | ||
m1.isSame(m3, 'day').should.be.false | ||
m1.isSame(m4, 'day').should.be.false | ||
m2.isSame(m3, 'day').should.be.false | ||
m2.isSame(m4, 'day').should.be.false | ||
m3.isSame(m4, 'day').should.be.false | ||
}) | ||
it("should work correctly for same day", function () { | ||
var m1 = moment("2016-02-04 06:00"); | ||
var m2 = moment("2016-02-04 07:00"); | ||
var m3 = moment("2016-02-03 06:00"); | ||
var m4 = moment("2016-02-05 06:00"); | ||
m1.isSame(m2, "day").should.be.equal(true); | ||
m1.isSame(m3, "day").should.be.equal(false); | ||
m1.isSame(m4, "day").should.be.equal(false); | ||
m2.isSame(m3, "day").should.be.equal(false); | ||
m2.isSame(m4, "day").should.be.equal(false); | ||
m3.isSame(m4, "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') | ||
m1.isSame(m2, 'jyear').should.be.true | ||
m1.isSame(m3, 'jyear').should.be.false | ||
m1.isSame(m4, 'jyear').should.be.false | ||
m2.isSame(m3, 'jyear').should.be.false | ||
m2.isSame(m4, 'jyear').should.be.false | ||
m3.isSame(m4, 'jyear').should.be.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"); | ||
m1.isSame(m2, "jyear").should.be.equal(true); | ||
m1.isSame(m3, "jyear").should.be.equal(false); | ||
m1.isSame(m4, "jyear").should.be.equal(false); | ||
m2.isSame(m3, "jyear").should.be.equal(false); | ||
m2.isSame(m4, "jyear").should.be.equal(false); | ||
m3.isSame(m4, "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') | ||
m1.isSame(m2, 'jmonth').should.be.true | ||
m1.isSame(m3, 'jmonth').should.be.false | ||
m1.isSame(m4, 'jmonth').should.be.false | ||
m2.isSame(m3, 'jmonth').should.be.false | ||
m2.isSame(m4, 'jmonth').should.be.false | ||
m3.isSame(m4, 'jmonth').should.be.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"); | ||
m1.isSame(m2, "jmonth").should.be.equal(true); | ||
m1.isSame(m3, "jmonth").should.be.equal(false); | ||
m1.isSame(m4, "jmonth").should.be.equal(false); | ||
m2.isSame(m3, "jmonth").should.be.equal(false); | ||
m2.isSame(m4, "jmonth").should.be.equal(false); | ||
m3.isSame(m4, "jmonth").should.be.equal(false); | ||
}); | ||
}); | ||
}); |
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
348106
13
2235
147
9
Updatedmoment@^2.18.1