riku
2024-11-13 af930887f9972b7dd21c80599e697e44f5e5a579
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 };