A few javascript functions for converting Vikram Samvat / Nepali and Gregorian calendar systems to each other.
Vikram Samvat (Hindi: विक्रम सम्वत्, Nepali: विक्रम सम्वत्) (abbreviated as V.S. (or VS) or B.S. (or BS)) is the historical Hindu calendar of India and Nepal. It uses lunar months and solar sidereal year (see: Vedic time keeping). It is used as the official calendar in Nepal. Read more on Wikipedia.
Calendar conversion is based on the JSON Data exposed as "NepaliCalendarData"
Calendar range from 2000 BS to 2090 BS
- Add more tests
- Adding support for more years
- Removing the json file and automating calendar conversions using some algorithm. Currently exploring : www.cc.kyoto-su.ac.jp/~yanom/sanskrit/pancanga/ for this purpose.
Please send your pull requests in so that this library can become better and more useful.
Use npm
to install:
$ npm install --save nepali-calendar-js
Then import it:
var nepali = require('nepali-calendar-js')
Converts a Gregorian date to Nepali.
nepali.toNepali(1943,4, 14) // { ny: 2000, nm: 1, nd: 1 }
Converts a JavaScript Date object to Nepali.
nepali.toNepali(new Date(1995, 3, 11)) // { ny: 2051, nm: 11, nd: 27 }
Converts a Nepali date to Gregorian.
nepali.toGregorian(2010, 1, 19) // { gy: 1953, gm: 5, gd: 1 }
Checks whether a Nepali date is valid or not.
nepali.isValidNepaliDate(2000, 1, 32) // false
nepali.isValidNepaliDate(2050, 12, 19) // true
Is this a leap year or not?
nepali.isLeapNepaliYear(2008) // false
nepali.isLeapNepaliYear(2019) // true
Number of days in a given month in a Nepali year.
nepali.nepaliMonthLength(2000, 12) // 31
nepali.nepaliMonthLength(2090, 12) // 30
Converts a date of the Nepali calendar to the Julian Day number.
nepali.j2d(2010, 1, 19) // 2434499
Converts the Julian Day number to a date in the Nepali calendar.
nepali.d2j(2434499) // { ny: 2010, nm: 1, nd: 19 }
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.
nepali.g2d(2016, 4, 11) // 2457490
Calculates Gregorian and Julian calendar dates from the Julian Day number (ndn) for the period since ndn=-34839655 (i.e. the year -100100 of both calendars) to some millions years ahead of the present.
nepali.d2g(2457490) // { gy: 2016, gm: 4, gd: 11 }
This project was built from the great work done by @behrang who is behind jalaali-js project.
MIT