Skip to content

Commit 92a0887

Browse files
authored
Merge pull request #32 from department-of-decentralization/q9f/loop/stammtisch
stammtisch: add hour to the calculation in utc
2 parents 0214e24 + afd0d6a commit 92a0887

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

app/impressum/NextStammtisch.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
'use client'
22

33
export default function NextStammtisch() {
4-
const today = new Date()
5-
const yesterday = new Date(today.getDate() - 1)
6-
const currentMonth = today.getMonth()
7-
const currentYear = today.getFullYear()
4+
const currentDate = new Date()
5+
const currentMonth = currentDate.getUTCMonth()
6+
const currentYear = currentDate.getUTCFullYear()
7+
let nextStammtisch = new Date()
8+
let nextMonth = 0
89

9-
// Create date object for 1st of current month
10-
let date = new Date(currentYear, currentMonth, 1)
10+
do {
11+
// Create date object for 1st of current month
12+
nextStammtisch = new Date(Date.UTC(currentYear, currentMonth + nextMonth, 1))
1113

12-
// Find first Wednesday
13-
while (date.getDay() !== 3) {
14-
date.setDate(date.getDate() + 1)
15-
}
14+
// Find first Wednesday
15+
while (nextStammtisch.getUTCDay() !== 3) {
16+
nextStammtisch.setUTCDate(nextStammtisch.getUTCDate() + 1)
17+
}
1618

17-
// Add 2 weeks to get to 3rd Wednesday
18-
date.setDate(date.getDate() + 14)
19+
// Add 2 weeks to get to 3rd Wednesday
20+
nextStammtisch.setUTCDate(nextStammtisch.getUTCDate() + 14)
1921

20-
// If 3rd Wednesday already passed this month, move to next month
21-
if (date < yesterday) {
22-
date = new Date(currentYear, currentMonth + 1, 1)
23-
while (date.getDay() !== 3) {
24-
date.setDate(date.getDate() + 1)
25-
}
26-
date.setDate(date.getDate() + 14)
27-
}
22+
// Set start time to 21:00 UTC which is intentially a bit into the event
23+
nextStammtisch.setUTCHours(21)
24+
25+
// If Stammtisch already started/passed this month, move to next month
26+
nextMonth++
27+
} while (nextStammtisch < currentDate)
2828

2929
return (
3030
<span className="font-medium">
31-
{date.toLocaleDateString('en-US', {
31+
{nextStammtisch.toLocaleDateString('en-US', {
3232
weekday: 'long',
3333
year: 'numeric',
3434
month: 'long',

0 commit comments

Comments
 (0)