import dayjs from 'dayjs'; /** * 周期时段转日期 * @param {String} period YYYY/M-M,表示某年的某月至某月周期 */ function toTime(period) { const [year, months] = period.split('/'); const [month] = months.split('-'); return dayjs() .year(year) .month(parseInt(month) - 1) .date(1); } /** * 日期转周期时段 * @param {String} time 时间 */ function toPeriod(time) { const _time = time ? dayjs(time) : dayjs(); return `${_time.year()}/${_time.month() + 1}-${_time.month() + 1}`; } export { toTime, toPeriod };