Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The features are:
not be correct as they are subject to the sighting of the moon)
- support for hebrew calendar from 1970 to 2100
- support for chinese calendar
- support for tibetan calendar

Happy holidays!

Expand Down
22 changes: 21 additions & 1 deletion docs/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This document describes the data contained within the files `holidays.yaml` and
* [Dates in Chinese calendar (lunar)](#dates-in-chinese-calendar-lunar)
* [Dates in Chinese calendar (solar)](#dates-in-chinese-calendar-solar)
* [Dates in Bengali Revised calendar](#dates-in-bengali-revised-calendar)
* [Dates in Tibetan calendar](#dates-in-tibetan-calendar)
* [Dates in Persian calendar](#dates-in-persian-calendar)
* [Equinox, Solstice](#equinox-solstice)
* [Different start-time for Fixed Date other than midnight](#different-start-time-for-fixed-date-other-than-midnight)
Expand Down Expand Up @@ -271,7 +272,7 @@ Where:

#### Dates in Chinese calendar (lunar)

Dates in the chines calendar can be attributed using the following rule:
Dates in the chinese calendar can be attributed using the following rule:

Rule: `chinese <cycle>-<year>-<month>-<leapmonth>-<day>`

Expand Down Expand Up @@ -316,6 +317,25 @@ Where:
- `bengali-revised 12-1` is the 1st day in the 12th month
- `bengali-revised 1425-1-1` is the 1st day in the first month of 1425 - equals 2018-04-14 in Gregorian date

#### Dates in Tibetan calendar

Dates in the tibetan lunar calendar can be attributed using the following rule:

Rule: `(tibetan|mongolian|bhutanese) <cycle>-<year>-<month>-<leapmonth>-<day>-<leapday>`

Where:
- `<cycle>` (optional) Tibetan cycle - current is 17
- `<year>` (optional) year in Tibetan cycle (1 ... 60)
- `<month>` (mandatory) lunar month
- `<leapmonth>` (mandatory) `0|1` - `1` means month is leap month
- `<day>` (mandatory) day of lunar month
- `<leapday>` (optional) `0|1` - `1` means day is leap day

**Examples**:

- `tibetan 01-0-01` is 1st day in the 1st lunar month
- `tibetan 17-33-01-1-06-1` is 6th leap day in the 1st leap lunar month in year 33 of 17th cycle

#### Dates in Persian calendar

Dates in the persian calendar can be attributed using the following rule:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"colors": true
},
"dependencies": {
"@hnw/date-tibetan": "^1.0.2",
"astronomia": "^4.1.1",
"caldate": "^2.0.5",
"date-bengali-revised": "^2.0.2",
Expand Down
9 changes: 9 additions & 0 deletions src/CalEventFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import Chinese from './Chinese.js'
// #ifndef nobengali
import BengaliRevised from './BengaliRevised.js'
// #endif
// #ifndef notibet
import Tibetan from './Tibetan.js'
// #endif

export default class CalEventFactory {
constructor (opts) {
Expand Down Expand Up @@ -61,6 +64,12 @@ export default class CalEventFactory {
case 'bengali-revised':
return new BengaliRevised(opts)
// #endif
// #ifndef notibetan
case 'tibetan':
case 'mongolian':
case 'bhutanese':
return new Tibetan(opts)
// #endif
default:
return new CalEvent(opts)
}
Expand Down
21 changes: 21 additions & 0 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const grammar = (function () {
chineseLunar: /^(chinese|korean|vietnamese) (?:(\d+)-(\d{1,2})-)?(\d{1,2})-([01])-(\d{1,2})/,
chineseSolar: /^(chinese|korean|vietnamese) (?:(\d+)-(\d{1,2})-)?(\d{1,2})-(\d{1,2}) solarterm/,
bengaliRevised: /^(bengali-revised) (?:-?0*(\d{1,4})-)?0?(\d{1,2})-0?(\d{1,2})/,
tibetanLunar: /^(tibetan|mongolian|bhutanese) (?:(\d+)-(\d{1,2})-)?(\d{1,2})-([01])-(\d{1,2})(?:-([01]))?/,

modifier: /^(substitutes|and|if equal|then|if)\b/,
rule_year: /^(?:in (even|odd|leap|non-leap) years|every (\d+) years? since 0*(\d{1,4}))/,
Expand Down Expand Up @@ -182,6 +183,7 @@ export default class Parser {
'_chineseSolar',
'_chineseLunar',
'_bengaliRevised',
'_tibetanLunar',
'_dateMonth',
'_ruleDateIfThen',
'_ruleWeekday',
Expand Down Expand Up @@ -422,6 +424,25 @@ export default class Parser {
}
}

_tibetanLunar (o) {
let cap
if ((cap = grammar.tibetanLunar.exec(o.str))) {
this._shorten(o, cap[0])
cap.shift()
const res = {
fn: cap.shift(),
cycle: toNumber(cap.shift()),
year: toNumber(cap.shift()),
month: toNumber(cap.shift()),
leapMonth: !!toNumber(cap.shift()),
day: toNumber(cap.shift()),
leapDay: !!toNumber(cap.shift()),
}
this.tokens.push(res)
return true
}
}

_dateMonth (o) {
let cap
if ((cap = grammar.dateMonth.exec(o.str))) {
Expand Down
39 changes: 39 additions & 0 deletions src/Tibetan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
CalendarTibetan,
CalendarMongolian,
CalendarBhutanese
} from '@hnw/date-tibetan';
import CalEvent from './CalEvent.js'
import CalDate from 'caldate'

export default class Tibetan extends CalEvent {
/**
* @param {object} [opts]
*/
constructor (opts) {
opts = opts || {}
super(opts)
switch (opts.fn) {
case 'tibetan':
this.cal = new CalendarTibetan()
break
case 'mongolian':
this.cal = new CalendarMongolian()
break
case 'bhutanese':
this.cal = new CalendarBhutanese()
break
}
}

inYear (year) {
let d
let date
const opts = this.opts
this.cal.set(opts.cycle, opts.year, opts.month, opts.leapMonth, opts.day, opts.leapDay)
date = this.cal.toGregorian(year)
d = new CalDate(date)
this.dates.push(d)
return this
}
}
79 changes: 70 additions & 9 deletions test/DateFn.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,78 @@ describe('#DateFn', function () {
}]
assert.deepStrictEqual(fixResult(res), exp)
})

it('bengali-revised 12-1', function () {
const fn = new DateFn('bengali-revised 12-1')
const res = fn.inYear(2015).get()
const exp = [{
date: '2015-03-15 00:00:00',
start: 'sun 2015-03-15 00:00',
end: 'mon 2015-03-16 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
})
})

it('bengali-revised 12-1', function () {
const fn = new DateFn('bengali-revised 12-1')
const res = fn.inYear(2015).get()
const exp = [{
date: '2015-03-15 00:00:00',
start: 'sun 2015-03-15 00:00',
end: 'mon 2015-03-16 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
describe('tibetan', function () {
it('tibetan 1-0-1', function () {
const fn = new DateFn('tibetan 1-0-1')
const res = fn.inYear(2003).get()
const exp = [{
date: '2003-03-03 00:00:00',
start: 'mon 2003-03-03 00:00',
end: 'tue 2003-03-04 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
})

it('mongolian 1-0-1', function () {
const fn = new DateFn('mongolian 1-0-1')
const res = fn.inYear(2003).get()
const exp = [{
date: '2003-02-02 00:00:00',
start: 'sun 2003-02-02 00:00',
end: 'mon 2003-02-03 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
})

it('bhutanese 1-0-1', function () {
const fn = new DateFn('bhutanese 1-0-1')
const res = fn.inYear(2003).get()
const exp = [{
date: '2003-03-04 00:00:00',
start: 'tue 2003-03-04 00:00',
end: 'wed 2003-03-05 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
})

it('tibetan 12-0-17-1', function () {
const fn = new DateFn('tibetan 12-0-17-1')
const res = fn.inYear(2013).get()
const exp = [{
date: '2013-01-28 00:00:00',
start: 'mon 2013-01-28 00:00',
end: 'tue 2013-01-29 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
})
it('twice tibetan 11-0-15 in gregorian year 2012', function () {
const fn = new DateFn('tibetan 11-0-15')
const res = fn.inYear(2012).get()
const exp = [{
date: '2012-01-09 00:00:00',
start: 'mon 2012-01-09 00:00',
end: 'tue 2012-01-10 00:00'
}, {
date: '2012-12-28 00:00:00',
start: 'fri 2012-12-28 00:00',
end: 'sat 2012-12-29 00:00'
}]
assert.deepStrictEqual(fixResult(res), exp)
})

})
})

Expand Down
33 changes: 33 additions & 0 deletions test/fixtures/parser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,39 @@ module.exports = {
year: undefined
}
],
'tibetan 01-0-01': [
{
fn: 'tibetan',
day: 1,
month: 1,
leapMonth: false,
leapDay: false,
year: undefined,
cycle: undefined,
}
],
'mongolian 01-1-01': [
{
fn: 'mongolian',
day: 1,
month: 1,
leapMonth: true,
leapDay: false,
year: undefined,
cycle: undefined,
}
],
'bhutanese 01-1-01-1': [
{
fn: 'bhutanese',
day: 1,
month: 1,
leapMonth: true,
leapDay: true,
year: undefined,
cycle: undefined,
}
],
'1 day before vietnamese 01-0-01': [
{
fn: 'vietnamese',
Expand Down