New route to delete the next alarm
This commit is contained in:
parent
4e0450faca
commit
fa13484718
4 changed files with 78 additions and 1 deletions
|
|
@ -69,6 +69,45 @@ func GetNextAlarm(cfg *config.Config, db *LevelDBStorage) (*time.Time, error) {
|
|||
return closestAlarm, nil
|
||||
}
|
||||
|
||||
func DropNextAlarm(cfg *config.Config, db *LevelDBStorage) error {
|
||||
timenext, err := GetNextAlarm(cfg, db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
alarmsRepeated, err := GetAlarmsRepeated(db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, alarm := range alarmsRepeated {
|
||||
next := alarm.GetNextOccurence(cfg, db)
|
||||
if next != nil && *next == *timenext {
|
||||
start := Date(*next)
|
||||
stop := Date((*next).Add(time.Second))
|
||||
|
||||
return PutAlarmException(db, &AlarmException{
|
||||
Start: &start,
|
||||
End: &stop,
|
||||
Comment: fmt.Sprintf("Automatic exception to cancel recurrent alarm %s", next.Format("Mon at 15:05")),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
alarmsSingle, err := GetAlarmsSingle(db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, alarm := range alarmsSingle {
|
||||
if alarm.Time == *timenext {
|
||||
return DeleteAlarmSingle(db, alarm)
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("Unable to find the next alarm")
|
||||
}
|
||||
|
||||
type Exceptions []time.Time
|
||||
|
||||
func (e Exceptions) Len() int {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue