UNPKG

@onesy/date

Version:

Time and date utils library

10 lines (9 loc) 382 B
import { units } from './OnesyDate'; export default function diff(value, value1) { let unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'millisecond'; if (value && value.valid && value1 && value1.valid) { const diffs = {}; units.forEach(unit_ => diffs[unit_] = Math.floor(value[unit_] - value1[unit_])); return Math.abs(diffs[unit]); } }