Skip to content

Commit 276f5d5

Browse files
committed
fix: correct IsImminent logic and improve notification template formatting
1 parent ad415e7 commit 276f5d5

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

ical/parse.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
"time"
1717
)
1818

19-
// LooseCategory is the category used to indicate that the event is without a fixed date or deadline
19+
// LooseCategory is the category used to indicate that the event is without a
20+
// fixed date or deadline
2021
const LooseCategory = "loose"
21-
// ShowAlarmCategory is the category used to indicate that the alarm details should be displayed in the notification
22+
// ShowAlarmCategory is the category used to indicate that the alarm details
23+
// should be displayed in the notification
2224
const ShowAlarmCategory = "show-alarm"
2325

2426
type Parser struct {

notify/notify.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
)
66

77
const Tpl = `
8+
{{- if and (not .Loose) .IsImminent}}
9+
📢🔥🚨 IN {{.TimeDifference}} 🚨🔥📢
10+
{{- end}}
811
{{- if .Summary}}
912
<b>{{.Summary}}</b>
1013
<b> </b>
@@ -45,16 +48,10 @@ Attendees:
4548
{{- end}}
4649
{{- if .ShowAlarm}}
4750
{{.Source}} 🔔 {{.DurIso8601}}
48-
{{- end}}
49-
50-
{{- if and (not .Loose) .IsImminent}}
51-
52-
📢🔥🚨 IN {{.TimeDifference}} 🚨🔥📢
53-
5451
{{- end}}
5552
`
5653

57-
const ImminenceThreshold = 1 * time.Hour
54+
const ImminenceThreshold = 2 * time.Hour
5855

5956
type Notifier interface {
6057
Notify(n Notification) error
@@ -122,9 +119,9 @@ func (n Notification) EventTimeTz() string {
122119
return n.EventTime.Location().String()
123120
}
124121

125-
// IsUrgent checks if the notification is urgent based on the difference between EventTime and Time
122+
// IsImminent checks if the notification is urgent based on the difference between EventTime and Time
126123
func (n Notification) IsImminent() bool {
127-
return n.EventTime.Sub(n.Time) > ImminenceThreshold
124+
return n.EventTime.Sub(n.Time) < ImminenceThreshold
128125
}
129126

130127
// TimeDifference returns the difference between EventTime and Time

0 commit comments

Comments
 (0)