Skip to content

A JavaScript library for converting dates to and from the Tabari calendar, used in the Mazandaran region of Iran.

License

Notifications You must be signed in to change notification settings

rezaghz/tabari-calendar-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tabari Calendar Library

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.

Features

  • ✅ Convert Gregorian dates to Tabari calendar
  • ✅ Convert Persian calendar dates to Tabari calendar
  • ✅ Calculate Tabari year based on Wikipedia formula
  • ✅ Uses built-in Intl.DateTimeFormat API for accurate Persian calendar conversion (no external dependencies)
  • ✅ Full support for all 14 Tabari months including Shishak

Installation

npm install tabari-calendar

Usage

Basic Usage

import { 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: '۱۰ شروینه ما ۱۵۳۷'
// }

API Reference

getTabariYear(date?)

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.

persianToTabari(day, month)

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 name
    • full (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

gregorianToTabari(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 year
    • day (number|null): Tabari day
    • month (string): Tabari month name
    • full (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.

getCurrentTabariDate()

Gets the current Tabari date.

Returns:

  • Object: Current Tabari date object (same format as gregorianToTabari())

Tabari Calendar Months

The Tabari calendar has 14 periods (13 months + Shishak):

  1. پیتک (Pitak) - Days 1-5 of Farvardin
  2. ارکه ما (Arke Ma) - Day 6 Farvardin to Day 4 Ordibehesht
  3. دِ ما (De Ma) - Day 5 Ordibehesht to Day 3 Khordad
  4. وَهمِنه ما (Vahmene Ma) - Day 4 Khordad to Day 2 Tir
  5. نوروزه ما (Nowruze Ma) - Day 3 Tir to Day 1 Mordad
  6. فردینه ما (Fardine Ma) - Day 2 Mordad to Day 31 Mordad
  7. کِرچه ما (Kerche Ma) - Day 1 Shahrivar to Day 30 Shahrivar
  8. هَره ما (Hare Ma) - Day 31 Shahrivar to Day 29 Mehr
  9. تیره ما (Tire Ma) - Day 30 Mehr to Day 29 Aban
  10. مِلاره ما (Melare Ma) - Day 30 Aban to Day 29 Azar
  11. شروینه ما (Shrovine Ma) - Day 30 Azar to Day 29 Dey
  12. میره ما (Mire Ma) - Day 30 Dey to Day 29 Bahman
  13. اونه ما (Oune Ma) - Day 30 Bahman to Day 29 Esfand
  14. شیشک (Shishak) - Day 30 Esfand (special day, no day number)

Technical Details

Persian Calendar Conversion

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

Year Calculation

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.

Testing

npm test

Run tests in watch mode:

npm run test:watch

Run example:

npm run example

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

References

  • Based on the formulas from the Wikipedia Tabari calendar template
  • Uses Intl.DateTimeFormat API for Persian calendar conversion
  • Tabari calendar month mappings based on traditional Mazandarani calendar system

About

A JavaScript library for converting dates to and from the Tabari calendar, used in the Mazandaran region of Iran.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published