绩效考核手机版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
969 B

3 years ago
import isValidDate from './isValidDate';
import parseDate from './parseDate';
import formatDate from './formatDate';
/**
* @description: 格式化日期为今天明天后天周几
* @param {Date | String | Number} date
* @param {Number} num 0,1,2,3
* @return {String}
* @example formatDay(new Date())
*/
export default function formatDay(date, num) {
if (!isValidDate((date = parseDate(date)))) return '';
num = parseInt(num) || 1;
const nowTime = new Date(formatDate(new Date(), 'YYYY/MM/DD')).getTime();
const dayTime = 24 * 60 * 60 * 1000;
const dateTime = new Date(formatDate(date, 'YYYY/MM/DD')).getTime();
const dayName = (
[
{ label: '今天', value: nowTime },
{ label: '明天', value: nowTime + dayTime },
{ label: '后天', value: nowTime + dayTime * 2 },
]
.slice(0, num)
.find(item => item.value == dateTime) || { label: '' }
).label;
return formatDate(date, `${dayName || '周E'}`);
}