NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/xe-utils/methods/date/getWhatYear.js
2023-09-14 14:47:11 +08:00

41 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var staticStrFirst = require('../static/staticStrFirst')
var staticStrLast = require('../static/staticStrLast')
var helperGetDateFullYear = require('./helperGetDateFullYear')
var getWhatMonth = require('./getWhatMonth')
var toStringDate = require('./toStringDate')
var isDate = require('../base/isDate')
/**
* 返回前几年或后几年的日期
*
* @param {Date} date 日期或数字
* @param {Number} year 年(默认当前年)、前几个年(数值)、后几个年(数值)
* @param {Number/String} month 获取哪月(null默认当前年)、年初(first)、年末(last)、指定月份0-11
* @return {Date}
*/
function getWhatYear (date, year, month) {
var number
date = toStringDate(date)
if (isDate(date)) {
if (year) {
number = year && !isNaN(year) ? year : 0
date.setFullYear(helperGetDateFullYear(date) + number)
}
if (month || !isNaN(month)) {
if (month === staticStrFirst) {
return new Date(helperGetDateFullYear(date), 0, 1)
} else if (month === staticStrLast) {
date.setMonth(11)
return getWhatMonth(date, 0, staticStrLast)
} else {
date.setMonth(month)
}
}
}
return date
}
module.exports = getWhatYear