Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jalali-moment

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jalali-moment - npm Package Compare versions

Comparing version 0.0.4 to 1.0.1

1213

jalali-moment.js

@@ -5,117 +5,117 @@

var moment = require('moment')
, jalaali = require('jalaali-js')
, jalaali = require('jalaali-js')
/************************************
Constants
************************************/
Constants
************************************/
var formattingTokens = /(\[[^\[]*\])|(\\)?j(Mo|MM?M?M?|Do|DDDo|DD?D?D?|w[o|w]?|YYYYY|YYYY|YY|gg(ggg?)?|)|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g
, localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g
, localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g
, parseTokenOneOrTwoDigits = /\d\d?/
, parseTokenOneToThreeDigits = /\d{1,3}/
, parseTokenThreeDigits = /\d{3}/
, parseTokenFourDigits = /\d{1,4}/
, 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
, parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i
, parseTokenT = /T/i
, parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/
, parseTokenOneOrTwoDigits = /\d\d?/
, parseTokenOneToThreeDigits = /\d{1,3}/
, parseTokenThreeDigits = /\d{3}/
, parseTokenFourDigits = /\d{1,4}/
, 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
, parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i
, parseTokenT = /T/i
, parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/
, unitAliases =
, unitAliases =
{ jm: 'jmonth'
, jmonths: 'jmonth'
, jy: 'jyear'
, jyears: 'jyear'
, jmonths: 'jmonth'
, jy: 'jyear'
, jyears: 'jyear'
}
, formatFunctions = {}
, formatFunctions = {}
, ordinalizeTokens = 'DDD w M D'.split(' ')
, paddedTokens = 'M D w'.split(' ')
, ordinalizeTokens = 'DDD w M D'.split(' ')
, paddedTokens = 'M D w'.split(' ')
, formatTokenFunctions =
, formatTokenFunctions =
{ jM: function () {
return this.jMonth() + 1
}
, jMMM: function (format) {
}
, jMMM: function (format) {
return this.localeData().jMonthsShort(this, format)
}
, jMMMM: function (format) {
}
, jMMMM: function (format) {
return this.localeData().jMonths(this, format)
}
, jD: function () {
}
, jD: function () {
return this.jDate()
}
, jDDD: function () {
}
, jDDD: function () {
return this.jDayOfYear()
}
, jw: function () {
}
, jw: function () {
return this.jWeek()
}
, jYY: function () {
}
, jYY: function () {
return leftZeroFill(this.jYear() % 100, 2)
}
, jYYYY: function () {
}
, jYYYY: function () {
return leftZeroFill(this.jYear(), 4)
}
, jYYYYY: function () {
}
, jYYYYY: function () {
return leftZeroFill(this.jYear(), 5)
}
, jgg: function () {
}
, jgg: function () {
return leftZeroFill(this.jWeekYear() % 100, 2)
}
, jgggg: function () {
}
, jgggg: function () {
return this.jWeekYear()
}
, jggggg: function () {
}
, jggggg: function () {
return leftZeroFill(this.jWeekYear(), 5)
}
}
}
function padToken(func, count) {
return function (a) {
return leftZeroFill(func.call(this, a), count)
}
return function (a) {
return leftZeroFill(func.call(this, a), count)
}
}
function ordinalizeToken(func, period) {
return function (a) {
return this.localeData().ordinal(func.call(this, a), period)
}
return function (a) {
return this.localeData().ordinal(func.call(this, a), period)
}
}
(function () {
var i
while (ordinalizeTokens.length) {
i = ordinalizeTokens.pop()
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.jDDDD = padToken(formatTokenFunctions.jDDD, 3)
var i
while (ordinalizeTokens.length) {
i = ordinalizeTokens.pop()
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.jDDDD = padToken(formatTokenFunctions.jDDD, 3)
}())
/************************************
Helpers
************************************/
Helpers
************************************/
function extend(a, b) {
var key
for (key in b)
if (b.hasOwnProperty(key))
a[key] = b[key]
return a
var key
for (key in b)
if (b.hasOwnProperty(key))
a[key] = b[key]
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]'
}

@@ -135,406 +135,406 @@

function normalizeUnits(units) {
if (units) {
var lowered = units.toLowerCase()
units = unitAliases[lowered] || lowered
}
return units
if (units) {
var lowered = units.toLowerCase()
units = unitAliases[lowered] || lowered
}
return units
}
function setDate(m, year, month, date) {
var d = m._d
if (m._isUTC) {
/*eslint-disable new-cap*/
m._d = new Date(Date.UTC(year, month, date,
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()))
/*eslint-enable new-cap*/
} else {
m._d = new Date(year, month, date,
d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds())
}
var d = m._d
if (m._isUTC) {
/*eslint-disable new-cap*/
m._d = new Date(Date.UTC(year, month, date,
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()))
/*eslint-enable new-cap*/
} else {
m._d = new Date(year, month, date,
d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds())
}
}
function objectCreate(parent) {
function F() {}
F.prototype = parent
return new F()
function F() {}
F.prototype = parent
return new F()
}
function getPrototypeOf(object) {
if (Object.getPrototypeOf)
return Object.getPrototypeOf(object)
else if (''.__proto__)
return object.__proto__
else
return object.constructor.prototype
if (Object.getPrototypeOf)
return Object.getPrototypeOf(object)
else if (''.__proto__)
return object.__proto__
else
return object.constructor.prototype
}
/************************************
Languages
************************************/
Languages
************************************/
extend(getPrototypeOf(moment.localeData()),
{ _jMonths: [ 'Farvardin'
, 'Ordibehesht'
, 'Khordaad'
, 'Tir'
, 'Amordaad'
, 'Shahrivar'
, 'Mehr'
, 'Aabaan'
, 'Aazar'
, 'Dey'
, 'Bahman'
, 'Esfand'
]
, jMonths: function (m) {
return this._jMonths[m.jMonth()]
{ _jMonths: [ 'Farvardin'
, 'Ordibehesht'
, 'Khordaad'
, 'Tir'
, 'Amordaad'
, 'Shahrivar'
, 'Mehr'
, 'Aabaan'
, 'Aazar'
, 'Dey'
, 'Bahman'
, 'Esfand'
]
, jMonths: function (m) {
return this._jMonths[m.jMonth()]
}
, _jMonthsShort: [ 'Far'
, 'Ord'
, 'Kho'
, 'Tir'
, 'Amo'
, 'Sha'
, 'Meh'
, 'Aab'
, 'Aaz'
, 'Dey'
, 'Bah'
, 'Esf'
]
, jMonthsShort: function (m) {
return this._jMonthsShort[m.jMonth()]
, _jMonthsShort: [ 'Far'
, 'Ord'
, 'Kho'
, 'Tir'
, 'Amo'
, 'Sha'
, 'Meh'
, 'Aab'
, 'Aaz'
, 'Dey'
, 'Bah'
, 'Esf'
]
, jMonthsShort: function (m) {
return this._jMonthsShort[m.jMonth()]
}
, jMonthsParse: function (monthName) {
var i
, mom
, regex
if (!this._jMonthsParse)
this._jMonthsParse = []
for (i = 0; i < 12; i += 1) {
// 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')
, jMonthsParse: function (monthName) {
var i
, mom
, regex
if (!this._jMonthsParse)
this._jMonthsParse = []
for (i = 0; i < 12; i += 1) {
// 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')
}
// Test the regex.
if (this._jMonthsParse[i].test(monthName))
return i
}
// Test the regex.
if (this._jMonthsParse[i].test(monthName))
return i
}
}
}
}
)
/************************************
Formatting
************************************/
Formatting
************************************/
function makeFormatFunction(format) {
var array = format.match(formattingTokens)
, length = array.length
, i
var array = format.match(formattingTokens)
, length = array.length
, i
for (i = 0; i < length; i += 1)
if (formatTokenFunctions[array[i]])
array[i] = 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
}
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
}
}
/************************************
Parsing
************************************/
Parsing
************************************/
function getParseRegexForToken(token, config) {
switch (token) {
case 'jDDDD':
return parseTokenThreeDigits
case 'jYYYY':
return parseTokenFourDigits
case 'jYYYYY':
return parseTokenSixDigits
case 'jDDD':
return parseTokenOneToThreeDigits
case 'jMMM':
case 'jMMMM':
return parseTokenWord
case 'jMM':
case 'jDD':
case 'jYY':
case 'jM':
case 'jD':
return parseTokenOneOrTwoDigits
case 'DDDD':
return parseTokenThreeDigits
case 'YYYY':
return parseTokenFourDigits
case 'YYYYY':
return parseTokenSixDigits
case 'S':
case 'SS':
case 'SSS':
case 'DDD':
return parseTokenOneToThreeDigits
case 'MMM':
case 'MMMM':
case 'dd':
case 'ddd':
case 'dddd':
return parseTokenWord
case 'a':
case 'A':
return moment.localeData(config._l)._meridiemParse
case 'X':
return parseTokenTimestampMs
case 'Z':
case 'ZZ':
return parseTokenTimezone
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':
return parseTokenOneOrTwoDigits
default:
return new RegExp(token.replace('\\', ''))
}
switch (token) {
case 'jDDDD':
return parseTokenThreeDigits
case 'jYYYY':
return parseTokenFourDigits
case 'jYYYYY':
return parseTokenSixDigits
case 'jDDD':
return parseTokenOneToThreeDigits
case 'jMMM':
case 'jMMMM':
return parseTokenWord
case 'jMM':
case 'jDD':
case 'jYY':
case 'jM':
case 'jD':
return parseTokenOneOrTwoDigits
case 'DDDD':
return parseTokenThreeDigits
case 'YYYY':
return parseTokenFourDigits
case 'YYYYY':
return parseTokenSixDigits
case 'S':
case 'SS':
case 'SSS':
case 'DDD':
return parseTokenOneToThreeDigits
case 'MMM':
case 'MMMM':
case 'dd':
case 'ddd':
case 'dddd':
return parseTokenWord
case 'a':
case 'A':
return moment.localeData(config._l)._meridiemParse
case 'X':
return parseTokenTimestampMs
case 'Z':
case 'ZZ':
return parseTokenTimezone
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':
return parseTokenOneOrTwoDigits
default:
return new RegExp(token.replace('\\', ''))
}
}
function addTimeToArrayFromToken(token, input, config) {
var a
, datePartArray = config._a
var a
, datePartArray = config._a
switch (token) {
case 'jM':
case 'jMM':
datePartArray[1] = input == null ? 0 : ~~input - 1
break
case 'jMMM':
case 'jMMMM':
a = moment.localeData(config._l).jMonthsParse(input)
if (a != null)
datePartArray[1] = a
else
config._isValid = false
break
case 'jD':
case 'jDD':
case 'jDDD':
case 'jDDDD':
if (input != null)
datePartArray[2] = ~~input
break
case 'jYY':
datePartArray[0] = ~~input + (~~input > 47 ? 1300 : 1400)
break
case 'jYYYY':
case 'jYYYYY':
datePartArray[0] = ~~input
}
if (input == null)
config._isValid = false
switch (token) {
case 'jM':
case 'jMM':
datePartArray[1] = input == null ? 0 : ~~input - 1
break
case 'jMMM':
case 'jMMMM':
a = moment.localeData(config._l).jMonthsParse(input)
if (a != null)
datePartArray[1] = a
else
config._isValid = false
break
case 'jD':
case 'jDD':
case 'jDDD':
case 'jDDDD':
if (input != null)
datePartArray[2] = ~~input
break
case 'jYY':
datePartArray[0] = ~~input + (~~input > 47 ? 1300 : 1400)
break
case 'jYYYY':
case 'jYYYYY':
datePartArray[0] = ~~input
}
if (input == null)
config._isValid = false
}
function dateFromArray(config) {
var g
, j
, jy = config._a[0]
, jm = config._a[1]
, jd = config._a[2]
var g
, j
, jy = config._a[0]
, jm = config._a[1]
, jd = config._a[2]
if ((jy == null) && (jm == null) && (jd == null))
return [0, 0, 1]
jy = jy != null ? jy : 0
jm = jm != null ? jm : 0
jd = jd != null ? jd : 1
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)
config._jDiff += 1
if (~~j.jm !== jm)
config._jDiff += 1
if (~~j.jd !== jd)
config._jDiff += 1
return [g.gy, g.gm, g.gd]
if ((jy == null) && (jm == null) && (jd == null))
return [0, 0, 1]
jy = jy != null ? jy : 0
jm = jm != null ? jm : 0
jd = jd != null ? jd : 1
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)
config._jDiff += 1
if (~~j.jm !== jm)
config._jDiff += 1
if (~~j.jd !== jd)
config._jDiff += 1
return [g.gy, g.gm, g.gd]
}
function makeDateFromStringAndFormat(config) {
var tokens = config._f.match(formattingTokens)
, string = config._i + ''
, len = tokens.length
, i
, token
, parsedInput
var tokens = config._f.match(formattingTokens)
, string = config._i + ''
, len = tokens.length
, i
, token
, parsedInput
config._a = []
config._a = []
for (i = 0; i < len; i += 1) {
token = tokens[i]
parsedInput = (getParseRegexForToken(token, config).exec(string) || [])[0]
if (parsedInput)
string = string.slice(string.indexOf(parsedInput) + parsedInput.length)
if (formatTokenFunctions[token])
addTimeToArrayFromToken(token, parsedInput, config)
}
if (string)
config._il = string
return dateFromArray(config)
for (i = 0; i < len; i += 1) {
token = tokens[i]
parsedInput = (getParseRegexForToken(token, config).exec(string) || [])[0]
if (parsedInput)
string = string.slice(string.indexOf(parsedInput) + parsedInput.length)
if (formatTokenFunctions[token])
addTimeToArrayFromToken(token, parsedInput, config)
}
if (string)
config._il = string
return dateFromArray(config)
}
function makeDateFromStringAndArray(config, utc) {
var len = config._f.length
, i
, format
, tempMoment
, bestMoment
, currentScore
, scoreToBeat
var len = config._f.length
, i
, format
, tempMoment
, bestMoment
, currentScore
, scoreToBeat
if (len === 0) {
return makeMoment(new Date(NaN))
}
if (len === 0) {
return makeMoment(new Date(NaN))
}
for (i = 0; i < len; i += 1) {
format = config._f[i]
currentScore = 0
tempMoment = makeMoment(config._i, format, config._l, config._strict, utc)
for (i = 0; i < len; i += 1) {
format = config._f[i]
currentScore = 0
tempMoment = makeMoment(config._i, format, config._l, config._strict, utc)
if (!tempMoment.isValid()) continue
if (!tempMoment.isValid()) continue
// currentScore = compareArrays(tempMoment._a, tempMoment.toArray())
currentScore += tempMoment._jDiff
if (tempMoment._il)
currentScore += tempMoment._il.length
if (scoreToBeat == null || currentScore < scoreToBeat) {
scoreToBeat = currentScore
bestMoment = tempMoment
// currentScore = compareArrays(tempMoment._a, tempMoment.toArray())
currentScore += tempMoment._jDiff
if (tempMoment._il)
currentScore += tempMoment._il.length
if (scoreToBeat == null || currentScore < scoreToBeat) {
scoreToBeat = currentScore
bestMoment = tempMoment
}
}
}
return bestMoment
return bestMoment
}
function removeParsedTokens(config) {
var string = config._i + ''
, input = ''
, format = ''
, array = config._f.match(formattingTokens)
, len = array.length
, i
, match
, parsed
var string = config._i + ''
, input = ''
, format = ''
, array = config._f.match(formattingTokens)
, len = array.length
, i
, match
, parsed
for (i = 0; i < len; i += 1) {
match = array[i]
parsed = (getParseRegexForToken(match, config).exec(string) || [])[0]
if (parsed)
string = string.slice(string.indexOf(parsed) + parsed.length)
if (!(formatTokenFunctions[match] instanceof Function)) {
format += match
if (parsed)
input += parsed
for (i = 0; i < len; i += 1) {
match = array[i]
parsed = (getParseRegexForToken(match, config).exec(string) || [])[0]
if (parsed)
string = string.slice(string.indexOf(parsed) + parsed.length)
if (!(formatTokenFunctions[match] instanceof Function)) {
format += match
if (parsed)
input += parsed
}
}
}
config._i = input
config._f = format
config._i = input
config._f = format
}
/************************************
Week of Year
************************************/
Week of Year
************************************/
function jWeekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
var end = firstDayOfWeekOfYear - firstDayOfWeek
, daysToDayOfWeek = firstDayOfWeekOfYear - mom.day()
, adjustedMoment
var end = firstDayOfWeekOfYear - firstDayOfWeek
, daysToDayOfWeek = firstDayOfWeekOfYear - mom.day()
, adjustedMoment
if (daysToDayOfWeek > end) {
daysToDayOfWeek -= 7
}
if (daysToDayOfWeek < end - 7) {
daysToDayOfWeek += 7
}
adjustedMoment = jMoment(mom).add(daysToDayOfWeek, 'd')
return { week: Math.ceil(adjustedMoment.jDayOfYear() / 7)
, year: adjustedMoment.jYear()
}
if (daysToDayOfWeek > end) {
daysToDayOfWeek -= 7
}
if (daysToDayOfWeek < end - 7) {
daysToDayOfWeek += 7
}
adjustedMoment = jMoment(mom).add(daysToDayOfWeek, 'd')
return { week: Math.ceil(adjustedMoment.jDayOfYear() / 7)
, year: adjustedMoment.jYear()
}
}
/************************************
Top Level Functions
************************************/
Top Level Functions
************************************/
function makeMoment(input, format, lang, strict, utc) {
if (typeof lang === 'boolean') {
utc = strict
strict = lang
lang = undefined
}
if (typeof lang === 'boolean') {
utc = strict
strict = lang
lang = undefined
}
if (format && typeof format === 'string')
format = fixFormat(format, moment)
if (format && typeof format === 'string')
format = fixFormat(format, moment)
var config =
{ _i: input
, _f: format
, _l: lang
, _strict: strict
, _isUTC: utc
}
, date
, m
, jm
, origInput = input
, origFormat = format
if (format) {
if (isArray(format)) {
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
var config =
{ _i: input
, _f: format
, _l: lang
, _strict: strict
, _isUTC: utc
}
, date
, m
, jm
, origInput = input
, origFormat = format
if (format) {
if (isArray(format)) {
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
}
}
}
if (utc)
m = moment.utc(input, format, lang, strict)
else
m = moment(input, format, lang, strict)
if (config._isValid === false)
m._isValid = false
m._jDiff = config._jDiff || 0
jm = objectCreate(jMoment.fn)
extend(jm, m)
if (strict && jm.isValid()) {
jm._isValid = jm.format(origFormat) === origInput
}
return jm
if (utc)
m = moment.utc(input, format, lang, strict)
else
m = moment(input, format, lang, strict)
if (config._isValid === false)
m._isValid = false
m._jDiff = config._jDiff || 0
jm = objectCreate(jMoment.fn)
extend(jm, m)
if (strict && jm.isValid()) {
jm._isValid = jm.format(origFormat) === origInput
}
return jm
}
function jMoment(input, format, lang, strict) {
return makeMoment(input, format, lang, strict, false)
return makeMoment(input, format, lang, strict, false)
}

@@ -546,23 +546,23 @@

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)
}
/************************************
jMoment Prototype
************************************/
jMoment Prototype
************************************/
function fixFormat(format, _moment) {
var i = 5
var replace = function (input) {
return _moment.localeData().longDateFormat(input) || input
}
while (i > 0 && localFormattingTokens.test(format)) {
i -= 1
format = format.replace(localFormattingTokens, replace)
}
return format
var i = 5
var replace = function (input) {
return _moment.localeData().longDateFormat(input) || input
}
while (i > 0 && localFormattingTokens.test(format)) {
i -= 1
format = format.replace(localFormattingTokens, replace)
}
return format
}

