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

Moment in and require ('node-xlsx') with the use of a problem #2930

Closed
thinkive opened this issue Jan 31, 2016 · 7 comments
Closed

Moment in and require ('node-xlsx') with the use of a problem #2930

thinkive opened this issue Jan 31, 2016 · 7 comments

Comments

@thinkive
Copy link

I use require ('node-xlsx') to read the xlsx file, the file contains the date, and now the problem is:
If xlsx document as a whole there is only a date column, then parsed using moment no problem, if the document inside more than two columns, then all dates are resolved to 1970-01-01 format, I would like to ask is what causes?
For example:
2015/12/1 2015/12/1
Moment (param[0]).Format ('YYYY-MM-DD') parameter param[1] for the acquisition of the cell date
If the entire document is only one column, then no problem
If used again
Moment (param[1]).Format ('YYYY-MM-DD') on the emergence of 1970-01-01 as

@thinkive
Copy link
Author

There is only one date format in the document, then there is no problem to deal with, if more than one column, then all the dates are treated as 1970-01-01

@mattjohnsonpint
Copy link
Contributor

Try console.log(param[1]) and see what the output is.

@mattjohnsonpint
Copy link
Contributor

Also note JavaScript is case sensitive. Please post the real code, with the real example value. Thanks.

@thinkive
Copy link
Author

thinkive commented Feb 3, 2016

code: console.log("~~~~~~~"+param[1]+"~~~~~~~"+moment(param[1]).format('YYYY-MM-DD'))
console.log("!!!!!"+param[2]+"!!!!!!!!"+moment(param[2]).format('YYYY-MM-DD'))

console: server-0 [2016-02-03 15:41:07.729] [INFO] console - ~~~~~~~41459~~~~~~~1970-01-01
server-0 [2016-02-03 15:41:07.731] [INFO] console - !!!!!41462!!!!!!!!1970-01-01

xlsx:
A B C
TKS20120605N017 2013/07/04 2013/07/07
TKS20130320N013 2013/04/07 2013/05/26

fail

if xlsx:
A B
TKS20120605N017 2013/07/04
TKS20130320N013 2013/04/07
correct

@maggiepint
Copy link
Member

Is this still an issue?

@thinkive
Copy link
Author

thinkive commented Apr 8, 2016

Yes, it's still a issue.

@mattjohnsonpint
Copy link
Contributor

Sorry for the delayed response. Missed my inbox somehow.

Since your values (41459, 41462, etc.) look like OLE Automation Dates, you should probably use the MSDate Plugin. This plugin also properly accounts for nuances with how time is represented as decimals.

moment.fromOADate(41459)

Though if you're only ever working with whole dates, it may be reasonable enough to use:

moment('1899-12-30').add(41459, 'days')

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

No branches or pull requests

3 participants