src/deltat.js
function monthOfYear (dyear) {
  if (!monthOfYear.data) { // memoize yearly fractions per month
    monthOfYear.data = {0: [], 1: []}
    for (let m = 0; m <= 12; m++) {
      monthOfYear.data[0][m] = new Calendar(1999, m, 1).toYear() - 1999 // non leap year
      monthOfYear.data[1][m] = new Calendar(2000, m, 1).toYear() - 2000 // leap year
    }
  }
  const year = dyear | 0
  const f = dyear - year
  const d = LeapYearGregorian(year) ? 1 : 0
  const data = monthOfYear.data[d]

  let month = 12 // TODO loop could be improved
  while (month > 0 && data[month] > f) {
    month--
  }
  const first = year + data[month]
  const last = month < 11 ? year + data[month + 2] : year + 1 + data[(month + 2) % 12]
  return {year, month, first, last}
}
function monthOfYear (dyear) {
  if (!monthOfYear.data) { // memoize yearly fractions per month
    monthOfYear.data = {0: [], 1: []}
    for (let m = 0; m <= 12; m++) {
      monthOfYear.data[0][m] = new Calendar(1999, m, 1).toYear() - 1999 // non leap year
      monthOfYear.data[1][m] = new Calendar(2000, m, 1).toYear() - 2000 // leap year
    }
  }
  const year = dyear | 0
  const f = dyear - year
  const d = LeapYearGregorian(year) ? 1 : 0
  const data = monthOfYear.data[d]

  let month = 12 // TODO loop could be improved
  while (month > 0 && data[month] > f) {
    month--
  }
  const first = year + data[month]
  const last = month < 11 ? year + data[month + 2] : year + 1 + data[(month + 2) % 12]
  return {year, month, first, last}
}
function monthOfYear ( dyear ) { if ( ! monthOfYear . data ) { // memoize yearly fractions per month monthOfYear . data = { 0 : [ ] , 1 : [ ] } for ( let m = 0 ; m <= 12 ; m ++ ) { monthOfYear . data [ 0 ] [ m ] = new Calendar ( 1999 , m , 1 ) . toYear ( ) - 1999 // non leap year monthOfYear . data [ 1 ] [ m ] = new Calendar ( 2000 , m , 1 ) . toYear ( ) - 2000 // leap year } } const year = dyear | 0 const f = dyear - year const d = LeapYearGregorian ( year ) ? 1 : 0 const data = monthOfYear . data [ d ] let month = 12 // TODO loop could be improved while ( month > 0 && data [ month ] > f ) { month -- } const first = year + data [ month ] const last = month < 11 ? year + data [ month + 2 ] : year + 1 + data [ ( month + 2 ) % 12 ] return { year , month , first , last } }
Get month of Year from fraction. Fraction differs at leap years.
@private
@param {Number} dyear - decimal year
@return {Object} `{year: Number, month: Number, first: Number, last}`
Get month of Year from fraction . Fraction differs at leap years .