Published
Edited
Jun 26, 2021
1 fork
Insert cell
md`# Session time calculator`
Insert cell
{
if (!!start_time && !!end_time && !!half_way) {
return md`
Time left: **${Math.max(0, time_left)} minutes**

(Half way between ${start_time.toLocaleTimeString()} and ${end_time.toLocaleTimeString()} is ${half_way.toLocaleTimeString()})
`;
} else {
return null;
}
}
Insert cell
viewof start_time_text = Inputs.text({
label: "Start time",
placeholder: "e.g. 13:30"
})
Insert cell
viewof end_time_text = Inputs.text({
label: "End time",
placeholder: "e.g. 14:30"
})
Insert cell
parser = d3.timeParse("%Y-%m-%d %H:%M")
Insert cell
today = d3.timeFormat("%Y-%m-%d")(now)
Insert cell
start_time = parser(today + " " + start_time_text)
Insert cell
end_time = parser(today + " " + end_time_text)
Insert cell
time_left = d3.timeMinutes(now, end_time).length
Insert cell
half_way = start_time &&
end_time &&
new Date(
start_time.valueOf() + (end_time.valueOf() - start_time.valueOf()) / 2
)
Insert cell
now = {
while (true) {
yield Promises.delay(1000, new Date());
}
}
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