Skip to content

Commit

Permalink
fix: update first day logic for months starting on Sunday (#3896)
Browse files Browse the repository at this point in the history
* Update calendar logic to accomodate for months starting on Sunday

* Apply suggestions from code review

---------

Co-authored-by: boojack <stevenlgtm@gmail.com>
  • Loading branch information
RoccoSmit and boojack authored Sep 9, 2024
1 parent 05d5fb4 commit f695e93
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion web/src/components/ActivityCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ActivityCalendar = (props: Props) => {
const year = dayjs(monthStr).toDate().getFullYear();
const month = dayjs(monthStr).toDate().getMonth() + 1;
const dayInMonth = new Date(year, month, 0).getDate();
const firstDay = (new Date(year, month - 1, 1).getDay() - weekStartDayOffset) % 7;
const firstDay = ((new Date(year, month - 1, 1).getDay() - weekStartDayOffset) % 7 + 7) % 7;

Check failure on line 42 in web/src/components/ActivityCalendar.tsx

View workflow job for this annotation

GitHub Actions / static-checks

Replace `new·Date(year,·month·-·1,·1).getDay()·-·weekStartDayOffset)·%·7` with `(new·Date(year,·month·-·1,·1).getDay()·-·weekStartDayOffset)·%·7)`
const lastDay = new Date(year, month - 1, dayInMonth).getDay() - weekStartDayOffset;
const WEEK_DAYS = [t("days.sun"), t("days.mon"), t("days.tue"), t("days.wed"), t("days.thu"), t("days.fri"), t("days.sat")];
const weekDays = WEEK_DAYS.slice(weekStartDayOffset).concat(WEEK_DAYS.slice(0, weekStartDayOffset));
Expand Down

0 comments on commit f695e93

Please sign in to comment.