Public
Edited
Aug 26, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
function interval(then, now) {
let t = now;

let mois = d3.timeMonth.count(then, now);
if ((t = d3.timeMonth.offset(t, -mois)) < then)
(t = d3.timeMonth.offset(t, -1)), mois;

let jours = d3.timeDay.count(t, then);
if ((t = d3.timeDay.offset(t, jours)) < then)
(t = d3.timeDay.offset(t, 1)), jours;

let heures = d3.timeHour.count(t, then);
if ((t = d3.timeHour.offset(t, heures)) < then)
(t = d3.timeHour.offset(t, 1)), heures;

let minutes = d3.timeMinute.count(t, then);
if ((t = d3.timeMinute.offset(t, minutes)) < then)
(t = d3.timeMinute.offset(t, 1)), minutes;
let secondes = d3.timeSecond.count(t, then);

if ((t = d3.timeSecond.offset(t, secondes)) < then)
(t = d3.timeSecond.offset(t, 1)), secondes;
return { mois, jours, heures, minutes, secondes };
}
Insert cell
mois = d3.timeMonth.count(now, then)
Insert cell
d3.timeMonth.offset(now, 1)
Insert cell
d3.timeMonth.count(then, now)
Insert cell
function formatInterval(interval) {
let format = [];
for (const key in interval) {
format.push(`${Math.abs(interval[key])} ${key}`);
}
if (format.length > 1) {
format[format.length - 1] = `et ${format[format.length - 1]}`;
}
return format.join(",\n");
}
Insert cell
Insert cell
then = new Date(Date.UTC(2024, 6, 17, -2))
Insert cell
now = {
while (true) {
const date = new Date(Math.ceil((Date.now() + 1) / 1000) * 1000);
yield Promises.when(date, date);
}
}
Insert cell
d3 = require("d3-time@2")
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