How to use the intervalToDuration function from date-fns
Find comprehensive JavaScript date-fns.intervalToDuration code examples handpicked from public code repositorys.
GitHub: nccasia/komubot
200 201 202 203 204 205 206 207 208 209
} } } function showTrackerTime(spentTime) { const duration = intervalToDuration({ start: 0, end: spentTime * 1000 * 60 }); return `${duration.hours}h ${duration.minutes}m ${duration.seconds}s`; } module.exports = reportCheckout;
7
3
3
GitHub: shnigi/spedebot
12 13 14 15 16 17 18 19 20
const sunsetDate = new Date(helsinki.sys.sunset * 1000); const sunrise = Intl.DateTimeFormat('fi-FI', { timeStyle: 'short' }).format(sunriseDate); const sunset = Intl.DateTimeFormat('fi-FI', { timeStyle: 'short' }).format(sunsetDate); const { hours, minutes } = intervalToDuration({ start: sunsetDate, end: sunriseDate, });
3
2
0
25 26 27 28 29 30 31 32 33 34
); console.log('quota', quota); if (quota <= 0) { const duration = intervalToDuration({ start: new Date().getTime(), end: tomorrow, }); const formattedDuration = formatDuration(duration, {
0
1
0
23 24 25 26 27 28 29 30 31 32
return stdout; } function durationToString(durationInSeconds) { return formatDuration( intervalToDuration({start: 0, end: durationInSeconds * 1000}) ); } async function hibernate() {
0
1
2
535 536 537 538 539 540 541 542 543 544
let selectDateMs = new Date(arr[0], arr[1] - 1, arr[2]).getTime(); let nowMs = new Date().getTime(); if (!selectDate.value) alert("Please select date!"); else if (nowMs >= selectDateMs) alert("Please select date in future!"); else { let result = _dateFns.intervalToDuration({ start: new Date(years, months, date, hours, minutes, 0), end: new Date(arr[0], arr[1] - 1, arr[2], 0, 0, 0) }); resultText.textContent = `${result.years} Years, ${result.months} Months, ${result.days} Days, ${result.hours} Hours`;
0
0
1
+ 10 other calls in file
6 7 8 9 10 11 12 13 14 15 16 17 18
return sameDay && sameHour && sameMinute; }; const getMinutesByInterval = (interval) => { const duration = fns.intervalToDuration(interval); const minutes = (duration.minutes ?? 0) + (duration.hours ?? 0) * 60; return minutes; };
0
0
0
+ 3 other calls in file
3 4 5 6 7 8 9 10 11 12
module.exports.formatDuration = function formatDuration(durationInMillis) { if (durationInMillis < 1000) { return `${durationInMillis}ms`; } else { const duration = fns.intervalToDuration({ start: new Date(0), end: new Date(durationInMillis) }); return fns.formatDuration(duration).replace(/ hours?/, 'h').replace(/ minutes?/, 'm').replace(/ seconds?/, 's');
0
0
8
GitHub: jsonMartin/humidimon
137 138 139 140 141 142 143 144 145
const powerSwitchLog = []; const logPowerSwitchStatus = () => { const lastEntry = powerSwitchLog.length >= 1 ? powerSwitchLog.slice(-1)[0] : false; if (lastEntry) { lastEntry['interval'] = intervalToDuration({ start: lastEntry['timestamp'], end: new Date(), });
0
0
2
date-fns.format is the most popular function in date-fns (3838 examples)