Похожие чаты

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

43 просмотра

Стикер

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта