All files / src/utils/date-utils date-utils.ts

100% Statements 12/12
100% Branches 3/3
100% Functions 2/2
100% Lines 10/10

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 2893x   93x         87x   25x   23x   23x 12x   11x               93x 42x    
import { dayjs } from '@zeedhi/core';
 
export function isDateAllowed(
	date: Date,
	dateFormat: string,
	allowedDates?: ((date: string) => boolean) | string[],
): boolean {
	if (!allowedDates) return true;
 
	if (allowedDates.length === 0) return false;
 
	const dateString = dayjs(date).format(dateFormat);
 
	if (allowedDates instanceof Function) {
		return allowedDates(dateString);
	}
	return allowedDates.indexOf(dateString) !== -1;
}
 
/**
 * Translates a date format into a mask format
 * @param format The format to be translated
 * @returns The mask format
 */
export function toMask(format: string): string {
	return format.replace(/[A-Za-z]/gi, '#');
}