Persian (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
# NPM
npm install --save dayjalali
# YARN
yarn add dayjalali
# PNPM
pnpm add dayjalali
import dayjs from 'dayjs'
import dayjalali from 'dayjalali'
dayjs.extend(dayjalali)
// 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')
// Parse Gregorian date
const gregDate = dayjs('2024-03-20T16:00:00.000Z')
// Parse Jalali date
const jalaliDate = dayjs('1403-01-01', { jalali: true })
// 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'
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
- Get and Set
- Manipulating
-
Displaying
-
Format
.format(stringWithTokens: string)
- 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()
-
Format
- Query
- Plugin APIs