date-fns#differenceInMilliseconds JavaScript Examples
The following examples show how to use
date-fns#differenceInMilliseconds.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From ftx-cli with MIT License | 6 votes |
function calculateMillisecondsUntilDate(date) {
const currentDate = new Date();
const scheduleDate = parseISO(date);
if (!isValid(scheduleDate)) {
return null;
}
if (isBefore(scheduleDate, currentDate)) {
return null;
}
return differenceInMilliseconds(scheduleDate, currentDate);
}
Example #2
Source File: index.js From react-timeline-range-slider with MIT License | 6 votes |
getFormattedBlockedIntervals = (blockedDates = [], [startTime, endTime]) => {
if (!blockedDates.length) return null
const timelineLength = differenceInMilliseconds(endTime, startTime)
const getConfig = getTimelineConfig(startTime, timelineLength)
const formattedBlockedDates = blockedDates.map((interval, index) => {
let { start, end } = interval
if (isBefore(start, startTime)) start = startTime
if (isAfter(end, endTime)) end = endTime
const source = getConfig(start)
const target = getConfig(end)
return { id: `blocked-track-${index}`, source, target }
})
return formattedBlockedDates
}
Example #3
Source File: index.js From react-timeline-range-slider with MIT License | 6 votes |
getNowConfig = ([startTime, endTime]) => {
const timelineLength = differenceInMilliseconds(endTime, startTime)
const getConfig = getTimelineConfig(startTime, timelineLength)
const source = getConfig(new Date())
const target = getConfig(addMinutes(new Date(), 1))
return { id: 'now-track', source, target }
}
Example #4
Source File: index.js From react-timeline-range-slider with MIT License | 5 votes |
getTimelineConfig = (timelineStart, timelineLength) => (date) => {
const percent = differenceInMilliseconds(date, timelineStart)/timelineLength * 100
const value = Number(format(date, 'T'))
return { percent, value }
}