@marchingy/lunar
v0.1.1
Published
Chinese calendar with the 24 solar terms.
Downloads
36
Readme
Lunar (Chinese calendar)
The standard mentioned below which means GB/T 33661-2017 - Calculation and promulgation of the Chinese calendar. The lunar mentioned below which means this library.
All algorithms in the package are according to the standard to be implemented. And used ephemeris to calculate sun ecliptic longitude and moon ecliptic longitude.
Some earlier dates might not are satisfied with the outputs of the lunar, the lunar use astronomy algorithms to reach high-precision results. Like 8/25/1919 and 1/25/1944, these dates were the first dates of the lunar months in the real history, but they are not new moons according to astronomy algorithms. and 8/26/1919 and 1/26/1944 were new moons, they should were the first dates.
Including:
- Calculate the solar term of a day, solar terms of year, 24 solar terms;
- Calculate month and day of Chinese calendar, and leap months;
- Calculate sexagesimal(celestial stem with terrestrial branch) of day, month and year;
- Calculate zodiac of year.
API
class ChineseDate(inherit native Date)
Methods
- getLunarYear(): OLunarYear
- getLunarMonth(): OLunarMonth
- getLunarDay(): OLunarDay
- toChineseString(): string | A date locale string in zh-CN language in PRC time zone
- toLunarString(): string | example: 农历壬寅年九月甲申日
inteface OLunarYear
- sexagesimal(): string | example: 壬寅
- zodiac(): string | example: 虎
- toString(): string | example: 壬寅年 虎年
inteface OLunarMonth
- capital(): string | example: 九
- isLeap(): boolean
- sexagesimal(): string | example: 己酉
- toString(): string | example: 己酉月 九月
inteface OLunarDay
- capital(): string | example: 初十
- sexagesimal(): string | example: 甲申
- toString(): string | example: 癸亥日 初九
Calendar tools
- countDaysOnYear(year: number): number
- isNewMoon(date: Date): boolean
- countNewMoons(fromDate: Date, toDate: Date): Array
- getWinterSolstice(year: number): Date
- isMissingMidTermMonth(date: Date): boolean
- isLeapMonth(date: Date): boolean
Solar terms
class SolarTerm
Constructor
constructor(public readonly order: number, public readonly longitude: number, public label: string) The parameter "order" must be an integer from 1 to 24. The parameter "longitude" must be an integer from 0 to 360, and must be in multiples of 15.
Properties
- date: ChineseDate | undefined
- label: string
- readonly order: number
- readonly longitude: number
Methods
- isMidTerm(): boolean
- toString(): string
- static create(index: number[, lang: Array]): SolarTerm | index is an integer from 1 to 24.
create24SolarTerms([lang: Array]): Map<number, SolarTerm>
getTermOnDay(date: Date[, coordinate: GeoJSON.Position]): SolarTerm | null
countSolarTerms(fromDate: Date, toDate: Date): Array
getTermsOnYear(year: number[, coordinate: GeoJSON.Position]): Array
calcSunEclipticLongitude(time: Date[, coordinate: GeoJSON.Position]): number
Calculate sun ecliptic longitude at the time.
calcMoonEclipticLongitude(time: Date[, coordinate: GeoJSON.Position]): number
Calculate moon ecliptic longitude at the time.
calcDiffOfSunAndMoon(time: Date[, coordinate: GeoJSON.Position]): number
Calculate different value between sun ecliptic longitude at the time and moon ecliptic longitude at the time.
Note: the default coordinate parameter is [120, 0].