In vue, I wrote a js to return the year, month and day from 2018 to 2100, but found that there were only 28 days in leap years.

here is the code:

range.js

export default function (n, m, polyfill = false, unit = "") {
  let arr = []
  for (let i = n; i <= m; iPP) {
    let value = (polyfill && i < 10 ? "0" + i : i) + unit
    arr.push(value)
  }
  return arr
}

date.js

import range from "./range";

function isLeapYear(y) {
  return y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
}

function getDays(y, m) {
  y = Number(y);
  m = Number(m);
  let endDay = null;
  switch (m) {
    case 2:
      endDay = isLeapYear(y) ? 29 : 28;
      break;
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      endDay = 31;
      break;
    case 4:
    case 6:
    case 9:
    case 11:
    default:
      endDay = 30;
      break;
  }
  const days = range(1, endDay, false);
  return days.map(day => {
    return {
      value: ("0" + day).length > 2 ? ("0" + day).substring(1) : "0" + day
    };
  });
}

const yearData = range(START_YEAR, END_YEAR, false);
const monthData = range(1, 12, false);

const cascadeMonthData = monthData.map(month => {
  return {
    value: ("0" + month).length > 2 ? ("0" + month).substring(1) : "0" + month,
    children: []
  };
});

const dateData = yearData.map(year => {
  const item = {
    value: year,
    children: cascadeMonthData.slice()
  };
  item.children.forEach(month => {
    month.children = getDays(year, month.value);
  });
  return item;
});


console.log(dateData)

let value = (polyfill & & I < 10?'0' + i: i) + unit

change to
let value = (polyfill & & (I < 10?'0' + i: i)) + unit

)

value: ("0" + month). Length > 2? ("0" + month) .substring (1): "0" + month
change
value: ("0" + month) > 2? (("0" + month). Substring (1)): ("0" + month)),

)

operational priority


found the answer because map returns an array and references an object with an address. Refer to the result

of .
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36b7b-2c04e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36b7b-2c04e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?