diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go index aa59bdb6..11ad1f93 100644 --- a/internal/alerts/alerts.go +++ b/internal/alerts/alerts.go @@ -153,22 +153,19 @@ func (am *AlertManager) IsNotificationSilenced(userID, systemID string) bool { // Handle case where window crosses midnight if endMinutes < startMinutes { // Window crosses midnight (e.g., 23:00 - 01:00) - if nowMinutes >= startMinutes || nowMinutes <= endMinutes { + if nowMinutes >= startMinutes || nowMinutes < endMinutes { return true } } else { // Normal case (e.g., 09:00 - 17:00) - if nowMinutes >= startMinutes && nowMinutes <= endMinutes { + if nowMinutes >= startMinutes && nowMinutes < endMinutes { return true } } } else { // One-time window: check if current time is within the date range - if now.After(start) || now.Equal(start) { - // If end is zero/null, suppression continues indefinitely from start - if end.IsZero() || now.Before(end) || now.Equal(end) { - return true - } + if (now.After(start) || now.Equal(start)) && now.Before(end) { + return true } } } diff --git a/internal/migrations/0_collections_snapshot_0_16_2.go b/internal/migrations/0_collections_snapshot_0_16_2.go index c4fc7895..cd703df3 100644 --- a/internal/migrations/0_collections_snapshot_0_16_2.go +++ b/internal/migrations/0_collections_snapshot_0_16_2.go @@ -1227,7 +1227,7 @@ func init() { "min": "", "name": "end", "presentable": false, - "required": false, + "required": true, "system": false, "type": "date" } diff --git a/internal/site/src/components/routes/settings/quiet-hours.tsx b/internal/site/src/components/routes/settings/quiet-hours.tsx index bb910640..be802966 100644 --- a/internal/site/src/components/routes/settings/quiet-hours.tsx +++ b/internal/site/src/components/routes/settings/quiet-hours.tsx @@ -103,13 +103,13 @@ export function QuietHours() { if (record.type === "daily") { // For daily windows, show only time const startTime = new Date(record.start).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) - const endTime = record.end ? new Date(record.end).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : "" - return endTime ? `${startTime} - ${endTime}` : startTime + const endTime = new Date(record.end).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) + return `${startTime} - ${endTime}` } // For one-time windows, show full date and time const start = formatShortDate(record.start) - const end = record.end ? formatShortDate(record.end) : "" - return end ? `${start} - ${end}` : start + const end = formatShortDate(record.end) + return `${start} - ${end}` } const getWindowState = (record: QuietHoursRecord): "active" | "past" | "future" => { @@ -118,22 +118,17 @@ export function QuietHours() { if (record.type === "daily") { // For daily windows, check if current time is within the window const startDate = new Date(record.start) - const endDate = record.end ? new Date(record.end) : null + const endDate = new Date(record.end) // Get current time in local timezone const currentMinutes = now.getHours() * 60 + now.getMinutes() const startMinutes = startDate.getUTCHours() * 60 + startDate.getUTCMinutes() - const endMinutes = endDate ? endDate.getUTCHours() * 60 + endDate.getUTCMinutes() : null + const endMinutes = endDate.getUTCHours() * 60 + endDate.getUTCMinutes() // Convert UTC to local time offset const offset = now.getTimezoneOffset() const localStartMinutes = (startMinutes - offset + 1440) % 1440 - const localEndMinutes = endMinutes !== null ? (endMinutes - offset + 1440) % 1440 : null - - if (localEndMinutes === null) { - // No end time, so it's always active from start time onwards each day - return "active" - } + const localEndMinutes = (endMinutes - offset + 1440) % 1440 // Handle cases where window spans midnight if (localStartMinutes <= localEndMinutes) { @@ -144,23 +139,14 @@ export function QuietHours() { } else { // For one-time windows const startDate = new Date(record.start) - const endDate = record.end ? new Date(record.end) : null + const endDate = new Date(record.end) - if (endDate) { - if (now >= startDate && now <= endDate) { - return "active" - } else if (now > endDate) { - return "past" - } else { - return "future" - } + if (now >= startDate && now < endDate) { + return "active" + } else if (now >= endDate) { + return "past" } else { - // No end date - if (now >= startDate) { - return "active" - } else { - return "future" - } + return "future" } } } @@ -490,20 +476,23 @@ function QuietHoursDialog({ onChange={(e) => setStartDateTime(e.target.value)} min={formatDateTimeLocal(new Date(new Date().setHours(0, 0, 0, 0)))} required + className="tabular-nums tracking-tighter" /> -