1.2.1 • Published 4 years ago

tibetan-date-calculator v1.2.1

Weekly downloads
8
License
MIT
Repository
gitlab
Last release
4 years ago

A Javascript library to calculate Tibetan calendrical dates according to the Phugpa tradition.

The calculations are basically implementation the formulas in Svante Janson, "Tibetan Calendar Mathematics". We are using year 806 as the epoch for all calculations. See the paper for details.

Installation

npm install tibetan-date-calculator

Usage

import { TibetanDate, TibetanMonth, TibetanYear }  from 'tibetan-date-calculator';

API

The API exposes 3 classes: TibetanDate, TibetanMonth, TibetanMonth

TibetanDate

tibDate = new TibetanDate(arg)

arg: undefined

This will return tibeatan date object for today.

arg: String

This will return tibetan date object for the wester date new Date(arg).

Note: using date string without time stamp (e.g. '2019-06-21') can create bugs when run in different timezones due to the way native Date object handles it. See Date documentation

arg: Object

This will return tibetan day according to object definition:

keystypedefaultdescription
yearnumberTibetan year number (ex. 2135)
monthnumberTibetan month number (1 to 12)
isLeapMonthbooleanfalseis this month a leap month (first of repeated months)
daynumberTibetan day number (1 to 30)
isLeapDaybooleanfalseis this day a leap day (first of repeated day)

Properties

These can be accessed directly tibDate.property

propertytypedescription
westernDateDatea JS Date object corresponding to this date
yearnumberTibetan year number (ex. 2135)
monthnumberTibetan month number (1 to 12)
datenumberTibetan date number (1 to 30)
daynumberday of the week, same as calling westernDate.getDay()
yearObjTibetanYear
monthObjTibetanMonth
isDoubledDayboolean
isLeapDayboolean
isSkippedDaybooleanis this date skipped in the Tibetan calendar
isPreviousSkippedbooleanis the previous date skipped (e.g. date=3 is 2 skipped)
westernDateStrstringYYYY-MM-DD

Methods

TibetanDate exposes a set of methods to mimic the native Date behaviour.

methodreturnsdescription
getWesternDate()Datesame as the property westernDate
getYear()numbersame as the property year
getMonth()numbersame as the property month
getDate()numbersame as the property date
getDay()numbersame as the property day
getMonthObj()TibetanMonthsame as the property monthObj
getYearObj()TibeatnYearsame as the property yearObj
toString()stringreturns 'year-month(-leap/-main)-date(-leap/-main)'

TibetanMonth

tibMonth = new TibetanMonth(arg)

arg: undefined

This will return tibeatan month object that includes today.

arg: String

This will return tibetan month object that includes the wester date new Date(arg).

arg: Object

This will return tibetan month according to object definition:

keystypedefaultdescription
yearnumberTibetan year number (ex. 2135)
monthnumberTibetan month number (1 to 12)
isLeapMonthbooleanfalseis this month a leap month (first of repeated months)

Properties

These can be accessed directly tibDate.property

propertytypedescription
yearnumberTibetan year number (ex. 2135)
monthnumberTibetan month number (1 to 12)
isLeapMonthbooleanis this month a leap month (first of repeated months)
isDoubledMonthbooleanis this month doubled (either leap or main)
startDateStrstringwestern date string for the first date of the month
endDateStrstringwestern date string for the last date of the month
yearObjTibetanYearTibetanYear object
daysTibetanDate[]list of days in the month, skipped days are not included. Need to call getDays() on the instance at least once to calculate it
toString()stringreturns 'year-month(-leap/-main)'

Methods

methodreturnsdescription
getDays()TibetanDate[]generates an array of TibetanDays within this month, excluding skipped days. Once called, the days property will be populated too.

TibetanYear

tibYear = new TibetanYear(arg, isWestern = false)

arg: undefined

This will return tibeatan year object that includes today.

arg: Number

This will return tibetan year passed, unless isWestern is set to true. In that case the arg will be interpreted as a western year number.

arg: Object

This will return tibetan year according to rabjung year definition:

keystypedescription
rabjungCyclenumberThe rabjung cycle number
rabjungYearnumberThe year within the cycle (1 - 60)

Properties

These can be accessed directly tibDate.property

propertytypedescription
rabjungCyclenumber
rabjungYearnumber
tibYearNumnumber
westernYearnumber
animalstring
elementstring
genderstring
monthsTibetanMonth[]need to call getMonth() on the instance at least once to calculate it

Methods

methodreturnsdescription
getMonths()TibetanMonth[]generates an array of TibetanMonth within this year. Once called, the months property will be populated too.
toRabjungString()stringreturns 'The X. year of the Y. rabjung cycle'
toString()stringreturns the Tibetan year number as string

Examples

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago