Coder Social home page Coder Social logo

sheetalgiri / nepali-calendar-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jalaali/jalaali-js

5.0 2.0 3.0 28 KB

Javascript functions for converting between Nepali and Gregorian calendar systems, Available as an NPM package: https://www.npmjs.com/package/nepali-calendar-js

Makefile 0.81% JavaScript 99.19%

nepali-calendar-js's Introduction

Nepali Calendar JavaScript

A few javascript functions for converting Vikram Samvat / Nepali and Gregorian calendar systems to each other.

About

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"

Limitations

Calendar range from 2000 BS to 2090 BS

Future Enhancement

  1. Add more tests
  2. Adding support for more years
  3. 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.

Request to other developers

Please send your pull requests in so that this library can become better and more useful.

Install

Node.js

Use npm to install:

$ npm install --save nepali-calendar-js

Then import it:

var nepali = require('nepali-calendar-js')

API

toNepali(gy, gm, gd)

Converts a Gregorian date to Nepali.

nepali.toNepali(1943,4, 14) // { ny: 2000, nm: 1, nd: 1 }

toNepali(date)

Converts a JavaScript Date object to Nepali.

nepali.toNepali(new Date(1995, 3, 11)) // { ny: 2051, nm: 11, nd: 27 }

toGregorian(ny, nm, nd)

Converts a Nepali date to Gregorian.

nepali.toGregorian(2010, 1, 19) // { gy: 1953, gm: 5, gd: 1 }

isValidNepaliDate(ny, nm, nd)

Checks whether a Nepali date is valid or not.

nepali.isValidNepaliDate(2000, 1, 32) // false
nepali.isValidNepaliDate(2050, 12, 19) // true

isLeapNepaliYear(ny)

Is this a leap year or not?

nepali.isLeapNepaliYear(2008) // false
nepali.isLeapNepaliYear(2019) // true

nepaliMonthLength(ny, nm)

Number of days in a given month in a Nepali year.

nepali.nepaliMonthLength(2000, 12) // 31
nepali.nepaliMonthLength(2090, 12) // 30

j2d(ny, nm, nd)

Converts a date of the Nepali calendar to the Julian Day number.

nepali.j2d(2010, 1, 19) // 2434499

d2j(ndn)

Converts the Julian Day number to a date in the Nepali calendar.

nepali.d2j(2434499) // { ny: 2010, nm: 1, nd: 19 }

g2d(gy, gm, gd)

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

d2g(ndn)

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 }

Acknowledgement

This project was built from the great work done by @behrang who is behind jalaali-js project.

License

MIT

nepali-calendar-js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.