Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseDateString(date, separator = '-') {
// Expects format MM-yyyy by default: no dates
let datePieces = date.split(separator);
if (datePieces.length === 2) {
if (datePieces[0] < 1 || datePieces[0] > 12) {
throw new Error('Not a valid month value');
}
let firstOfMonth = new Date(datePieces[1], datePieces[0] - 1, 1);
if (isValid(firstOfMonth)) {
return firstOfMonth;
}
}
// what to return if not valid?
throw new Error(`Please use format MM${separator}yyyy`);
}
function handleRaw(what, value, displayDateFormat) {
const denseFormat = displayDateFormat.replace(/[-\/\.]/g, "");
// Assuming the format consists of 2 M, 2 d, and 2 y
const dIdx = denseFormat.indexOf("d");
const d = value.substring(dIdx, dIdx + 2);
const mIdx = denseFormat.indexOf("M");
const m = value.substring(mIdx, mIdx + 2);
const yIdx = denseFormat.indexOf("y");
const y = value.substring(yIdx, yIdx + 4);
let date = new Date(parseInt(y), parseInt(m) - 1, parseInt(d));
date = isValid(date) ? date : null;
if (what === "min") return { min: date, max: null };
else return { min: null, max: date };
}
const isActive = () => {
if (isValid(now) && isValid(startedAtDate) && isValid(endsAt)) {
return isWithinInterval(now, {
start: startedAtDate,
end: endsAt,
});
}
return false;
};
)
}
});
}
}
].filter(Boolean);
const cells = [
<div title="{fingerprint}">
<span>{fingerprint}</span>
</div>,
!isNarrow && (isValid(creation) ? format(creation, 'PP', { locale: dateLocale }) : '-'),
!isTinyMobile &&
(isValid(expiration) ? format(expiration, 'PP', { locale: dateLocale }) : '-'),
!isNarrow && algo,
{isActive ? {c('Key badge').t`Active`} : null}
{isVerificationOnly ? (
{c('Key badge').t`Verification only`}
) : null}
{isWKD ? {c('Key badge').t`WKD`} : null}
{isTrusted ? {c('Key badge').t`Trusted`} : null}
{isRevoked ? {c('Key badge').t`Revoked`} : null}
{isExpired ? {c('Key badge').t`Expired`} : null}
,
].filter(Boolean);
return ;
_isValidDate(date, min, max) {
try {
if (!date) {
return false;
}
if (dateFns.isValid(date)) {
if (!min && !max) {
return true;
}
if (min && max) {
return dateFns.isWithinRange(date, min, max);
}
if (max) {
return dateFns.isBefore(date, max) || dateFns.isEqual(date, max);
}
return dateFns.isAfter(date, min) || dateFns.isEqual(date, min);
} else {
return false;
}
} catch (e) {
return false;
}
private parseToDate( val: any ): Date {
if (!val) {
return;
}
let parsedVal;
if (typeof val === 'string') {
parsedVal = parse(val, this.dateFormat, this.now);
} else {
parsedVal = val;
}
return isValid(parsedVal) ? parsedVal : null;
}
export const isBeforeMin = (month: Date, minDate: Date, n: number = 0) => {
return isValid(minDate) ? isBefore(addMonths(startOfDay(month), n), startOfDay(minDate)) : false;
};
.x(({ name }) => xScale(isValid(name) ? new Date(name) : name))
.y(({ value }) => yScale(value))
export function iCalEventForExam(module: Module, semester: Semester): EventOption | null {
const semesterData = getModuleSemesterData(module, semester);
if (!semesterData) return null;
const { examDate, examDuration } = semesterData;
if (!examDate) return null;
const start = new Date(examDate);
if (!isValid(start)) return null;
return {
start,
end: addMinutes(start, examDuration || DEFAULT_EXAM_DURATION),
summary: `${module.moduleCode} Exam`,
description: module.title,
};
}
var isAfterMax = function (month, maxDate, n) {
if (n === void 0) { n = 0; }
return dateFns.isValid(maxDate) ? dateFns.isAfter(dateFns.addMonths(dateFns.startOfDay(month), n), dateFns.startOfDay(maxDate)) : false;
};
var isDisabled = function (config, date) {