d3 = require("d3-time@2")
function interval(then, now) {
if (then <= now) throw new Error("Time’s up!");
let t = now;
let years = d3.timeYear.count(now, then);
if ((t = d3.timeYear.offset(t, years)) > then) t = d3.timeYear.offset(t, -1), --years;
let months = d3.timeMonth.count(t, then);
if ((t = d3.timeMonth.offset(t, months)) > then) t = d3.timeMonth.offset(t, -1), --months;
let days = d3.timeDay.count(t, then);
if ((t = d3.timeDay.offset(t, days)) > then) t = d3.timeDay.offset(t, -1), --days;
let hours = d3.timeHour.count(t, then);
if ((t = d3.timeHour.offset(t, hours)) > then) t = d3.timeHour.offset(t, -1), --hours;
let minutes = d3.timeMinute.count(t, then);
if ((t = d3.timeMinute.offset(t, minutes)) > then) t = d3.timeMinute.offset(t, -1), --minutes;
let seconds = d3.timeSecond.count(t, then);
if ((t = d3.timeSecond.offset(t, seconds)) > then) t = d3.timeSecond.offset(t, -1), --seconds;
return {years: years, months: months, days: days, hours: hours, minutes: minutes, seconds: seconds};
// return `Seconds left ${seconds}`
}
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(`${interval[key]} ${key}`);
}
}
if (format.length > 1) {
format[format.length - 1] = `and ${format[format.length - 1]}`;
}
return format.join(",\n");
}
templateFunction = (interval) => {
return html`<div class="countdown">
<span class="time">${interval.years} YEARS</span>
<span class="time">${interval.months} MONTHS</span>
<span class="occupation">${interval.days} DAYS</span>
<br>
<span class="occupation">${interval.hours} HOURS</span>
<span class="occupation">${interval.minutes} MINUTES</span>
<span class="occupation">${interval.seconds} SECONDS</span>
</div>`
}
then = new Date(Date.UTC(doom.year,doom.month,doom.day,doom.hour,doom.minute,doom.second))
now = {
while (true) {
const date = new Date(Math.ceil((Date.now() + 1) / 1000) * 1000);
yield Promises.when(date, date);
}
}
until 95.42% of all CRAN packages will be archived.
(last update: 2024-10-07 12:10:17.419088)