Похожие чаты

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 ответов

36 просмотров

Стикер

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

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

Стикер

Anon
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

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

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

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта