I’m having trouble creating a column containing the month name in an Arquero table. It seems as if the Date.toLocaleDateString("default", { month: "long" }) method can’t be called when using derive to create a new column.
Similarly, it seems as if I can’t reference a separate array with month names:
// Tried to use a separate array, but can't seem to reference it properly
month_name = protests
.derive({ month_num: d => op.month(d.Date) })
.derive({ month_name: d => monthNames[d.month_num] })
.select("Date", "month_num")
.view()
I would like to filter an Arquero table from an observable input selector.
But I am stuck, the following is a snapshot of a reproducible example I created:
Any suggestions is super welcome
Thanks in advance!
FYI: More than likely, multiple date/time formatting will be done on Arquero tables (eg: date, day of week, year, hours, minutes, etc.) In that event, using d3’s date formatting (or a library-independent formatting) through Arquero’s extended functions is a viable option:
The following pattern is library-independent, will provide multi-formatting flexibility and perform well:
{
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
const dateFormatting = new Intl.DateTimeFormat("en-US",{month: "long"});
// https://uwdata.github.io/arquero/api/extensibility#addFunction
aq.addFunction("getMonth", x => dateFormatting.format(x));
return protests
.derive({ month: d => op.getMonth(d.Date)})
.select("Date", "month")
.view()
}