Public
Edited
May 12, 2021
2 forks
3 stars
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) {
if (interval[key] === 1) {
format.push(`${interval[key]} ${key.slice(0, -1)}`);
} else if (format.length || interval[key] > 1) {
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(2020, 9, 9, -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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more