{"version":3,"file":"date-comparison-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/date/date-comparison-rules.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Between dates rule - date must be between start and end dates\r\n */\r\nexport const betweenDatesRule: SchemaRule<{\r\n  startDate: Date;\r\n  endDate: Date;\r\n}> = {\r\n  name: \"betweenDates\",\r\n  defaultErrorMessage: \"The :input must be between :startDate and :endDate\",\r\n  async validate(value: Date, context) {\r\n    const { startDate, endDate } = this.context.options;\r\n    const inputDate = new Date(value);\r\n\r\n    if (inputDate >= startDate && inputDate <= endDate) {\r\n      this.context.translationParams.startDate = startDate.toISOString();\r\n      this.context.translationParams.endDate = endDate.toISOString();\r\n      return VALID_RULE;\r\n    }\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Today rule - date must be exactly today\r\n */\r\nexport const todayRule: SchemaRule = {\r\n  name: \"today\",\r\n  defaultErrorMessage: \"The :input must be today\",\r\n  async validate(value: Date, context) {\r\n    const today = new Date();\r\n    today.setHours(0, 0, 0, 0);\r\n    const inputDate = new Date(value);\r\n    inputDate.setHours(0, 0, 0, 0);\r\n\r\n    if (inputDate.getTime() === today.getTime()) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Past rule - date must be in the past\r\n */\r\nexport const pastRule: SchemaRule = {\r\n  name: \"past\",\r\n  defaultErrorMessage: \"The :input must be in the past\",\r\n  async validate(value: Date, context) {\r\n    const now = new Date();\r\n    const inputDate = new Date(value);\r\n\r\n    if (inputDate < now) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Future rule - date must be in the future\r\n */\r\nexport const futureRule: SchemaRule = {\r\n  name: \"future\",\r\n  defaultErrorMessage: \"The :input must be in the future\",\r\n  async validate(value: Date, context) {\r\n    const now = new Date();\r\n\r\n    if (value > now) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * After today rule - date must be after today (not including today)\r\n */\r\nexport const afterTodayRule: SchemaRule = {\r\n  name: \"afterToday\",\r\n  defaultErrorMessage: \"The :input must be after today\",\r\n  async validate(value: Date, context) {\r\n    const today = new Date();\r\n    today.setHours(0, 0, 0, 0);\r\n    const inputDate = new Date(value);\r\n    inputDate.setHours(0, 0, 0, 0);\r\n\r\n    if (inputDate > today) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,mBAGR;CACH,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,WAAW,YAAY,KAAK,QAAQ;EAC5C,MAAM,YAAY,IAAI,KAAK,KAAK;EAEhC,IAAI,aAAa,aAAa,aAAa,SAAS;GAClD,KAAK,QAAQ,kBAAkB,YAAY,UAAU,YAAY;GACjE,KAAK,QAAQ,kBAAkB,UAAU,QAAQ,YAAY;GAC7D,OAAO;EACT;EAEA,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,YAAwB;CACnC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,wBAAQ,IAAI,KAAK;EACvB,MAAM,SAAS,GAAG,GAAG,GAAG,CAAC;EACzB,MAAM,YAAY,IAAI,KAAK,KAAK;EAChC,UAAU,SAAS,GAAG,GAAG,GAAG,CAAC;EAE7B,IAAI,UAAU,QAAQ,MAAM,MAAM,QAAQ,GACxC,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,WAAuB;CAClC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,sBAAM,IAAI,KAAK;EAGrB,IAAI,IAF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