chartjs/chartjs-adapter-luxon

Parser Error for Luxon Objects

saintflow47 opened this issue · 6 comments

Versions:

  • Chart.js: 2.9.3
  • Chart.js adapter luxon: 0.2.0
  • Luxon: 1.22.0

When I try to use Luxon DateTime Objects in my Datasets Data, the chartjs-adapter-luxon parser has an error on line 57 when it tries to parse the incoming DateTime object. I do not know if I missed something on how to use this adapter, but as soon as I just remove line 57 for testing purposes, the DateTime objects work.

Should the parser not be invoked if the datasets already have DateTime Objects as dates? Or does the parser get invoked in any case and should be altered to just return an already working Luxon Object? Sorry if I missed something. Thank you!

Typically it's expected that the data would be passed in as timestamps. E.g. if you fetch data from the server, the server can fetch JSON containing numbers, but not Luxon DateTime objects. Would that work for you or is there a use case where it makes more sense to have already parsed DateTime objects?

To harness the full power of luxon, I decided to parse data from the server as early as possible so I can work with luxon objects in all parts of my frontend. Of course I could start making exceptions, but in this case, I would love not to!

I would second this for a similar reason, being able to pre-process data as Luxon objects would be ideal. The fix should be as simple as changing line 47 in index.js from:

} else if (type === 'object') {

to:

} else if (type === 'object' && !value.isLuxonDateTime) {

isLuxonDateTime looks like a private field so probably better to check instanceof DateTime. Feel free to send a PR

good call. see #10

Fixed