Skip to content

Commit

Permalink
fix: add CURRENT_MONDAY constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Sep 24, 2024
1 parent 0ebdf29 commit d6d950f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/helpers/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { dateToDayjs, getMonday, timeToDayjs } from '../utils/date';

const MAX_DATE = dayjs('6666-06-06');
const MIN_DATE = dayjs('2005-03-12');
const CURRENT_MONDAY = getMonday(dayjs());

/**
* Get the start date (Monday) of the start and end week
Expand All @@ -25,8 +26,7 @@ const MIN_DATE = dayjs('2005-03-12');
export const getStartEndWeek = (
dates: Array<{ start: string; end: string }>,
): [dayjs.Dayjs, dayjs.Dayjs] => {
const currentMonday = getMonday(dayjs());
if (dates.length === 0) return [currentMonday, currentMonday];
if (dates.length === 0) return [CURRENT_MONDAY, CURRENT_MONDAY];

let startWeek = MAX_DATE;
let endWeek = MIN_DATE;
Expand Down Expand Up @@ -119,7 +119,7 @@ export const useCalendar = () => {
);
const [startWeek, endWeek] = getStartEndWeek(dates);

const [currentWeek, setCurrentWeek] = useState(getMonday(dayjs()));
const [currentWeek, setCurrentWeek] = useState(CURRENT_MONDAY);

useEffect(() => {
if (currentWeek.isBefore(startWeek)) {
Expand Down

0 comments on commit d6d950f

Please sign in to comment.