{"version":3,"file":"date-relative-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/date/date-relative-rules.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Within days rule - date must be within X days from now (past or future)\r\n */\r\nexport const withinDaysRule: SchemaRule<{ days: number }> = {\r\n  name: \"withinDays\",\r\n  defaultErrorMessage: \"The :input must be within :days days from now\",\r\n  async validate(value: Date, context) {\r\n    const now = new Date();\r\n    const inputDate = new Date(value);\r\n    const diffTime = Math.abs(inputDate.getTime() - now.getTime());\r\n    const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));\r\n\r\n    if (diffDays <= this.context.options.days) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    this.context.translationParams.days = this.context.options.days;\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Within past days rule - date must be within X days in the past\r\n */\r\nexport const withinPastDaysRule: SchemaRule<{ days: number }> = {\r\n  name: \"withinPastDays\",\r\n  defaultErrorMessage: \"The :input must be within the past :days days\",\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 invalidRule(this, context); // Must be in past\r\n    }\r\n\r\n    const diffTime = now.getTime() - inputDate.getTime();\r\n    const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));\r\n\r\n    if (diffDays <= this.context.options.days) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    this.context.translationParams.days = this.context.options.days;\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Within future days rule - date must be within X days in the future\r\n */\r\nexport const withinFutureDaysRule: SchemaRule<{ days: number }> = {\r\n  name: \"withinFutureDays\",\r\n  defaultErrorMessage: \"The :input must be within the next :days days\",\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 invalidRule(this, context); // Must be in future\r\n    }\r\n\r\n    const diffTime = inputDate.getTime() - now.getTime();\r\n    const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));\r\n\r\n    if (diffDays <= this.context.options.days) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    this.context.translationParams.days = this.context.options.days;\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,iBAA+C;CAC1D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,sBAAM,IAAI,KAAK;EACrB,MAAM,YAAY,IAAI,KAAK,KAAK;EAChC,MAAM,WAAW,KAAK,IAAI,UAAU,QAAQ,IAAI,IAAI,QAAQ,CAAC;EAG7D,IAFiB,KAAK,KAAK,YAAY,MAAO,KAAK,KAAK,GAE7C,KAAK,KAAK,QAAQ,QAAQ,MACnC,OAAO;EAGT,KAAK,QAAQ,kBAAkB,OAAO,KAAK,QAAQ,QAAQ;EAE3D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,qBAAmD;CAC9D,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,sBAAM,IAAI,KAAK;EACrB,MAAM,YAAY,IAAI,KAAK,KAAK;EAEhC,IAAI,YAAY,KACd,OAAO,YAAY,MAAM,OAAO;EAGlC,MAAM,WAAW,IAAI,QAAQ,IAAI,UAAU,QAAQ;EAGnD,IAFiB,KAAK,KAAK,YAAY,MAAO,KAAK,KAAK,GAE7C,KAAK,KAAK,QAAQ,QAAQ,MACnC,OAAO;EAGT,KAAK,QAAQ,kBAAkB,OAAO,KAAK,QAAQ,QAAQ;EAE3D,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,uBAAqD;CAChE,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,sBAAM,IAAI,KAAK;E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