Persian (Jalali, Khorshidi) Calendar Plugin for Day.js with TypeScript support
npm install dayjalaliPersian (Jalali, Khorshidi) Calendar Plugin for Day.js with full TypeScript support. This plugin adds multi-calendar functionality to Day.js core, allowing seamless switching between Gregorian and Jalali calendars regardless of locale.
Key Features:
- 🎯 Full TypeScript Support
- 🔄 Seamless Calendar Switching
- 📅 Standard Format Support
- 🌐 Multi-language Support
- ⚡ Lightweight and Immutable
- 🐛 Fixed Leap Year Calculations
``bashNPM
npm install --save dayjalali
Usage
`typescript
import dayjs from 'dayjs'
import dayjalali from 'dayjalali'dayjs.extend(dayjalali)
`$3
`typescript
// Set default calendar
dayjs.calendar('jalali') // Jalali Calendar
dayjs.calendar('gregory') // Gregorian Calendar// Create a jalali date instance
const date = dayjs()
const jalaliDate = date.calendar('jalali')
`$3
`typescript
// Parse Gregorian date
const gregDate = dayjs('2024-03-20T16:00:00.000Z')// Parse Jalali date
const jalaliDate = dayjs('1403-01-01', { jalali: true })
`$3
`typescript
// Jalali calendar with English locale
dayjs().calendar('jalali').locale('en').format('DD MMMM YYYY')
// Output: '01 Farvardin 1403'// Gregorian calendar with Persian locale
dayjs().calendar('gregory').locale('fa').format('DD MMMM YYYY')
// Output: '20 مارس 2024'
`$3
All Api operations of dayjalali is same as Dayjs itself but calendar based, for more information checkout Dayjs API
For a glance:
- API Reference
- Parsing
- Constructor dayjs(existing?: string | number | Date | Dayjs)
- ISO 8601 string
- Unix Timestamp (milliseconds since the Unix Epoch - Jan 1 1970, 12AM UTC)
- Native Javascript Date object
- Clone .clone() | dayjs(original: Dayjs)
- Validation .isValid()
- Get and Set
- Year .year()
- Month .month()
- Day of the Month .date()
- Day of the Week .day()
- Hour .hour()
- Minute .minute()
- Second .second()
- Millisecond .millisecond()
- Set .set(unit: string, value: number)
- Manipulating
- Add .add(value: number, unit: string)
- Subtract .subtract(value: number, unit: string)
- Start of Time .startOf(unit: string)
- End of Time .endOf(unit: string)
- Displaying
- Format .format(stringWithTokens: string)
- List of all available formats
- Difference .diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)
- Unix Timestamp (milliseconds) .valueOf()
- Unix Timestamp (seconds) .unix()
- Days in the Month .daysInMonth()
- As Javascript Date .toDate()
- As Array .toArray()
- As JSON .toJSON()
- As ISO 8601 String .toISOString()
- As Object .toObject()
- As String .toString()
- Query
- Is Before .isBefore(compared: Dayjs)
- Is Same .isSame(compared: Dayjs)
- Is After .isAfter(compared: Dayjs)
- Is a Dayjs .isDayjs()`