How to use the astronomia/lib/moonphase.meanLunarMonth function in astronomia

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 / lib / Chinese.js View on Github external
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * @copyright 2016 commenthol
 * @license MIT
 */

var base = require('astronomia/lib/base');
var solstice = require('astronomia/lib/solstice');
var solar = require('astronomia/lib/solar');
var moonphase = require('astronomia/lib/moonphase');
var planetpos = require('astronomia/lib/planetposition');
var julian = require('astronomia/lib/julian');

var earth = new planetpos.Planet(require('astronomia/data/vsop87Bearth.js'));
var lunarOffset = moonphase.meanLunarMonth / 2;
var p = 180 / Math.PI;

// Start of Chinese Calendar in 2636 BCE by Chalmers
var epochY = -2636;
var epoch = new julian.CalendarGregorian(epochY, 2, 15).toJDE();

function toYear(jde) {
  return new julian.CalendarGregorian().fromJDE(jde).toYear();
}

// prevent rounding errors
function toFixed(val, e) {
  return parseFloat(val.toFixed(e), 10);
}

var CalendarChinese = function () {
github commenthol / date-chinese / src / Chinese.js View on Github external
/**
 * @copyright 2016 commenthol
 * @license MIT
 */

// import {base, solstice, solar, moonphase, planetposition, julian, data} from 'astronomia' // TODO waiting for tree-shaking that works...
import base from 'astronomia/lib/base'
import solstice from 'astronomia/lib/solstice'
import solar from 'astronomia/lib/solar'
import moonphase from 'astronomia/lib/moonphase'
import planetposition from 'astronomia/lib/planetposition'
import julian from 'astronomia/lib/julian'
import dataEarth from 'astronomia/data/vsop87Bearth'

const earth = new planetposition.Planet(dataEarth)
const lunarOffset = moonphase.meanLunarMonth / 2
const p = 180 / Math.PI

// Start of Chinese Calendar in 2636 BCE by Chalmers
const epochY = -2636
const epoch = new julian.CalendarGregorian(epochY, 2, 15).toJDE()

function toYear (jde) {
  return new julian.CalendarGregorian().fromJDE(jde).toYear()
}

// prevent rounding errors
function toFixed (val, e) {
  return parseFloat(val.toFixed(e), 10)
}

export default class CalendarChinese {
github commenthol / date-chinese / lib / Chinese.js View on Github external
value: function newYear(gyear) {
      gyear = Math.trunc(gyear);
      if (this._cache.ny[gyear]) return this._cache.ny[gyear];

      var sue1 = this._cache.sue[gyear - 1] || solstice.december2(gyear - 1, earth);
      var sue2 = this._cache.sue[gyear] || solstice.december2(gyear, earth);
      this._cache.sue[gyear - 1] = sue1;
      this._cache.sue[gyear] = sue2;

      var m11n = this.previousNewMoon(this.midnight(sue2 + 1));
      var m12 = this.nextNewMoon(this.midnight(sue1 + 1));
      var m13 = this.nextNewMoon(this.midnight(m12 + lunarOffset));
      this.leapSui = Math.round((m11n - m12) / moonphase.meanLunarMonth) === 12;
      var ny = m13;

      if (this.leapSui && (this.isLeapMonth(m12) || this.isLeapMonth(m13))) {
        ny = this.nextNewMoon(this.midnight(m13 + moonphase.meanLunarMonth / 2));
      }
      this._cache.ny[gyear] = ny;
      return ny;
    }
github commenthol / date-chinese / src / Chinese.js View on Github external
_from (j, year) {
    let ny = this.newYear(year)
    if (ny > j) {
      ny = this.newYear(year - 1)
    }
    let nm = this.previousNewMoon(j)
    if (nm < ny) {
      nm = ny
    }

    const years = 1.5 + (ny - this._epoch) / base.BesselianYear
    this.cycle = 1 + Math.trunc((years - 1) / 60)
    this.year = 1 + Math.trunc((years - 1) % 60)

    this.month = this.inMajorSolarTerm(nm).term
    const m = Math.round((nm - ny) / moonphase.meanLunarMonth)
    if (m === 0) {
      this.month = 1
      this.leap = false
    } else {
      this.leap = this.isLeapMonth(nm)
    }

    if (m > this.month) {
      this.month = m
    } else if (this.leap) {
      this.month--
    }

    this.day = 1 + Math.trunc(toFixed(j, 3) - toFixed(nm, 3))
  }