0

I make use of a own employee schedule system and it works great for 3 years. Now this year a new bug appears :). We work with week days and the systeem calculates current date + 7 days to calculate the next week. If you check on a sunday in december (e.g. 25-12-2022 is a sunday + 7 days) the schedule for week 52 you will find an error because 01-01-2023 is a sunday but the system says it is week 52 (so the schedule goes to week 52 of 2023 instead of week 52 of 2022).

    $('#nweek_availability').click(function(){
        setTimeout(function() {
            var week = $('.week-picker').val();
            var longs = Number(week.substr(1,2)) + 1;
            selectedDate = moment(new Date(year, month, day)).add(7, 'days').format('DD-MM-YYYY');
            if ((longs < 53) && (longs > 0)) {
                $('.nortifi-pick-week').attr('hidden', true)
                location.replace("./schedule.php?page=employee-availability&week=" + longs + "&date=" + selectedDate);
            }
            else{
                $('.nortifi-pick-week').attr('hidden', false)
            }
        }, 500);
    });

Maybe it is easier to calculate the first monday of the new week instead of current day + 7.

Did not find a solution yet to solve this but made some buttons with date that starts on monday for the next 6 weeks, so we can use buttons instead of next week arrow button so the problem doesn't show.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Mike
  • 3
  • 5
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 24 '22 at 12:35
  • The issue seems to be in the function that generates the week number, which your question doesn't show. There may be a suitable answer at [*Get week of year in JavaScript like in PHP*](https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php). Also note that some years have 53 weeks (e.g. 1 Jan 2021 was in week 53 of 2020). – RobG Nov 24 '22 at 14:10
  • Please close the topic. I fixed it with an if and else with the next week button. If week 51 is selected than next week is not +7 days but first monday of week 52 – Mike Nov 24 '22 at 14:53
  • You can delete the question. – RobG Nov 25 '22 at 05:27

0 Answers0