riku
2024-08-14 b4033c002e21c1376d68be61622da56182a962e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 };