Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jMoment fails when called with an array as input #69

Open
pouyamn opened this issue Jul 1, 2019 · 2 comments
Open

jMoment fails when called with an array as input #69

pouyamn opened this issue Jul 1, 2019 · 2 comments

Comments

@pouyamn
Copy link
Contributor

pouyamn commented Jul 1, 2019

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"
        }
//...
@fingerpich
Copy link
Owner

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

@pouyamn
Copy link
Contributor Author

pouyamn commented Aug 21, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants