Jalali Date Validation

Strict mathematical validation for Persian dates. Validates leap years and exact month lengths without relying on heavy external libraries.

Validation in Forms

Using this schema prevents impossible dates from passing validation (e.g., rejecting the 30th of Esfand in non-leap years).

schema.ts
typescript
import * as z from 'zod';
import { zJalaliDate } from 'zod-ir';

const ValidationSchema = z.object({
  birthDate: zJalaliDate({ message: 'تاریخ وارد شده نامعتبر است' }),
});

// Valid (Leap Year)
ValidationSchema.parse({ birthDate: '1403/12/30' });

// Invalid (1402 is not a Leap Year)
ValidationSchema.parse({ birthDate: '1402/12/30' });

Pure Functions

Independently verify a date's validity and extract precise details such as its leap year status.

pure-functions.ts
typescript
import { isJalaliDate, getJalaliDateInfo } from 'zod-ir';

const dateStr = '1403/12/30';

if (isJalaliDate(dateStr)) {
  const info = getJalaliDateInfo(dateStr);
  console.log(info.year);   // 1403
  console.log(info.isLeap); // true
} else {
  console.log('تاریخ نامعتبر است');
}