All files / src/utils DateUtils.ts

87.5% Statements 7/8
50% Branches 1/2
66.66% Functions 2/3
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 26 27            67x             67x 17x             67x 2x 2x 2x    
import dayjs from 'dayjs';
import { DateTimeFormat, TimeFormat } from '@config/base';
 
/**
 * 格式化日期
 */
export const formatDate = (dateString: string): string => {
  return dayjs(dateString)?.format(DateTimeFormat);
};
 
/**
 * 格式化时间
 */
export const formatTime= (dateString: string): string => {
  return dayjs(dateString)?.format(TimeFormat);
};
 
/**
 * 获取当前日期的周一
 * @param date
 */
export const getMonday = (date: Date): Date => {
  const day = date.getDay();
  const diff = date.getDate() - day + (day === 0 ? -6 : 1); // adjust when day is sunday
  return new Date(date.getFullYear(), date.getMonth(), diff);
};