import * as StringCheck from "../../../../sync/check/string"; import * as check from "../../../../sync/check/date"; export type PotentiallyUnsafeDateStringResult = StringCheck.StringErrorCode|check.PotentiallyUnsafeDateErrorCode; export function checkPotentiallyUnsafeDateString (mixed : any) : undefined|PotentiallyUnsafeDateStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkPotentiallyUnsafeDate(toCheck); if (error !== undefined) { return error; } return undefined; }); } export type ValidDateStringResult = StringCheck.StringErrorCode|check.ValidDateErrorCodeType; export function checkValidDateString (mixed : any) : undefined|ValidDateStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkValidDate(toCheck); if (error !== undefined) { return error; } return undefined; }); } export type BeforeStringResult = StringCheck.StringErrorCode|check.ValidDateErrorCodeType|check.BeforeErrorCode; export function checkBeforeString (mixed : any, x : Date) : undefined|BeforeStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkBefore(toCheck, x); if (error !== undefined) { return error; } return undefined; }); } export type AfterStringResult = StringCheck.StringErrorCode|check.ValidDateErrorCodeType|check.AfterErrorCode; export function checkAfterString (mixed : any, x : Date) : undefined|AfterStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkAfter(toCheck, x); if (error !== undefined) { return error; } return undefined; }); } export type BeforeOrAtStringResult = StringCheck.StringErrorCode|check.ValidDateErrorCodeType|check.BeforeOrAtErrorCode; export function checkBeforeOrAtString (mixed : any, x : Date) : undefined|BeforeOrAtStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkBeforeOrAt(toCheck, x); if (error !== undefined) { return error; } return undefined; }); } export type AfterOrAtStringResult = StringCheck.StringErrorCode|check.ValidDateErrorCodeType|check.AfterOrAtErrorCode; export function checkAfterOrAtString (mixed : any, x : Date) : undefined|AfterOrAtStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkAfterOrAt(toCheck, x); if (error !== undefined) { return error; } return undefined; }); } export type RangeStringResult = StringCheck.StringErrorCode|check.RangeErrorCode; export function checkRangeString (mixed : any, args : { min? : Date, max? : Date }) : undefined|RangeStringResult { return StringCheck.checkStringPredicate(mixed, (str) => { const toCheck = new Date(str); const error = check.checkRange(toCheck, args); if (error !== undefined) { return error; } return undefined; }); }