Public
Edited
Oct 1, 2023
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
today = Temporal.Now.plainDateISO()
Insert cell
Temporal.Now.plainDateISO().toString()
Insert cell
Temporal.Now.plainDateISO().toJSON()
Insert cell
Temporal.Now.plainTimeISO()
Insert cell
Temporal.Now.plainTimeISO().toString()
Insert cell
Temporal.Now.plainTimeISO().toJSON()
Insert cell
Temporal.Now.plainDateTimeISO()
Insert cell
Temporal.Now.plainDateTimeISO().toString()
Insert cell
Temporal.Now.plainDateTimeISO().toJSON()
Insert cell
Insert cell
someDate = Temporal.PlainDate.from({ year: 2006, month: 8, day: 24 })
Insert cell
({
hour: someTime.hour,
minute: someTime.minute,
second: someTime.second,
millisecond: someTime.millisecond,
microsecond: someTime.microsecond,
nanosecond: someTime.nanosecond
})
Insert cell
Insert cell
Insert cell
timeStamp.epochMilliseconds
Insert cell
timeStamp.epochSeconds
Insert cell
timeStamp = Temporal.Now.instant()
Insert cell
Temporal = {
const { Intl, Temporal } = await import(
"https://unpkg.com/@js-temporal/polyfill@0.4.4/dist/index.esm.js?module"
);
return Temporal;
}
Insert cell
<input id='calendar-picker' type="date">
Insert cell
{
const datePicker = document.getElementById("calendar-picker");
const today = Temporal.Now.plainDateISO();
datePicker.max = today;
datePicker.value = today;
}
Insert cell
Plot.plot({
title: `LotR Calendar for ${today.year}`,
padding: 0,
height: 130,
x: { axis: null },
y: { tickFormat: Plot.formatWeekday("en", "narrow"), tickSize: 0 },
fy: { tickFormat: "" },
marks: [
Plot.cell(daysInThisYear, {
x: (d) => d.weekOfYear,
y: (d) => d.dayOfWeek,
fy: (d) => d.year,
stroke: "white",
fill: "lightgray",
inset: 0.5
}),
Plot.cell(lotrCalendarNow, {
x: (d) => d.date.weekOfYear,
y: (d) => d.date.dayOfWeek,
fy: (d) => d.date.year,
title: (d) => `${d.date.toString()}: ${d.event}`,
stroke: "white",
fill: "forestgreen",
inset: 0.5
})
]
})
Insert cell
daysInThisYear = {
const startDate = Temporal.PlainDate.from({
year: today.year,
month: 1,
day: 1
});

const daysOfYear = Array.from(
{ length: isLeapYear(today.year) ? 366 : 365 },
(_, i) => i
);

return daysOfYear.map((day) => startDate.add({ days: day }));
}
Insert cell
function isLeapYear(year) {
return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
}
Insert cell
lotrCalendarNow = lotrCalendarBase.map((d) => ({
date: d.date.toPlainDate({ year: today.year }),
event: d.event
}))
Insert cell
lotrCalendarBase = lotr.map((d) => ({
date: Temporal.PlainMonthDay.from({ month: +d.month, day: +d.day }),
event: d.event
}))
Insert cell
lotr = FileAttachment("lotr.csv").csv()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more