Skip to content

Commit

Permalink
refactor: align struct field names and improve consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
revelaction committed Aug 27, 2024
1 parent 247c901 commit b96fabf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (l *Location) UnmarshalText(text []byte) error {
}

type Alarm struct {
Type string `toml:"type"`
DurIso8601 string `toml:"when"`
Dur time.Duration
Type string `toml:"type"`
DurIso8601 string `toml:"when"`
Dur time.Duration
}

type Alarms []Alarm
Expand Down
6 changes: 3 additions & 3 deletions ical/alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type Alarms struct {
}

type Alarm struct {
config.Alarm
Time time.Time
config.Alarm
time time.Time
}

func NewAlarms(c config.Config, start time.Time) *Alarms {
Expand All @@ -35,7 +35,7 @@ func (s *Alarms) Get(eventTime time.Time) []Alarm {
//slog.Info("🔔 Alarm", "diff", alarm.When, "type", alarm.Type, "alarm_time", alTime)

if s.isInTickPeriod(alarmTime) {
tickAlarms = append(tickAlarms, Alarm{config.Alarm: alarm, Time: alarmTime})
tickAlarms = append(tickAlarms, Alarm{Alarm: alarm, time: alarmTime})
}

}
Expand Down
4 changes: 2 additions & 2 deletions ical/alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestGetInTick(t *testing.T) {

// 1 September 2024, 5:00
expectedAlarmTime := time.Date(2024, time.September, 1, 5, 0, 0, 0, time.UTC)
if result[0].Time != expectedAlarmTime {
t.Errorf("Expected alarm time %v, got %v", expectedAlarmTime, result[0].Time)
if result[0].time != expectedAlarmTime {
t.Errorf("Expected alarm time %v, got %v", expectedAlarmTime, result[0].time)
}
}

Expand Down
8 changes: 4 additions & 4 deletions ical/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (p *Parser) Parse(data []byte) error {

eventTime, err := et.nextTime(p.start)
if err != nil {
slog.Info("📅 Event", "event_time", eventTime, "error", err)
continue
slog.Info("📅 Event", "event_time", eventTime, "error", err)
continue
}

slog.Info("📅 Event", "event_time", eventTime, "has_rrule", et.hasRRule(), "has_rdate", et.hasRDate())
Expand All @@ -51,10 +51,10 @@ func (p *Parser) Parse(data []byte) error {
for _, alarm := range als {
// To notification
n := buildNotification(event)
n.Time = alarm.Time
n.Time = alarm.time
n.EventTime = eventTime
n.Type = alarm.Type
n.Diff = alarm.Diff
n.DurIso8601 = alarm.DurIso8601

p.notifications = append(p.notifications, n)
}
Expand Down
2 changes: 1 addition & 1 deletion notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Notification struct {
Description string
Location string
Type string
Diff string
DurIso8601 string
Time time.Time
Status string
Duration time.Duration
Expand Down
2 changes: 1 addition & 1 deletion notify/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *Scheduler) Schedule(notifications []notify.Notification) error {

f := s.getNotifyFunc(n)
dur := n.Time.Sub(s.start)
slog.Info("⏰ Notification", "time", n.Time, "diff", n.Diff, "type", n.Type, "summary", n.Summary, "event_time", n.EventTime, "trigger_in", dur)
slog.Info("⏰ Notification", "time", n.Time, "diff", n.DurIso8601, "type", n.Type, "summary", n.Summary, "event_time", n.EventTime, "trigger_in", dur)
timer := time.AfterFunc(dur, f)
s.timers = append(s.timers, timer)
}
Expand Down

0 comments on commit b96fabf

Please sign in to comment.