jalali-moment
Advanced tools
Comparing version 3.2.5 to 3.2.6
@@ -123,2 +123,3 @@ declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment; | ||
interface LocaleSpecification { | ||
useGregorianParser?: boolean; | ||
months?: string[] | StandaloneFormatSpec | MonthWeekdayFn; | ||
@@ -125,0 +126,0 @@ monthsShort?: string[] | StandaloneFormatSpec | MonthWeekdayFn; |
@@ -576,3 +576,3 @@ | ||
var itsJalaliDate = (isJalali(this)); | ||
if(input && (typeof input === "string") && !format && itsJalaliDate) { | ||
if(input && (typeof input === "string") && !format && itsJalaliDate && !moment.useGregorianParser) { | ||
input = input.replace(/\//g,"-"); | ||
@@ -966,6 +966,6 @@ if(/\d{4}\-\d{2}\-\d{2}/.test(input)) { | ||
************************************/ | ||
jMoment.locale = function(locale) { | ||
jMoment.locale = function(locale, options) { | ||
if (locale && moment.changeCalendarSystemByItsLocale) { | ||
if (locale === "fa") { | ||
this.useJalaliSystemPrimarily(); | ||
this.useJalaliSystemPrimarily(options); | ||
} else { | ||
@@ -994,4 +994,9 @@ this.useJalaliSystemSecondary(); | ||
jMoment.useJalaliSystemPrimarily = function () { | ||
jMoment.useJalaliSystemPrimarily = function (options) { | ||
moment.justUseJalali = true; | ||
useGregorianParser = false; | ||
if (options) { | ||
useGregorianParser = options.useGregorianParser; | ||
} | ||
moment.useGregorianParser = useGregorianParser; | ||
}; | ||
@@ -998,0 +1003,0 @@ jMoment.useJalaliSystemSecondary = function () { |
{ | ||
"name": "jalali-moment", | ||
"version": "3.2.5", | ||
"version": "3.2.6", | ||
"description": "Manipulate and convert Jalali and Gregorian date easily", | ||
@@ -5,0 +5,0 @@ "author": { |
11
test.js
@@ -1129,2 +1129,13 @@ | ||
}); | ||
describe("use gregorian calendar parser in 'fa' locale", function () { | ||
it("use jalali calendar when useGregorianParser is false in fa locale", function () { | ||
moment.locale("fa", { useGregorianParser: false }); | ||
moment("1370-10-17").format("YYYY-MM-DD").should.be.equal("1370-10-17"); | ||
}); | ||
it("parse using gregorian calendar in fa locale", function () { | ||
moment.locale("fa", { useGregorianParser: true }); | ||
moment("2019-01-17T08:19:19.975Z").format("YYYY-MM-DD").should.be.equal("1397-10-27"); | ||
moment("2019-02-23").format("YYYY-MM-DD").should.be.equal("1397-12-04"); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1272442
4027