{"version":3,"file":"date-special-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/date/date-special-rules.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Birthday rule - valid birthday (not in future, reasonable age)\r\n */\r\nexport const birthdayRule: SchemaRule<{ minAge?: number; maxAge?: number }> = {\r\n  name: \"birthday\",\r\n  defaultErrorMessage: \"The :input must be a valid birthday\",\r\n  async validate(birthDate: Date, context) {\r\n    const today = new Date();\r\n\r\n    // Must not be in the future\r\n    if (birthDate > today) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    // Calculate age\r\n    let age = today.getFullYear() - birthDate.getFullYear();\r\n    const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n    if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n      age--;\r\n    }\r\n\r\n    // Check minimum age (default: 0)\r\n    const minAge = this.context.options.minAge ?? 0;\r\n    if (age < minAge) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    // Check maximum age (default: 150)\r\n    const maxAge = this.context.options.maxAge ?? 150;\r\n    if (age > maxAge) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Between age rule - age must be between min and max years\r\n */\r\nexport const betweenAgeRule: SchemaRule<{ minAge: number; maxAge: number }> = {\r\n  name: \"betweenAge\",\r\n  defaultErrorMessage: \"Age must be between :minAge and :maxAge years\",\r\n  async validate(value: Date, context) {\r\n    const birthDate = new Date(value);\r\n    const today = new Date();\r\n    let age = today.getFullYear() - birthDate.getFullYear();\r\n    const monthDiff = today.getMonth() - birthDate.getMonth();\r\n\r\n    if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {\r\n      age--;\r\n    }\r\n\r\n    const { minAge, maxAge } = this.context.options;\r\n\r\n    if (age >= minAge && age <= maxAge) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    this.context.translationParams.minAge = minAge;\r\n    this.context.translationParams.maxAge = maxAge;\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Leap year rule - date must be in a leap year\r\n */\r\nexport const leapYearRule: SchemaRule = {\r\n  name: \"leapYear\",\r\n  defaultErrorMessage: \"The :input must be in a leap year\",\r\n  async validate(value: Date, context) {\r\n    const inputDate = new Date(value);\r\n    const year = inputDate.getFullYear();\r\n\r\n    // Leap year logic: divisible by 4, except century years unless divisible by 400\r\n    const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\r\n\r\n    if (isLeapYear) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,eAAiE;CAC5E,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,WAAiB,SAAS;EACvC,MAAM,wBAAQ,IAAI,KAAK;EAGvB,IAAI,YAAY,OACd,OAAO,YAAY,MAAM,OAAO;EAIlC,IAAI,MAAM,MAAM,YAAY,IAAI,UAAU,YAAY;EACtD,MAAM,YAAY,MAAM,SAAS,IAAI,UAAU,SAAS;EAExD,IAAI,YAAY,KAAM,cAAc,KAAK,MAAM,QAAQ,IAAI,UAAU,QAAQ,GAC3E;EAIF,MAAM,SAAS,KAAK,QAAQ,QAAQ,UAAU;EAC9C,IAAI,MAAM,QACR,OAAO,YAAY,MAAM,OAAO;EAIlC,MAAM,SAAS,KAAK,QAAQ,QAAQ,UAAU;EAC9C,IAAI,MAAM,QACR,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF;;;;AAKA,MAAa,iBAAiE;CAC5E,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,YAAY,IAAI,KAAK,KAAK;EAChC,MAAM,wBAAQ,IAAI,KAAK;EACvB,IAAI,MAAM,MAAM,YAAY,IAAI,UA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