is odd or even based on the first week?
I'm absolutely terrible at working with dates so I don't even know how to test it and make sure it'll calculate the weeks correctly. My uni said the first week was even so as for now, it's calculating it correctly
* Do I need to calculate this based on our local date time? I don't really care about seconds of accuracy, I just need a simple even or odd
function determineWeek() {
const startDate = Date.parse("2024-03-30"); // was: "EVEN"
const currentDate = new Date().getTime();
const elapsedTime = currentDate - startDate;
const elapsedDays = Math.floor(
elapsedTime / (1000 * 60 * 60 * 24)
);
const currentWeekNumber = Math.floor(elapsedDays / 7);
return currentWeekNumber % 2 === 0 ? "EVEN" : "ODD";
}
No. Each year has 52 weeks, if the first week is odd, then the next week will be even and so on... So in our calendar, the first week of the new year was odd, the next was even, and the current week is odd. Basically I need it to tell me whether the current week is an odd or even week. * If someone is curious as why I need this, it's for my uni. Depending on the week being odd or even, we have different schedules. And usually I forget whether I'm in an odd or even week and I kinda have trust issues so I don't really trust previous data and want to make sure I'm correct about this week
is the start date relevant? from my understanding first week is always odd as it is week 1
https://t.me/thedevs_js/549554
Then its a simple (dayOfYear / 7) % 2 === 0 calculation
Обсуждают сегодня