Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Allow multiple values for exactly/not predicate #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions __tests__/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,31 @@ const generateRuleConfig = (type, options) => ({
options,
});

// Function that checks if a string is a valid date in the format YYYY-MM-DD, YYYY-MM, or YYYY
// and converts it to a Date object
const isValidDate = (dateString) => {
const dateRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
const yearMonthRegex = /^(\d{4})-(\d{2})$/;
const yearRegex = /^(\d{4})$/;

if (dateRegex.test(dateString)) {
const [year, month, day] = dateString.split('-');
return new Date(year, month - 1, day);
}

if (yearMonthRegex.test(dateString)) {
const [year, month] = dateString.split('-');
return new Date(year, month - 1);
}

if (yearRegex.test(dateString)) {
const [year] = dateString.split('-');
return new Date(year);
}

return false;
};

exports.isValidDate = isValidDate;
exports.getEntityGenerator = getEntityGenerator;
exports.generateRuleConfig = generateRuleConfig;
Loading