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

Dates are output as strings in ISO format #229

Closed
arion-p opened this issue Mar 31, 2023 · 3 comments · Fixed by #236
Closed

Dates are output as strings in ISO format #229

arion-p opened this issue Mar 31, 2023 · 3 comments · Fixed by #236
Assignees
Labels
accepted It is accepted to do BUG Something isn't working important Do it first

Comments

@arion-p
Copy link

arion-p commented Mar 31, 2023

It is impossible to output any Date data to Excel. exceljs expects date data to be Javascript Date object to output them properly so that Excel can handle them. However, after fixing #137 all dates are passed to exceljs as strings (in ISO format). The reason is that JSON.parse(JSON.stringify(vm)) doesn't make an exact deep copy. JSON.stringify(vm) turns dates in ISO formatted strings but JSON.parse(....) does not turn them back to Date objects. It rather leaves them as strings.

We either need the proxy solution or a proper deep copy.

@Siemienik
Copy link
Owner

Thank you for open this issue, I will look on it soon.

@Siemienik Siemienik self-assigned this Apr 10, 2023
@Siemienik Siemienik added BUG Something isn't working accepted It is accepted to do labels Apr 10, 2023
@arion-p
Copy link
Author

arion-p commented Apr 12, 2023

A reviver function could be used in JSON.parse to turn ISO date strings back to Dates but it is hard to identify which ones are really dates and which are strings. Creating a map of Date properties in the source before JSON.stringify might help but I'm not sure how it could be used from the reviver function (it only gets a key which is local to the object being parsed). Another option would be to also use a replacer function in JSON.stringify to turn Dates to composite objects with some discriminator property that the reviver can identify.

@Siemienik
Copy link
Owner

Siemienik commented Apr 14, 2023

Great ideas, I will definitely check them out. So far, I was considering another cloning function, the one using JSON is primitive, which your example demonstrates perfectly. By the way, contributions to this project are very welcome, so feel free to submit a PR 😃

I'm planning to tackle this issue soon. Currently, along with several contributors from exceljs, we are trying to clear the PR list (currently at 70 PRs 🙈 ). We coordinate on Discord: https://discord.gg/BqTQGHDKw8. I mention this because this project is based on exceljs, so working there brings double benefits :D

@Siemienik Siemienik added the important Do it first label Nov 11, 2023
Siemienik added a commit that referenced this issue Nov 20, 2023
* Using Proxy to prevent against modification the original view model.

Fixes #137
Fixes #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted It is accepted to do BUG Something isn't working important Do it first
Projects
Status: To Release
Development

Successfully merging a pull request may close this issue.

2 participants