All files time.ts

100% Statements 17/17
100% Branches 2/2
100% Functions 2/2
100% Lines 13/13

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 222x   2x 53x 53x   53x 53x 53x 178x   178x   125x 125x       2x 7x    
import moment from 'moment'
 
export const getAllDayBetween = (start: string, end: string, dateOfWeek: number): Date[] => {
  const dateStart = moment(start, 'DD/MM/YYYY')
  const dateEnd = moment(end, 'DD/MM/YYYY')
  // Find first day in date of week
  let i = (dateOfWeek - 1) % 7
  const dates: Date[] = []
  while (true) {
    const currentDate = dateStart.clone().day(i)
 
    if (currentDate.isAfter(dateEnd)) return dates
    // Check ngay dau tien
    if (currentDate.isSameOrAfter(dateStart)) dates.push(currentDate.toDate())
    i = i + 7
  }
}
 
export const formatDay = (date: Date) => {
  return moment(date).format('DD/MM/YYYY')
}