@@ -110,12 +110,35 @@ const calendarApiUrl = withBase('/api/calendar.json')
110110 })
111111
112112 const weekdayFormatter = new Intl.DateTimeFormat(locale, { weekday: 'short' })
113+ const vigoTimezone = 'Europe/Madrid'
113114
114115 const getDateKey = (date) => `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`
115116 const keyToDate = (key) => {
116117 const [year, month, day] = key.split('-').map(Number)
117118 return new Date(year, month, day)
118119 }
120+ const getTimezoneDateParts = (date, timeZone) => {
121+ const parts = new Intl.DateTimeFormat('en-CA', {
122+ timeZone,
123+ year: 'numeric',
124+ month: '2-digit',
125+ day: '2-digit',
126+ }).formatToParts(date)
127+
128+ return {
129+ year: Number(parts.find((part) => part.type === 'year')?.value),
130+ month: Number(parts.find((part) => part.type === 'month')?.value) - 1,
131+ day: Number(parts.find((part) => part.type === 'day')?.value),
132+ }
133+ }
134+ const getTimezoneDateKey = (date, timeZone) => {
135+ const { year, month, day } = getTimezoneDateParts(date, timeZone)
136+ return `${year}-${month}-${day}`
137+ }
138+ const getDayStamp = (key) => {
139+ const [year, month, day] = key.split('-').map(Number)
140+ return Date.UTC(year, month, day)
141+ }
119142
120143 const getEventsByDay = (events) => {
121144 const map = new Map()
@@ -197,6 +220,9 @@ const calendarApiUrl = withBase('/api/calendar.json')
197220
198221 const eventsByDay = getEventsByDay(events)
199222 const eventDays = new Set(eventsByDay.keys())
223+ const now = new Date()
224+ const todayKey = getTimezoneDateKey(now, vigoTimezone)
225+ const todayStamp = getDayStamp(todayKey)
200226
201227 calendarGrid.innerHTML = ''
202228
@@ -223,6 +249,8 @@ const calendarApiUrl = withBase('/api/calendar.json')
223249 if (inMonth) {
224250 const key = getDateKey(currentDate)
225251 const hasEvents = hasEventsOnDate(eventsByDay, key)
252+ const isToday = key === todayKey
253+ const isPastDate = getDayStamp(key) < todayStamp
226254 dayCell.textContent = String(currentDate.getDate())
227255 dayCell.classList.remove('text-[var(--ink-soft)]')
228256 dayCell.classList.add('text-[var(--ink)]')
@@ -240,14 +268,27 @@ const calendarApiUrl = withBase('/api/calendar.json')
240268 }
241269
242270 if (eventDays.has(key)) {
243- dayCell.classList.add('bg-primary', 'font-semibold', 'text-white')
271+ if (isPastDate) {
272+ dayCell.classList.add('bg-primary-past', 'font-semibold', 'text-white')
273+ } else {
274+ dayCell.classList.add('bg-primary', 'font-semibold', 'text-white')
275+ }
244276 } else {
245277 dayCell.classList.add('bg-[var(--bg-panel)]/65')
246278 }
247279
248280 if (selectedDateKey === key) {
249281 dayCell.classList.add('ring-2', 'ring-primary/40', 'ring-offset-2', 'ring-offset-[var(--bg-elevated)]')
250282 }
283+
284+ if (isToday) {
285+ dayCell.classList.add(
286+ 'outline',
287+ 'outline-2',
288+ 'outline-[var(--accent)]',
289+ 'outline-offset-2',
290+ )
291+ }
251292 } else {
252293 dayCell.textContent = ''
253294 dayCell.classList.add('opacity-50')
0 commit comments