This commit is contained in:
henrygd
2025-11-24 16:57:06 -05:00
parent bf36015bd9
commit 1275af956b
4 changed files with 40 additions and 54 deletions

View File

@@ -153,22 +153,19 @@ func (am *AlertManager) IsNotificationSilenced(userID, systemID string) bool {
// Handle case where window crosses midnight // Handle case where window crosses midnight
if endMinutes < startMinutes { if endMinutes < startMinutes {
// Window crosses midnight (e.g., 23:00 - 01:00) // Window crosses midnight (e.g., 23:00 - 01:00)
if nowMinutes >= startMinutes || nowMinutes <= endMinutes { if nowMinutes >= startMinutes || nowMinutes < endMinutes {
return true return true
} }
} else { } else {
// Normal case (e.g., 09:00 - 17:00) // Normal case (e.g., 09:00 - 17:00)
if nowMinutes >= startMinutes && nowMinutes <= endMinutes { if nowMinutes >= startMinutes && nowMinutes < endMinutes {
return true return true
} }
} }
} else { } else {
// One-time window: check if current time is within the date range // One-time window: check if current time is within the date range
if now.After(start) || now.Equal(start) { if (now.After(start) || now.Equal(start)) && now.Before(end) {
// If end is zero/null, suppression continues indefinitely from start return true
if end.IsZero() || now.Before(end) || now.Equal(end) {
return true
}
} }
} }
} }

View File

@@ -1227,7 +1227,7 @@ func init() {
"min": "", "min": "",
"name": "end", "name": "end",
"presentable": false, "presentable": false,
"required": false, "required": true,
"system": false, "system": false,
"type": "date" "type": "date"
} }

View File

@@ -103,13 +103,13 @@ export function QuietHours() {
if (record.type === "daily") { if (record.type === "daily") {
// For daily windows, show only time // For daily windows, show only time
const startTime = new Date(record.start).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) 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" }) : "" const endTime = new Date(record.end).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })
return endTime ? `${startTime} - ${endTime}` : startTime return `${startTime} - ${endTime}`
} }
// For one-time windows, show full date and time // For one-time windows, show full date and time
const start = formatShortDate(record.start) const start = formatShortDate(record.start)
const end = record.end ? formatShortDate(record.end) : "" const end = formatShortDate(record.end)
return end ? `${start} - ${end}` : start return `${start} - ${end}`
} }
const getWindowState = (record: QuietHoursRecord): "active" | "past" | "future" => { const getWindowState = (record: QuietHoursRecord): "active" | "past" | "future" => {
@@ -118,22 +118,17 @@ export function QuietHours() {
if (record.type === "daily") { if (record.type === "daily") {
// For daily windows, check if current time is within the window // For daily windows, check if current time is within the window
const startDate = new Date(record.start) 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 // Get current time in local timezone
const currentMinutes = now.getHours() * 60 + now.getMinutes() const currentMinutes = now.getHours() * 60 + now.getMinutes()
const startMinutes = startDate.getUTCHours() * 60 + startDate.getUTCMinutes() 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 // Convert UTC to local time offset
const offset = now.getTimezoneOffset() const offset = now.getTimezoneOffset()
const localStartMinutes = (startMinutes - offset + 1440) % 1440 const localStartMinutes = (startMinutes - offset + 1440) % 1440
const localEndMinutes = endMinutes !== null ? (endMinutes - offset + 1440) % 1440 : null const localEndMinutes = (endMinutes - offset + 1440) % 1440
if (localEndMinutes === null) {
// No end time, so it's always active from start time onwards each day
return "active"
}
// Handle cases where window spans midnight // Handle cases where window spans midnight
if (localStartMinutes <= localEndMinutes) { if (localStartMinutes <= localEndMinutes) {
@@ -144,23 +139,14 @@ export function QuietHours() {
} else { } else {
// For one-time windows // For one-time windows
const startDate = new Date(record.start) 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) {
if (now >= startDate && now <= endDate) { return "active"
return "active" } else if (now >= endDate) {
} else if (now > endDate) { return "past"
return "past"
} else {
return "future"
}
} else { } else {
// No end date return "future"
if (now >= startDate) {
return "active"
} else {
return "future"
}
} }
} }
} }
@@ -490,20 +476,23 @@ function QuietHoursDialog({
onChange={(e) => setStartDateTime(e.target.value)} onChange={(e) => setStartDateTime(e.target.value)}
min={formatDateTimeLocal(new Date(new Date().setHours(0, 0, 0, 0)))} min={formatDateTimeLocal(new Date(new Date().setHours(0, 0, 0, 0)))}
required required
className="tabular-nums tracking-tighter"
/> />
</div> </div>
<div className="grid gap-2"> <div className="grid gap-2">
<Label htmlFor="end-datetime"> <Label htmlFor="end-datetime">
<Trans>End Date & Time</Trans> (<Trans>Optional</Trans>) <Trans>End Date & Time</Trans>
</Label> </Label>
<Input <Input
id="end-datetime" id="end-datetime"
type="datetime-local" type="datetime-local"
value={endDateTime} value={endDateTime}
onChange={(e) => setEndDateTime(e.target.value)} onChange={(e) => setEndDateTime(e.target.value)}
min={startDateTime || formatDateTimeLocal(new Date())} min={startDateTime || formatDateTimeLocal(new Date())}
/> required
</div> className="tabular-nums tracking-tighter"
/>
</div>
</> </>
) : ( ) : (
<> <>
@@ -519,12 +508,12 @@ function QuietHoursDialog({
required required
/> />
</div> </div>
<div className="grid gap-2"> <div className="grid gap-2">
<Label htmlFor="end-time"> <Label htmlFor="end-time">
<Trans>End Time</Trans> (<Trans>Optional</Trans>) <Trans>End Time</Trans>
</Label> </Label>
<Input id="end-time" type="time" value={endTime} onChange={(e) => setEndTime(e.target.value)} /> <Input id="end-time" type="time" value={endTime} onChange={(e) => setEndTime(e.target.value)} required />
</div> </div>
</> </>
)} )}

View File

@@ -250,7 +250,7 @@ export interface QuietHoursRecord extends RecordModel {
system: string system: string
type: "one-time" | "daily" type: "one-time" | "daily"
start: string start: string
end?: string | null end: string
expand?: { expand?: {
system?: { system?: {
name: string name: string