jalali-plugin-dayjs
v1.1.4
Published
Persian (Jalali, Khorshidi) Plugin for Day.js
Downloads
3,746
Maintainers
Readme
jalali-plugin-dayjs
This plugin is based on the jalaliday package. Since that package is no longer maintained, I have addressed and fixed various issues to ensure continued support and functionality.
Persian (Jalali, Khorshidi) Plugin for Day.js, jalali-plugin-dayjs add multi-calendar functionality to Day.js core regardless for of locale, so we can have Gregorian calendar is Persian locale of Jalali calendar in English locale
Unlike moment and becuase of immutablity of dayjs, there is no need for formats like jYYYY
or jMM
, in jalali-plugin-dayjs all formats are same and standard
Installation
NPM
npm install --save jalali-plugin-dayjs
YARN
yarn add jalali-plugin-dayjs
Usage
import dayjs from 'dayjs'
import jalaliday from 'jalali-plugin-dayjs'
dayjs.extend(jalaliday)
Changing calendar
If you want to all new instanses of dayjs use jalali
calendar, you can set default calendar
dayjs.calendar('jalali') // Jalali Calendar
// OR
dayjs.calendar('gregory') // Gregorian Calendar
also you can create a jalali date without changing default calendar
const date = dayjs()
const jalaliDate = date.calendar('jalali')
Parse Date
- Parse Gregory date
const date = dayjs('2018-04-04T16:00:00.000Z');
- Parse Jalali date
const date = dayjs('1398-10-17', { jalali: true });
Multiple Locale
with combination of calendar
and locale
we have multi language for real
dayjs().calendar('jalali').locale('en').format('DD MMMM YYYY') // '13 Shahrivar 1397'
dayjs().calendar('gregory').locale('fa').format('DD MMMM YYYY') // '04 سپتامبر 2018'
API
All Api operations of jalali-plugin-dayjs 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