fingerpich / jalali-moment

Display, parse, manipulate, validate and convert jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times.

Home Page:https://fingerpich.github.io/jalali-moment/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jMoment fails when called with an array as input

pouyamn opened this issue · comments

Describe the bug
jMoment fails when called with an array as input

To Reproduce
MJ = new jMoment ([1398,4,6,13,9,8,0])

Expected behavior
create related object like moment itself

Additional context
I have changed the library alot for my propose in another repo, I post here my resolution not sure if it should be merged as is:

function makeMoment(input, format, lang, strict, utc) {
//...
if (isArray(input)) {
            if (input[0] !== latinNumber(input[0])) {
                // pmn: if it uses persian number assume it is persian (problem in this.utc)
                itsJalaliDate = true;
                input = input.map(latinNumber);
            }
            input = input.map(x => parseInt(x, 10));
        }
        if (input && isArray(input) && !format && itsJalaliDate && !moment0.useGregorianParser) {
            input = input[0] + "-" + (input[1] + 1) + "-" + input[2] + " " +
                input[3] + ":" + input [4] + ":" + input[5] + "." + leftZeroFill(input[6], 3);
            if (!format) format = "jYYYY-jM-jD H:m:s.SSS"
        }
//...

Thanks
But there is still a problem
month isn't added correctly
as you can see in the demo

moment([1398,4,6,13,9,8,0]) => 1398,05,06,13,09,08

Yes because as I said before I have changed the code a lot, one of them is that in my fork the months are 0 based. This is the reason that I didn't create PR, but issue. I added the snippet as a suggestion.
Anyway, if this is the only problem, just remove +1 from (input[1] + 1)