@date-vir/duration
Version:
Durations units an utils for date-vir.
20 lines (19 loc) • 455 B
JavaScript
/**
* Negates all properties in a duration.
*
* @category Duration
* @example
*
* ```ts
* import {negateDuration} from 'date-vir';
*
* negateDuration({hours: -1, minutes: 5, seconds: 35});
* // `{hours: 1, minutes: -5, seconds: -35}`
* ```
*/
export function negateDuration(duration) {
return Object.fromEntries(Object.entries(duration).map(([key, value,]) => [
key,
value == undefined ? undefined : value * -1,
]));
}