@@ -572,156 +572,156 @@

if (format) {
format = fixFormat(format, this)
if (format) {
format = fixFormat(format, this)
if (!formatFunctions[format]) {
formatFunctions[format] = makeFormatFunction(format)
if (!formatFunctions[format]) {
formatFunctions[format] = makeFormatFunction(format)
}
format = formatFunctions[format](this)
}
format = formatFunctions[format](this)
}
return moment.fn.format.call(this, format)
return moment.fn.format.call(this, format)
}
jMoment.fn.jYear = function (input) {
var lastDay
, j
, g
if (typeof input === 'number') {
j = toJalaali(this.year(), this.month(), this.date())
lastDay = Math.min(j.jd, jMoment.jDaysInMonth(input, j.jm))
g = toGregorian(input, j.jm, lastDay)
setDate(this, g.gy, g.gm, g.gd)
moment.updateOffset(this)
return this
} else {
return toJalaali(this.year(), this.month(), this.date()).jy
}
var lastDay
, j
, g
if (typeof input === 'number') {
j = toJalaali(this.year(), this.month(), this.date())
lastDay = Math.min(j.jd, jMoment.jDaysInMonth(input, j.jm))
g = toGregorian(input, j.jm, lastDay)
setDate(this, g.gy, g.gm, g.gd)
moment.updateOffset(this)
return this
} else {
return toJalaali(this.year(), this.month(), this.date()).jy
}
}
jMoment.fn.jMonth = function (input) {
var lastDay
, j
, g
if (input != null) {
if (typeof input === 'string') {
input = this.lang().jMonthsParse(input)
if (typeof input !== 'number')
var lastDay
, j
, g
if (input != null) {
if (typeof input === 'string') {
input = this.lang().jMonthsParse(input)
if (typeof input !== 'number')
return this
}
j = toJalaali(this.year(), this.month(), this.date())
lastDay = Math.min(j.jd, jMoment.jDaysInMonth(j.jy, input))
this.jYear(j.jy + div(input, 12))
input = mod(input, 12)
if (input < 0) {
input += 12
this.jYear(this.jYear() - 1)
}
g = toGregorian(this.jYear(), input, lastDay)
setDate(this, g.gy, g.gm, g.gd)
moment.updateOffset(this)
return this
} else {
return toJalaali(this.year(), this.month(), this.date()).jm
}
j = toJalaali(this.year(), this.month(), this.date())
lastDay = Math.min(j.jd, jMoment.jDaysInMonth(j.jy, input))
this.jYear(j.jy + div(input, 12))
input = mod(input, 12)
if (input < 0) {
input += 12
this.jYear(this.jYear() - 1)
}
g = toGregorian(this.jYear(), input, lastDay)
setDate(this, g.gy, g.gm, g.gd)
moment.updateOffset(this)
return this
} else {
return toJalaali(this.year(), this.month(), this.date()).jm
}
}
jMoment.fn.jDate = function (input) {
var j
, g
if (typeof input === 'number') {
j = toJalaali(this.year(), this.month(), this.date())
g = toGregorian(j.jy, j.jm, input)
setDate(this, g.gy, g.gm, g.gd)
moment.updateOffset(this)
return this
} else {
return toJalaali(this.year(), this.month(), this.date()).jd
}
var j
, g
if (typeof input === 'number') {
j = toJalaali(this.year(), this.month(), this.date())
g = toGregorian(j.jy, j.jm, input)
setDate(this, g.gy, g.gm, g.gd)
moment.updateOffset(this)
return this
} else {
return toJalaali(this.year(), this.month(), this.date()).jd
}
}
jMoment.fn.jDayOfYear = function (input) {
var dayOfYear = Math.round((jMoment(this).startOf('day') - jMoment(this).startOf('jYear')) / 864e5) + 1
return input == null ? dayOfYear : this.add(input - dayOfYear, 'd')
var dayOfYear = Math.round((jMoment(this).startOf('day') - jMoment(this).startOf('jYear')) / 864e5) + 1
return input == null ? dayOfYear : this.add(input - dayOfYear, 'd')
}
jMoment.fn.jWeek = function (input) {
var week = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).week
return input == null ? week : this.add((input - week) * 7, 'd')
var week = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).week
return input == null ? week : this.add((input - week) * 7, 'd')
}
jMoment.fn.jWeekYear = function (input) {
var year = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year
return input == null ? year : this.add(input - year, 'y')
var year = jWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year
return input == null ? year : this.add(input - year, 'y')
}
jMoment.fn.add = function (val, units) {
var temp
if (units !== null && !isNaN(+units)) {
temp = val
val = units
units = temp
}
units = normalizeUnits(units)
if (units === 'jyear') {
this.jYear(this.jYear() + val)
} else if (units === 'jmonth') {
this.jMonth(this.jMonth() + val)
} else {
moment.fn.add.call(this, val, units)
}
return this
var temp
if (units !== null && !isNaN(+units)) {
temp = val
val = units
units = temp
}
units = normalizeUnits(units)
if (units === 'jyear') {
this.jYear(this.jYear() + val)
} else if (units === 'jmonth') {
this.jMonth(this.jMonth() + val)
} else {
moment.fn.add.call(this, val, units)
}
return this
}
jMoment.fn.subtract = function (val, units) {
var temp
if (units !== null && !isNaN(+units)) {
temp = val
val = units
units = temp
}
units = normalizeUnits(units)
if (units === 'jyear') {
this.jYear(this.jYear() - val)
} else if (units === 'jmonth') {
this.jMonth(this.jMonth() - val)
} else {
moment.fn.subtract.call(this, val, units)
}
return this
var temp
if (units !== null && !isNaN(+units)) {
temp = val
val = units
units = temp
}
units = normalizeUnits(units)
if (units === 'jyear') {
this.jYear(this.jYear() - val)
} else if (units === 'jmonth') {
this.jMonth(this.jMonth() - val)
} else {
moment.fn.subtract.call(this, val, units)
}
return this
}
jMoment.fn.startOf = function (units) {
units = normalizeUnits(units)
if (units === 'jyear' || units === 'jmonth') {
if (units === 'jyear') {
this.jMonth(0)
units = normalizeUnits(units)
if (units === 'jyear' || units === 'jmonth') {
if (units === 'jyear') {
this.jMonth(0)
}
this.jDate(1)
this.hours(0)
this.minutes(0)
this.seconds(0)
this.milliseconds(0)
return this
} else {
return moment.fn.startOf.call(this, units)
}
this.jDate(1)
this.hours(0)
this.minutes(0)
this.seconds(0)
this.milliseconds(0)
return this
} else {
return moment.fn.startOf.call(this, units)
}
}
jMoment.fn.endOf = function (units) {
units = normalizeUnits(units)
if (units === undefined || units === 'milisecond') {
return this
}
return this.startOf(units).add(1, (units === 'isoweek' ? 'week' : units)).subtract(1, 'ms')
units = normalizeUnits(units)
if (units === undefined || units === 'milisecond') {
return this
}
return this.startOf(units).add(1, (units === 'isoweek' ? 'week' : units)).subtract(1, 'ms')
}
jMoment.fn.isSame = function (other, units) {
units = normalizeUnits(units)
if (units === 'jyear' || units === 'jmonth') {
return moment.fn.isSame.call(this.clone().startOf(units), other.clone().startOf(units))
}
return moment.fn.isSame.call(this, other, units)
units = normalizeUnits(units)
if (units === 'jyear' || units === 'jmonth') {
return moment.fn.isSame.call(this.clone().startOf(units), other.clone().startOf(units))
}
return moment.fn.isSame.call(this, other, units)
}
jMoment.fn.clone = function () {
return jMoment(this)
return jMoment(this)
}

@@ -735,21 +735,21 @@

/************************************
jMoment Statics
************************************/
jMoment Statics
************************************/
jMoment.jDaysInMonth = function (year, month) {
year += div(month, 12)
month = mod(month, 12)
if (month < 0) {
month += 12
year -= 1
}
if (month < 6) {
return 31
} else if (month < 11) {
return 30
} else if (jMoment.jIsLeapYear(year)) {
return 30
} else {
return 29
}
year += div(month, 12)
month = mod(month, 12)
if (month < 0) {
month += 12
year -= 1
}
if (month < 6) {
return 31
} else if (month < 11) {
return 30
} else if (jMoment.jIsLeapYear(year)) {
return 30
} else {
return 29
}
}

@@ -760,83 +760,82 @@

jMoment.loadPersian = function () {
moment.locale('fa', null)
moment.defineLocale('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'
}
, calendar:
{ 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 سال'
}
, ordinal: '%dم'
, week:
{ dow: 6 // Saturday is the first day of the week.
, doy: 12 // The week that contains Jan 1st is the first week of the year.
}
, meridiem: function (hour) {
return hour < 12 ? 'ق.ظ' : 'ب.ظ'
}
, jMonths: ('فروردین_اردیبهشت_خرداد_تیر_امرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند').split('_')
, jMonthsShort: 'فرو_ارد_خرد_تیر_امر_شهر_مهر_آبا_آذر_دی_بهم_اسف'.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'
}
, calendar:
{ 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 سال'
}
, ordinal: '%dم'
, week:
{ dow: 6 // Saturday is the first day of the week.
, doy: 12 // The week that contains Jan 1st is the first week of the year.
}
, meridiem: function (hour) {
return hour < 12 ? 'ق.ظ' : 'ب.ظ'
}
, jMonths: ('فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند').split('_')
, jMonthsShort: 'فرو_ارد_خرد_تیر_مرد_شهر_مهر_آبا_آذر_دی_بهم_اسف'.split('_')
}
);
}
jMoment.jConvert = { toJalaali: toJalaali
, toGregorian: toGregorian
}
, toGregorian: toGregorian
}
/************************************
Jalaali Conversion
************************************/
Jalaali Conversion
************************************/
function toJalaali(gy, gm, gd) {
var j = jalaali.toJalaali(gy, gm + 1, gd)
j.jm -= 1
return j
var j = jalaali.toJalaali(gy, gm + 1, gd)
j.jm -= 1
return j
}
function toGregorian(jy, jm, jd) {
var g = jalaali.toGregorian(jy, jm + 1, jd)
g.gm -= 1
return g
var g = jalaali.toGregorian(jy, jm + 1, jd)
g.gm -= 1
return g
}
/*
Utility helper functions.
*/
Utility helper functions.
*/
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": "0.0.4",
"version": "1.0.1",
"description": "Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.",

