nanakshahi-js
A JavaScript Library to get Nanakshahi Dates and Gurpurabs
![jsdelivr](https://data.jsdelivr.com/v1/package/npm/nanakshahi/badge)
Contents
- Usage
- API
- getDateFromNanakshahi(year, month, date)
- getHolidaysForDay([gregorianDate])
- getHolidaysForMonth(month, [year])
- getNanakshahiDate(gregorianDate)
- findMovableHoliday(holiday, [year])
- findBikramiFromDate(date, [astro], [isJulian])
- findDateFromBikramiLunar(year, month, date, [paksh], [leapMonth], [leapDay], [astro])
- findDateFromBikramiSolar(year, month, date, [astro])
- Acknowledgements
- Contributing
Usage
Install the library via NPM:
npm install nanakshahi
The library can be imported into Node as below:
const n = require('nanakshahi')
const date = new Date()
n.getNanakshahiDate( date )
n.getDateFromNanakshahi( 550, 10, 23 )
n.getHolidaysForDay( date )
n.getHolidaysForMonth( 1 )
n.findMovableHoliday( 'gurunanak' )
n.findBikramiFromDate( date )
n.findDateFromBikramiLunar( 1723, 10, 7 )
n.findDateFromBikramiSolar( 1723, 9, 23 )
Additionally, the package is available for web use via unpkg CDN.
<script src="https://unpkg.com/nanakshahi"></script>
Or via jsDelivr
<script src="https://cdn.jsdelivr.net/npm/nanakshahi/dist/index.min.js"></script>
Want a demo?
![Try on RunKit](https://img.shields.io/badge/Try%20on%20RunKit-nanakshahi-brightgreen.svg?style=flat-square)
Polyfill
While the library does run on most modern browsers, it does not work on IE11.
The library requires Math.sign
and Array.prototype.includes
. These can be added with the Polyfill below to add IE11 support:
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=Math.sign%2CArray.prototype.includes"></script>
API
getDateFromNanakshahi(year, month, date)
Converts Nanakshahi Date into the Gregorian Calendar
Returns: Object
- Gregorian Date
Param | Type | Description |
---|
year | number | Nanakshahi Year |
month | number | Nanakshahi Month, 1-12 |
date | number | Nanakshahi Day |
Example
getDateFromNanakshahi( 550, 10, 23 )
getHolidaysForDay([gregorianDate])
Returns all Gurpurabs and Holidays for a Date
Returns: Array
- Holidays for the day with Date and name in English and Punjabi
Param | Type | Description |
---|
[gregorianDate] | Object | JavaScript Date() Object |
Example
getHolidaysForDay( new Date() )
getHolidaysForMonth(month, [year])
Returns all Gurpurabs and Holidays for a Nanakshahi Month
Returns: Object
- Holidays for the month with Date and name in English and Punjabi
Param | Type | Description |
---|
month | number | Nanakshahi Month, 1-12 |
[year] | number | Nanakshahi Year, default is Current Gregorian Year |
Example
getHolidaysForMonth( 1 )
getNanakshahiDate(gregorianDate)
Converts given Gregorian Date to the corresponding date in the Nanakshahi Calendar
Returns: Object
- Nanakshahi Date in English and Punjabi
Param | Type | Description |
---|
gregorianDate | Object | JavaScript Date() Object |
Example
getNanakshahiDate( new Date() )
findMovableHoliday(holiday, [year])
Returns Gregorian Date of Movable Holiday
Movable Holidays List:
gurunanak
Parkash Guru Nanak Dev Jibandishhorr
Bandi Shhorr Divas / Diwaliholla
Holla Mahallakabeer
Birthday Bhagat Kabeer Jiravidaas
Birthday Bhagat Ravidaas Jinaamdev
Birthday Bhagat Naamdev Ji
Returns: Object
- Holiday Date with Name in English and Punjabi
Param | Type | Description |
---|
holiday | string | Holiday which date will be calculated. |
[year] | number | Gregorian year, default is current year. |
Example
findMovableHoliday( 'gurunanak' )
findBikramiFromDate(date, [astro], [isJulian])
Returns given date to the corresponding date in the Bikrami Calendar
Returns: Object
- Bikrami (Includes Lunar and Solar Date)
Param | Type | Default | Description |
---|
date | Object | | JavaScript Date() Object |
[astro] | boolean | true | Set to false to use Surya Sidhantta instead of Drik Gannit |
[isJulian] | boolean | false | Set to true if entered date is in Julian Calendar |
Example
findBikramiFromDate( new Date() )
findDateFromBikramiLunar(year, month, date, [paksh], [leapMonth], [leapDay], [astro])
Converts Bikrami Lunar Date into the Gregorian Calendar
Returns: Object
- Gregorian Date
Param | Type | Default | Description |
---|
year | number | | Bikrami Year |
month | number | | Bikrami Month |
date | number | | Bikrami Tithi |
[paksh] | boolean | false | Lunar Paksh. Default is Sudi, true for Vadi. |
[leapMonth] | boolean | false | Set to true if the month is Adhika Month (Mal Maas) |
[leapDay] | boolean | false | Set to true if the lunar day spans more than 1 solar day |
[astro] | boolean | true | Set to false to use Surya Sidhantta instead of Drik Gannit |
Example
findDateFromBikramiLunar( 1723, 10, 7 )
findDateFromBikramiSolar(year, month, date, [astro])
Converts Bikrami Solar Date into the Gregorian Calendar
Returns: Object
- Gregorian Date
Param | Type | Default | Description |
---|
year | number | | Bikrami Year |
month | number | | Bikrami Month |
date | number | | Bikrami Day |
[astro] | boolean | true | Set to false to use Surya Sidhantta instead of Drik Gannit |
Example
findDateFromBikramiSolar( 1723, 9, 23 )
Acknowledgements
I want to thank:
-
Guru Sahib, who inspires us into Sikhi.
-
Pal Singh Purewal, who explained various concepts in the Bikrami and Nanakshahi Calendars to me and answered my various technical and historical questions. Spent countless hours verifying the calculations done by me.
-
E. M. Reingold and N. Dershowitz for their Calendrical Calculations book and Calendrica program code, which serves as the base for the Bikrami calculations done in this library.
-
My father, Jasjit Singh, whose curiosity in the Nanakshahi and Bikrami calendar systems inspired me find answers to his technical questions.
Contributing
We're happy to accept suggestions and pull requests!
To get started, clone this repo and run npm install
inside this directory.
This repository follows the Airbnb's Javascript Style Guide, with a few minor modifications. Notably, spaces should be included inside parentheses and brackets (weird, right!). An ESLint file is provided,
and your code will automatically be checked on-commit for style.
It is recommended to install an ESLint plugin for your editor (VS Code's ESLint
plugin works out of the box), so you can receive
linter suggestions as you type.
When writing commit messages, please follow the seven rules.
Markdown and HTML JSDoc documentation is generated automatically, on commit,
however if you'd like to preview any changes to documentation, npm run build-docs
will
update README.md
. README.md
should not be edited, instead apply modifications to README.hbs
.
The general workflow for contributing:
- Fork/create a new branch.
- Write or update existing tests with expected results
- Implement functions/changes
- Add JSDoc function documentation and examples.
- Create a pull request with the changes.