All files / src/components/zd-date-range utils.ts

100% Statements 13/13
100% Branches 8/8
100% Functions 3/3
100% Lines 13/13

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 19 20 21 22 23 24 25 26 27 28 29 30 31 3293x   93x 84x 19x   65x       19x   19x   19x           93x 80x 80x 80x           80x    
import { toMask } from '../../utils/date-utils/date-utils';
 
export function getDateRangeMask(format: string, splitter: string, focused = true) {
    if (focused && format) {
        return toFullMask(format, splitter);
    }
    return '';
}
 
function toFullMask(format: string, splitter: string) {
    const partialMask = toMask(format);
 
    const fullMask = `${partialMask}${splitter}${partialMask}`;
 
    return fullMask;
}
 
/**
 * Helper to simplify the generation of date range mask and unit mask
 */
export function getMaskAndUnitMask({ inputFormat, displayFormat, splitter, isFocused }: { inputFormat?: string; displayFormat: string; splitter: string; isFocused?: boolean }) {
    const format = inputFormat || displayFormat;
    const unitMask = isFocused ? toMask(format) : '';
    const mask = getDateRangeMask(
        format,
        splitter,
        isFocused,
    )
 
    return { mask, unitMask };
}