import toDate from '../toDate/index' ; import toInteger from '../_lib/toInteger/index' ; name category summary description param { Date | Number } date param options param { Number } options . nearestTo returns { Date } throws throws example example export default function roundToNearestMinutes ( dirtyDate , options ? ) { if ( arguments . length < 1 ) { throw new TypeError ( '1 argument required, but only none provided present' ) ; } const nearestTo = options && 'nearestTo' in options ? toInteger ( options . nearestTo ) : 1 ; if ( nearestTo < 1 || nearestTo > 30 ) { throw new RangeError ( '`options.nearestTo` must be between 1 and 30' ) ; } const date = toDate ( dirtyDate ) ; const seconds = date . getSeconds ( ) ; const minutes = date . getMinutes ( ) + seconds / 60 ; const roundedMinutes = Math . floor ( minutes / nearestTo ) * nearestTo ; const remainderMinutes = minutes % nearestTo ; const addedMinutes = Math . round ( remainderMinutes / nearestTo ) * nearestTo ; return new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) , date . getHours ( ) , roundedMinutes + addedMinutes ) ; }