@@ -5,0 +5,0 @@ "author": {

@@ -5,5 +5,7 @@ # jalali-moment

[![Build Status](https://travis-ci.org/fingerpich/jalali-moment.png?branch=master)](https://travis-ci.org/fingerpich/jalali-moment)
[![NPM version][npm-version-image]][npm-url]
[![MIT License][license-image]][license-url]
[![Build Status][travis-image]][travis-url]
Jalali calendar is a solar calendar that was used in Persia, variants of which today are still in use in Iran as well as Afghanistan. [Read more on Wikipedia](http://en.wikipedia.org/wiki/Jalali_calendar) or see [Calendar Converter](http://www.fourmilab.ch/documents/calendar/).
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) or see [Calendar Converter](http://www.fourmilab.ch/documents/calendar/).

@@ -21,2 +23,3 @@ This plugin adds Jalali calendar support to [momentjs](http://momentjs.com) library.

Install via NPM
```shell

@@ -56,2 +59,8 @@ npm install jalali-moment -S

### Typescript
```ts
import * as moment from 'jalali-moment';
let todayJalali = moment().format('jYYYY/jM/jD');
```
## API

@@ -115,14 +124,16 @@

A lightweight angular.js date picker using `jalali-moment` is [thg303/ng-jalali-flat-datepicker](https://github.com/thg303/ng-jalali-flat-datepicker) created by [@thg303](https://github.com/thg303).
A highly configurable date picker built for Angular 2 applications using `jalali-moment` is [fingerpich/jalali-angular-datepicker](https://github.com/fingerpich/jalali-angular-datepicker) created by [@Fingerpich](https://github.com/fingerpich).
This project needs a plugin on moment.js to have Jalali date so I had been using [moment-hijri](https://github.com/jalaali/moment-jalaali) but it had some problem so I forked it.
### pholiday
## License
A library based on `jalali-moment` for calculating holidays in Persian calendar is [shkarimpour/pholiday](https://github.com/shkarimpour/pholiday) created by [@shkarimpour](https://github.com/shkarimpour).
MIT
### moment-hijri
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE
Another calendar system plugin for `momentjs` is [moment-hijri](https://github.com/xsoh/moment-hijri) created by [@xsoh](https://github.com/xsoh).
[npm-url]: https://npmjs.org/package/jalali-moment
[npm-version-image]: http://img.shields.io/npm/v/jalali-moment.svg?style=flat
## License
MIT
[travis-url]: https://travis-ci.org/fingerpich/jalali-moment
[travis-image]: https://travis-ci.org/fingerpich/jalali-moment.png?branch=master
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc