date-chinese
Chinese Calendar
Chinese Calendar calculations with conversion from/ to Gregorian Date.
The module supports:
- conversion from Gregorian Date to Chinese Date and vice versa
- conversion from javascript Date object to Chinese Date and vice versa
- conversion from JDE to Chinese Date and vice versa
- calculation of chinese New Year for a given Gregorian year
- calculation of Qı̄ngmíng pure brightness festival
- calculation of solar terms (minor - Jiéqì / major - Zhōngqì)
- calculations of Korean, Vietnamese Calendar based on the Chinese but using a different meridian
- calculations of Japanese solar terms (sekki)
Note: Some calculations may take quite some time (> 40ms). Therefore
CalendarChinese
has a built in cache to store results of long running
calculations.
Table of Contents
Usage
Construct a new Chinese Date
Parameters
cycle: Number | Array | Object
, chinese 60 year cicle; if {Array}
than [cycle, year, ..., day]
year: Number
, chinese year in cycle
month: Number
, chinese month
leap: Number
, true
if leap month
day: Number
, chinese day
const CalendarChinese = require('date-chinese')
let cal = new CalendarChinese(78, 1, 10, true, 9)
cal.get()
CalenderChinese
uses an internal cache for long running calculations.
Use set()
to reuse cached results.
from Gregorian Date
The timezone of the Gregorian Date is Chinese Standard Time (Beijing Time for years less than 1929).
const CalendarChinese = require('date-chinese')
let cal = new CalendarChinese()
cal.fromGregorian(1984, 12, 1)
cal.cycle
cal.year
cal.month
cal.leap
cal.day
let [cycle, year, month, leap, day] = cal.get()
to Gregorian Date
Convert Chinese Date back to Gregorian Date
let cal = new CalendarChinese(78, 1, 10, true, 9)
let gdate = cal.toGregorian()
from Date
Calculate chinese calendar date from javascript Date object
let cal = new CalendarChinese()
let date = new Date('1984-12-01T00:00:00+08:00')
cal.fromDate(date)
let cdate = cal.get()
to Date
let cal = new CalendarChinese(78, 1, 10, true, 9)
let date = cal.toDate(date).toISOString()
Chinese New Year
const CalendarChinese = require('date-chinese')
let cal = new CalendarChinese()
let newYear = cal.newYear(1985)
cal.fromJDE(newYear)
let cdate = cal.get()
let gdate = cal.toGregorian()
let date = cal.toDate()
const julian = require('astronomia').julian
let date = new julian.CalendarGregorian().fromJDE(newYear).toDate()
Qı̄ngmíng
Pure brightness festival date
let cal = new CalendarChinese()
let qm = cal.qingming(1985)
cal.fromJDE(qm)
let cdate = cal.get()
let gdate = cal.toGregorian()
or using chinese cycle/ year
let cal = new CalendarChinese(78, 2)
let qm = cal.qingming()
cal.fromJDE(qm)
let cdate = cal.get()
let gdate = cal.toGregorian()
Solar Terms
let cal = new CalendarChinese()
let qm = cal.solarTerm(5, 1985)
cal.fromJDE(qm)
let cdate = cal.get()
let gdate = cal.toGregorian()
Zhōngqì - Major Solar Terms
let cal = new CalendarChinese()
let qm = cal.majorSolarTerm(3, 1985)
cal.fromJDE(qm)
let cdate = cal.get()
let gdate = cal.toGregorian()
Jiéqì - Minor Solar Terms
let cal = new CalendarChinese()
let qm = cal.minorSolarTerm(3, 1985)
cal.fromJDE(qm)
let cdate = cal.get()
let gdate = cal.toGregorian()
Japanese Calendar
Epoch start for the Japanese Calendar in unknown. So Chinese Epoch in 2636 BCE is wrongly used.
Sekki
const CalendarJapanese = require('date-chinese').CalendarJapanese
let cal = new CalendarJapanese()
let qm = cal.solarTerm(1, 2016)
cal.fromJDE(qm)
let gdate = cal.toGregorian()
Korean Calendar
Epoch start in 2333 BCE
const CalendarKorean = require('date-chinese').CalendarKorean
let cal = new CalendarKorean(73, 13, 11, false, 25)
let gdate = cal.toGregorian()
Vietnamese Calendar
Epoch start for the Vietnamese Calendar in unknown. So Chinese Epoch in 2636 BCE is maybe wrongly used.
const CalendarVietnamese = require('date-chinese').CalendarVietnamese
let cal = new CalendarVietnamese()
cal.fromGregorian(1985, 3, 22)
let cdate = cal.get()
let gyear = cal.yearFromEpochCycle()
Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your
code to be distributed under the MIT license. You are also implicitly
verifying that all code is your original work or correctly attributed
with the source of its origin and License.
License
Copyright (c) 2016 commenthol (MIT License)
See LICENSE for more info.
References