
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
jalaali-js
Advanced tools
The jalaali-js npm package provides utilities for converting between the Jalaali (Persian) calendar and the Gregorian calendar. It is useful for applications that need to support Persian date formats and conversions.
Convert Gregorian to Jalaali
This feature allows you to convert a Gregorian date to a Jalaali date. The `toJalaali` function takes a Gregorian year, month, and day as input and returns an object with the corresponding Jalaali year, month, and day.
const jalaali = require('jalaali-js');
const jalaaliDate = jalaali.toJalaali(2023, 10, 5);
console.log(jalaaliDate); // { jy: 1402, jm: 7, jd: 13 }
Convert Jalaali to Gregorian
This feature allows you to convert a Jalaali date to a Gregorian date. The `toGregorian` function takes a Jalaali year, month, and day as input and returns an object with the corresponding Gregorian year, month, and day.
const jalaali = require('jalaali-js');
const gregorianDate = jalaali.toGregorian(1402, 7, 13);
console.log(gregorianDate); // { gy: 2023, gm: 10, gd: 5 }
Check if a Jalaali year is a leap year
This feature allows you to check if a given Jalaali year is a leap year. The `isLeapJalaaliYear` function takes a Jalaali year as input and returns a boolean indicating whether it is a leap year.
const jalaali = require('jalaali-js');
const isLeap = jalaali.isLeapJalaaliYear(1402);
console.log(isLeap); // false
The `moment-jalaali` package extends the popular `moment` library to support Jalaali dates. It provides a rich set of features for date manipulation and formatting, making it more versatile than `jalaali-js` for applications that already use `moment`.
A few javascript functions for converting Jalaali (Jalali, Persian, Khayyami, Khorshidi, Shamsi) and Gregorian calendar systems to each other.
If you just need to display date and time in Persian calendar, you may use Intl
which is ECMAScript Internationalization API with a very good browser support. For example:
const d = new Date(2022,2,21)
// Simple format
console.log(new Intl.DateTimeFormat('fa-IR').format(d));
// => ۱۴۰۱/۱/۱
// Full long format
console.log(new Intl.DateTimeFormat('fa-IR', {dateStyle: 'full', timeStyle: 'long'}).format(d));
// => ۱۴۰۱ فروردین ۱, دوشنبه، ساعت ۰:۰۰:۰۰ (+۳:۳۰ گرینویچ)
// Latin numbers
console.log(new Intl.DateTimeFormat('fa-IR-u-nu-latn', {dateStyle: 'full', timeStyle: 'long'}).format(d));
// => 1401 فروردین 1, دوشنبه، ساعت 0:00:00 (+3:30 گرینویچ)
// English US locale with Persian calendar
console.log(new Intl.DateTimeFormat('en-US-u-ca-persian', {dateStyle: 'full', timeStyle: 'long'}).format(d));
// => Monday, Farvardin 1, 1401 AP at 12:00:00 AM GMT+3:30
// Just year
console.log(new Intl.DateTimeFormat('en-US-u-ca-persian', {year: 'numeric'}).format(d));
// => 1401 AP
// Just month
console.log(new Intl.DateTimeFormat('en-US-u-ca-persian', {month: 'short'}).format(d));
// Farvardin
// Just day
console.log(new Intl.DateTimeFormat('en-US-u-ca-persian', {day: 'numeric'}).format(d));
// => 1
Notice: the current implementation of
jalaali-js
algorithms diverge from theIntl
API results after the Gregorian year 2256 (or Jalali year 1634) due to different approaches to calculating the leap years. However, this shouldn't affect the usage of the library, as the results are the same from 1800 to 2256. (for more information, see this comparison)
Jalali calendar is a solar calendar that was used in Persia, variants of which today are still in use in Iran as well as Afghanistan. Read more on Wikipedia or see Calendar Converter.
Calendar conversion is based on the algorithm provided by Kazimierz M. Borkowski and has a very good performance.
Use npm
to install:
$ npm install --save jalaali-js
Then import it:
var jalaali = require('jalaali-js')
Use component
to install:
$ component install jalaali/jalaali-js
Then import it:
var jalaali = require('jalaali-js')
Or use a CDN:
<script src="https://cdn.jsdelivr.net/npm/jalaali-js/dist/jalaali.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jalaali-js/dist/jalaali.min.js"></script>
<script src="https://unpkg.com/jalaali-js/dist/jalaali.js"></script>
<script src="https://unpkg.com/jalaali-js/dist/jalaali.min.js"></script>
Converts a Gregorian date to Jalaali.
jalaali.toJalaali(2016, 4, 11) // { jy: 1395, jm: 1, jd: 23 }
Converts a JavaScript Date object to Jalaali.
jalaali.toJalaali(new Date(2016, 3, 11)) // { jy: 1395, jm: 1, jd: 23 }
Converts a Jalaali date to Gregorian.
jalaali.toGregorian(1395, 1, 23) // { gy: 2016, gm: 4, gd: 11 }
Checks whether a Jalaali date is valid or not.
jalaali.isValidJalaaliDate(1394, 12, 30) // false
jalaali.isValidJalaaliDate(1395, 12, 30) // true
Is this a leap year or not?
jalaali.isLeapJalaaliYear(1394) // false
jalaali.isLeapJalaaliYear(1395) // true
Number of days in a given month in a Jalaali year.
jalaali.jalaaliMonthLength(1394, 12) // 29
jalaali.jalaaliMonthLength(1395, 12) // 30
This function determines if the Jalaali (Persian) year is leap (366-day long) or is the common year (365 days), and finds the day in March (Gregorian calendar) of the first day of the Jalaali year (jy).
jalaali.jalCal(1390) // { leap: 3, gy: 2011, march: 21 }
jalaali.jalCal(1391) // { leap: 0, gy: 2012, march: 20 }
jalaali.jalCal(1392) // { leap: 1, gy: 2013, march: 21 }
jalaali.jalCal(1393) // { leap: 2, gy: 2014, march: 21 }
jalaali.jalCal(1394) // { leap: 3, gy: 2015, march: 21 }
jalaali.jalCal(1395) // { leap: 0, gy: 2016, march: 20 }
Converts a date of the Jalaali calendar to the Julian Day number.
jalaali.j2d(1395, 1, 23) // 2457490
Converts the Julian Day number to a date in the Jalaali calendar.
jalaali.d2j(2457490) // { jy: 1395, jm: 1, jd: 23 }
Calculates the Julian Day number from Gregorian or Julian calendar dates. This integer number corresponds to the noon of the date (i.e. 12 hours of Universal Time). The procedure was tested to be good since 1 March, -100100 (of both calendars) up to a few million years into the future.
jalaali.g2d(2016, 4, 11) // 2457490
Calculates Gregorian and Julian calendar dates from the Julian Day number (jdn) for the period since jdn=-34839655 (i.e. the year -100100 of both calendars) to some millions years ahead of the present.
jalaali.d2g(2457490) // { gy: 2016, gm: 4, gd: 11 }
Convert Jalaali calendar date to javascript Date object by giving Jalaali year, month, and day.
jalaali.jalaaliToDateObject(1400, 4, 30) // new Date(2021, 6, 21)
Return Saturday and Friday day of current week(week start in Saturday)
jalaali.jalaaliWeek(1400, 4, 30) // { saturday: { jy: 1400, jm: 4, jd: 26 }, friday: { jy: 1400, jm: 5, jd: 1 } }
MIT
FAQs
Converts Gregorian and Jalaali calendars to each other
The npm package jalaali-js receives a total of 164,984 weekly downloads. As such, jalaali-js popularity was classified as popular.
We found that jalaali-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.