Home > Software engineering >  React Tabulator failing to return valid date from ISO 8601 timestamp
React Tabulator failing to return valid date from ISO 8601 timestamp

Time:05-14

I'm using React running Tabulator 0.18.1. I have a timestamp formatted in ISO 8601 (ex. 2022-05-08T03:24:19.991 00:00) that I'd like to be converted into mm/dd/yyyy.

This is what I'm doing to set up the column data and formatter:

 var columns = [
        {
            title: "Last Seen", field: "attributes.lastSeen", width: 200, formatter: "datetime", formatterParams: {
                inputFormat: "iso",
                outputFormat: "mm/dd/yyyy",
                invalidPlaceholder: "(invalid date)",
                timezone: "America/Los_Angeles",
            }
        }
    ]

My problem is that Tabulator prints (invalid date) in the table, instead of the converted date. I have luxon 2.3.2 installed, and am getting no errors regarding that, just the invalid date. I'm actually not getting any errors in the console at all, so I'm having trouble diagnosing this. I've tried looking for other possible inputFormats that might work, but I've yet to find anything.

Any recommendations on how to get this ISO time converted to mm/dd/yyyy? Hopefully I covered everything, but if any additional detail is need, just ask. Thank you all very much!

CodePudding user response:

I'm assuming that the type of lastSeen is ISO string in your input data.

Working Demo: https://codesandbox.io/s/valid-date-from-iso-f06hc2?file=/components/Home.js

I used a fake data for the above demo which you can find in data.js inside components folder.

Hope it helps!

  • Related