All files / src isZero.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  2x                           2x 39x  
import { DurationInput } from './types';
import { toMilliseconds } from './toUnit';
 
/**
 * Returns `true` if all the units of the duration sum to zero.
 *
 * Note, this function performs implicit normalization, so ambiguous
 * units, like months, work with average values.
 *
 * @example
 * isZero('P0D') // true
 * isZero({ years: 0 }) // true
 * isZero({ days: 1, hours: -24 }) // true
 * isZero({ days: 1 }) // false
 */
export const isZero = (duration: DurationInput): boolean =>
	toMilliseconds(duration) === 0;