|
1 | 1 | 'use client'
|
2 | 2 |
|
3 | 3 | 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 |
8 | 9 |
|
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)) |
11 | 13 |
|
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 | + } |
16 | 18 |
|
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) |
19 | 21 |
|
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) |
28 | 28 |
|
29 | 29 | return (
|
30 | 30 | <span className="font-medium">
|
31 |
| - {date.toLocaleDateString('en-US', { |
| 31 | + {nextStammtisch.toLocaleDateString('en-US', { |
32 | 32 | weekday: 'long',
|
33 | 33 | year: 'numeric',
|
34 | 34 | month: 'long',
|
|
0 commit comments