How to use astronomia - 10 common examples

To help you get started, we’ve selected a few astronomia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commenthol / date-chinese / test / chinese.mocha.js View on Github external
/* globals describe, it */
/* eslint no-multi-spaces: 0 */

'use strict'

process.env.TZ = 'Asia/Shanghai'

const assert = require('assert')
const julian = require('astronomia').julian

const CalendarChinese = require('../src').CalendarChinese

function toDate (jde) {
  return new julian.Calendar().fromJDE(jde).toDate()
}

describe('#CalendarChinese', function () {
  describe('construction', function () {
    let cal
    let exp = [78, 1, 10, true, 9]
    it('can construct via new', function () {
      cal = new CalendarChinese(78, 1, 10, true, 9)
      assert.ok(cal instanceof CalendarChinese)
      assert.deepEqual(cal.get(), exp)
    })
github commenthol / date-chinese / test / korean.mocha.js View on Github external
/* globals describe, it */
/* eslint no-multi-spaces: 0 */

'use strict'

const assert = require('assert')
const julian = require('astronomia').julian

const CalendarKorean = require('../src').CalendarKorean

// process.env.TZ = 'Asia/Seoul'

describe('#CalendarKorean', function () {
  describe('newYear', function () {
    var tests = [
      '1985-02-20T00:00:00+0900',
      '1986-02-09T00:00:00+0900'
    ]
    var cal = new CalendarKorean()
    tests.forEach(function (t) {
      var date = new Date(t)
      it(t, function () {
        var y = date.getFullYear()
github commenthol / date-chinese / test / japanese.mocha.js View on Github external
/* globals describe, it */
/* eslint no-multi-spaces: 0 */

'use strict'

const assert = require('assert')
const julian = require('astronomia').julian

const CalendarJapanese = require('../src').CalendarJapanese

process.env.TZ = 'Asia/Tokyo'

describe('#CalendarJapanese', function () {
  describe('newYear', function () {
    var tests = [
      '1887-01-24T00:00:56+0920',
      '1888-02-12T00:00:00+0900',
      '1986-02-09T00:00:00+0900'
    ]
    var cal = new CalendarJapanese()
    tests.forEach(function (t) {
      var date = new Date(t)
      it(t, function () {
github commenthol / date-chinese / test / korean.mocha.js View on Github external
it(t, function () {
        var y = date.getFullYear()
        var jde = cal.newYear(y)
        var res = new julian.CalendarGregorian().fromJDE(jde).toDate()
        var td = new Date(t)
        var err = Math.abs(+res - +td)
        // test max error 2sec
        assert.ok(err < 1000, res.toISOString() + ' !== ' + t)
      })
    })
github commenthol / date-chinese / test / chinese.mocha.js View on Github external
it(y, function () {
        let cal = new CalendarChinese()
        let qm = cal.qingming(y)
        cal.fromJDE(qm)
        let gre = cal.toGregorian()
        assert.deepEqual(gre, test[1])
        // converting to Gregorian using jde
        let gcal = new julian.CalendarGregorian().fromJDE(qm)
        let ts = cal.timeshiftUTC(gcal)
        let date = new Date(+(gcal.toDate()) + ts * 86400000)
        assert.equal(date.toISOString(), test[2])
      })
    })
github commenthol / date-chinese / test / vietnamese.mocha.js View on Github external
it(t, function () {
        var y = date.getFullYear()
        var jde = cal.newYear(y)
        var res = new julian.CalendarGregorian().fromJDE(jde).toDate()
        var td = new Date(t)
        var err = Math.abs(+res - +td)
        // test max error 2sec
        assert.ok(err < 1000, res.toISOString() + ' !== ' + t)
      })
    })
github commenthol / date-chinese / test / vietnamese.mocha.js View on Github external
/* globals describe, it */
/* eslint no-multi-spaces: 0 */

'use strict'

const assert = require('assert')
const julian = require('astronomia').julian

const CalendarVietnamese = require('../src').CalendarVietnamese

// process.env.TZ = 'Asia/Ho_Chi_Minh'

describe('#CalendarVietnamese', function () {
  describe('newYear', function () {
    var tests = [
      '1967-02-09T00:00:00+0800',
      '1968-01-29T00:00:00+0700',
      '1985-01-21T00:00:00+0700', // this date is different to Chinese
      '1986-02-09T00:00:00+0700'
    ]
    var cal = new CalendarVietnamese()
    tests.forEach(function (t) {
      var date = new Date(t)
github commenthol / date-holidays-parser / src / Equinox.js View on Github external
let jde
    switch (this._season) {
      case 'march': {
        jde = solstice.march2(year, earth)
        break
      }
      case 'june': {
        jde = solstice.june2(year, earth)
        break
      }
      case 'september': {
        jde = solstice.september2(year, earth)
        break
      }
      case 'december': {
        jde = solstice.december2(year, earth)
        break
      }
    }

    const str = new julian.Calendar().fromJDE(jde).toDate().toISOString()
    let date
    if (/^[+-]\d{2}:\d{2}?$/.test(this._timezone)) { // for '+08:00' formats
      date = moment(str).utcOffset(this._timezone)
    } else { // for 'Asia/Shanghai' formats
      date = moment(str).tz(this._timezone) // move to timezone
    }

    const floorDate = {
      year: year,
      month: date.month() + 1,
      day: date.date()
github commenthol / date-holidays-parser / src / Equinox.js View on Github external
}
      case 'june': {
        jde = solstice.june2(year, earth)
        break
      }
      case 'september': {
        jde = solstice.september2(year, earth)
        break
      }
      case 'december': {
        jde = solstice.december2(year, earth)
        break
      }
    }

    const str = new julian.Calendar().fromJDE(jde).toDate().toISOString()
    let date
    if (/^[+-]\d{2}:\d{2}?$/.test(this._timezone)) { // for '+08:00' formats
      date = moment(str).utcOffset(this._timezone)
    } else { // for 'Asia/Shanghai' formats
      date = moment(str).tz(this._timezone) // move to timezone
    }

    const floorDate = {
      year: year,
      month: date.month() + 1,
      day: date.date()
    }

    const d = new CalDate(floorDate).setOffset(this.offset)
    this.dates.push(d)
    return this
github commenthol / date-holidays-parser / src / Equinox.js View on Github external
inYear (year) {
    let jde
    switch (this._season) {
      case 'march': {
        jde = solstice.march2(year, earth)
        break
      }
      case 'june': {
        jde = solstice.june2(year, earth)
        break
      }
      case 'september': {
        jde = solstice.september2(year, earth)
        break
      }
      case 'december': {
        jde = solstice.december2(year, earth)
        break
      }
    }

    const str = new julian.Calendar().fromJDE(jde).toDate().toISOString()
    let date
    if (/^[+-]\d{2}:\d{2}?$/.test(this._timezone)) { // for '+08:00' formats
      date = moment(str).utcOffset(this._timezone)