export function getInputQuarter() {
// 首先通过解构赋值将每个季度第一个月的月份存储在一个数组中
// 获取当前月份并计算出它属于哪个季度。最后使用数组和indexOf方法来找到对应的季度编号
const currentMonth = new Date().getMonth() + 1;
const [firstMonth, secondMonth, thirdMonth, fourthMonth] = [1, 4, 7, 10];
const normalQuarter = Math.floor((currentMonth % 3 == 0 ? (currentMonth / 3) : (currentMonth / 3 + 1))); // 其它月份
const quarter = [4, 1, 2, 3][[firstMonth, secondMonth, thirdMonth, fourthMonth].indexOf(currentMonth) % 4]; //季度初
return quarter ? quarter : normalQuarter;
}
根据当前月份确定季度,每季度的第一个月显示为上季度
最新推荐文章于 2024-06-07 23:26:45 发布