Похожие чаты

Is this a correct way to determine if a week

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";
}

7 ответов

11 просмотров

Стикер

Senator- Автор вопроса

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

Стикер

Senator
No. Each year has 52 weeks, if the first week is o...

is the start date relevant? from my understanding first week is always odd as it is week 1

Senator- Автор вопроса
Senator
https://t.me/thedevs_js/549554

Then its a simple (dayOfYear / 7) % 2 === 0 calculation

Похожие вопросы

Обсуждают сегодня

читать файл максимально быстро? странный вопрос))
zamtmn
50
Посоветуйте пожалуйста аудио плеер для библиотеки mp3- FLAC на компьютере. На Винде пользовался Aimp, в том числе для конвертации. Много нужных команд было прямо в контекст...
Виктор Кузнецов
31
Guys is any possible go up? Shib
Prem Kumar
21
Ajeeb aadmi hai, isko padhna nahi aata kya?
Jay Bansal
43
@LGCYMan @JustinKKW Q/A List 1. this part confuses me on #8: "From there, a bridge between erc20 LGXY and erc20 LGXY will be out once that swap is closed." does this mean ...
Sig | LGXY | BattleVerse L1 | BitWin
1
How can I install a driver downloaded from NVIDIA website on my Linux Debian?
Mehrshad
17
у меня такой вопрос про память в x86 возник, может кто пояснить?.. у процессора есть (как минимум) 3 типа адресов (названия "п1", "п2", "п3" --- мои, чтобы проще было дальше)...
Toideng
5
Would the removal of government imposed taxes across the board destroy a functioning society?
yehcool
13
Does anyone know if it's possible to upload a website that will never be able to be taken down by any government entity?
yehcool
10
А какие расширения активно используются в промышленности? Именно идейные, по типу гадт, а не всякие оверлоадедстрингс
Степан
10
Карта сайта