A JavaScript library for converting dates to and from the Tabari calendar, used in the Mazandaran region of Iran.
The Tabari calendar (also known as Mazandarani calendar) is a traditional calendar system used in the Mazandaran province of Iran. It is based on the Persian calendar but uses different month names and has its own year calculation.
- ✅ Convert Gregorian dates to Tabari calendar
- ✅ Convert Persian calendar dates to Tabari calendar
- ✅ Calculate Tabari year based on Wikipedia formula
- ✅ Uses built-in
Intl.DateTimeFormatAPI for accurate Persian calendar conversion (no external dependencies) - ✅ Full support for all 14 Tabari months including Shishak
npm install tabari-calendarimport { getTabariYear, persianToTabari, gregorianToTabari, getCurrentTabariDate } from 'tabari-calendar';
// Get Tabari year from a Gregorian date
const date = new Date(2024, 5, 15); // June 15, 2024
const tabariYear = getTabariYear(date);
console.log(tabariYear); // Tabari year
// Convert Persian calendar date to Tabari calendar
const tabariDate = persianToTabari(1, 1); // 1 Farvardin
console.log(tabariDate);
// {
// day: 1,
// month: 'پیتک',
// full: '۱ پیتک'
// }
// Convert Gregorian date to Tabari calendar
const tabari = gregorianToTabari(new Date(2024, 5, 15));
console.log(tabari);
// {
// year: 1537,
// day: 15,
// month: 'شروینه ما',
// full: '۱۵ شروینه ما ۱۵۳۷'
// }
// Get current Tabari date
const current = getCurrentTabariDate();
console.log(current);
// {
// year: 1537,
// day: 10,
// month: 'شروینه ما',
// full: '۱۰ شروینه ما ۱۵۳۷'
// }Calculates the Tabari year based on a Gregorian date.
Parameters:
date(Date, optional): Gregorian date. Defaults to current date.
Returns:
number: Tabari year
Formula: The formula is based on Persian calendar month (not Gregorian month), following the Wikipedia template:
- If Persian month >= 6: Tabari year = Gregorian year + 133
- If Persian month = 5 and day >= 2: Tabari year = Gregorian year + 133
- Otherwise: Tabari year = Gregorian year + 132
Note: The conversion uses Intl.DateTimeFormat API for accurate Persian calendar conversion, ensuring correct results.
Converts a Persian calendar date to Tabari calendar date.
Parameters:
day(number): Day of Persian month (1-31)month(number): Persian month (1-12)
Returns:
Object: Tabari date object with:day(number|null): Tabari day (null for Shishak)month(string): Tabari month namefull(string): Full Tabari date string
Throws:
- Error if month is not between 1 and 12
- Error if day is not between 1 and 31
- Error if no mapping found for the date
Converts a Gregorian date to Tabari calendar.
Parameters:
date(Date, optional): Gregorian date. Defaults to current date.
Returns:
Object: Tabari date object with:year(number): Tabari yearday(number|null): Tabari daymonth(string): Tabari month namefull(string): Full Tabari date string with year
Note: This function converts Gregorian to Persian first using the built-in Intl.DateTimeFormat API, then converts to Tabari calendar. This ensures accurate conversion without requiring external dependencies.
Gets the current Tabari date.
Returns:
Object: Current Tabari date object (same format asgregorianToTabari())
The Tabari calendar has 14 periods (13 months + Shishak):
- پیتک (Pitak) - Days 1-5 of Farvardin
- ارکه ما (Arke Ma) - Day 6 Farvardin to Day 4 Ordibehesht
- دِ ما (De Ma) - Day 5 Ordibehesht to Day 3 Khordad
- وَهمِنه ما (Vahmene Ma) - Day 4 Khordad to Day 2 Tir
- نوروزه ما (Nowruze Ma) - Day 3 Tir to Day 1 Mordad
- فردینه ما (Fardine Ma) - Day 2 Mordad to Day 31 Mordad
- کِرچه ما (Kerche Ma) - Day 1 Shahrivar to Day 30 Shahrivar
- هَره ما (Hare Ma) - Day 31 Shahrivar to Day 29 Mehr
- تیره ما (Tire Ma) - Day 30 Mehr to Day 29 Aban
- مِلاره ما (Melare Ma) - Day 30 Aban to Day 29 Azar
- شروینه ما (Shrovine Ma) - Day 30 Azar to Day 29 Dey
- میره ما (Mire Ma) - Day 30 Dey to Day 29 Bahman
- اونه ما (Oune Ma) - Day 30 Bahman to Day 29 Esfand
- شیشک (Shishak) - Day 30 Esfand (special day, no day number)
This library uses the built-in Intl.DateTimeFormat API with Persian calendar (en-US-u-ca-persian) for accurate conversion from Gregorian to Persian dates. This ensures:
- ✅ No external dependencies for calendar conversion
- ✅ Accurate date calculations based on official calendar rules
- ✅ Support for leap years and month boundaries
- ✅ Cross-platform compatibility
The Tabari year calculation follows the Wikipedia formula template, which determines the year based on the Persian calendar month and day, not the Gregorian month. This ensures accurate year calculation that aligns with the traditional Tabari calendar system.
npm testRun tests in watch mode:
npm run test:watchRun example:
npm run exampleContributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details.
- Based on the formulas from the Wikipedia Tabari calendar template
- Uses
Intl.DateTimeFormatAPI for Persian calendar conversion - Tabari calendar month mappings based on traditional Mazandarani calendar system