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

Question: My timestamp is getting truncated to year month day, How can I fix this? #61

Closed
Matt-st opened this issue May 13, 2019 · 1 comment
Labels
ready to close Issue reporter will close when satisfied

Comments

@Matt-st
Copy link

Matt-st commented May 13, 2019

Hey folks, I am using jsonexport to convert to csv. My timestamp field which comes from a database query is being truncated when I convert to csv. I expect it to stay the same.

What I expect? ( and see when this is printed in json)
"last_modified_date":"2018-10-26T19:17:01.447Z"
What I get?
"last_modified_date":"2018-10-26"

My code is very simple.
jsonexport(output.rows,{rowDelimiter: '|', includeHeaders: false}

I saw that there are handleDate type handler is deprecated. Can someone share some example code of how I can go about solving this?

@kaue
Copy link
Owner

kaue commented May 23, 2020

@Matt-st sorry for the delay, since a Date is an Object you should do something like this:

      jsonexport({
        a: new Date(),
        b: true
      }, {
        typeHandlers: {
          Object: (value, name) => {
            if (value instanceof Date) return value.toLocaleString();
            return value;
          }
        }
      }, (err, csv) => {
        console.log(csv);
      });

@kaue kaue added the ready to close Issue reporter will close when satisfied label May 23, 2020
@kaue kaue closed this as completed May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to close Issue reporter will close when satisfied
Projects
None yet
Development

No branches or pull requests

2 participants