Mohd-FaiZ-Jr / Menu-Mate

Menu Mate is a convenient app designed for ITER hostel residents. It allows users to easily view the daily mess menu and check tomorrow's menu in advance, helping them plan their meals ahead of time. Developed by Mandeep Ray & Mohammad Faiz
https://menumate.netlify.app
MIT License
1 stars 11 forks source link

Fix out the week calculation in Menu.js file in scripts folder. Ensure that it covers the edge cases. #3

Closed Mohd-FaiZ-Jr closed 1 week ago

Mohd-FaiZ-Jr commented 1 week ago

Task: Fix Week Calculation in Menu.js

Objective: Update the week calculation logic in the Menu.js file to ensure that it correctly calculates the current week number, constrained between 0-3. This change should account for edge cases such as leap years, transitions between months, and varying days in the week.

Requirements:

  1. Valid Week Range: The calculation must always return a week number in the range of 0 to 3 (inclusive), which means that any calculated week value outside this range should be handled appropriately (e.g., wrapping or capping the value).
  2. Edge Cases:
    • End of Month: Ensure the logic handles the transition between months (e.g., when a month ends mid-week).
    • Leap Year: Handle February in leap years properly (with 29 days) when calculating weeks.
    • Week Transition: Address situations where the first or last days of a month affect the current week calculation.

Suggested Fix:

  1. Refactor the existing week calculation logic.
  2. Ensure that it wraps or resets the week value when it exceeds 3 (i.e., Week 4 wraps back to Week 0).
  3. Add unit tests or manual test cases to validate against edge cases like:
    • Weeks that span across months.
    • Days around February 28th and 29th (in leap years).
    • Ensuring that calculations on different days return the correct week value.
Zish303 commented 1 week ago

@Mohd-FaiZ-Jr I have added a new logic to calculate the week number. Please review the changes.