diff --git a/plan/command/update.go b/plan/command/update.go index 685e1b2..36bf4b6 100644 --- a/plan/command/update.go +++ b/plan/command/update.go @@ -84,31 +84,31 @@ func (update *Update) Do() error { if as.Main != "" { e.Title = as.Main } - if onStr != "" || atStr != "" { - oldStart := e.Start - dateStr := oldStart.Format("2006-01-02") - if onStr != "" { - dateStr = onStr + if as.IsSet(FlagOn) || as.IsSet(FlagAt) { + on := time.Date(e.Start.Year(), e.Start.Month(), e.Start.Day(), 0, 0, 0, 0, time.UTC) + atH := time.Duration(e.Start.Hour()) * time.Hour + atM := time.Duration(e.Start.Minute()) * time.Minute + + if as.IsSet(FlagOn) { + on = as.GetTime(FlagOn) } - timeStr := oldStart.Format("15:04") - if atStr != "" { - timeStr = atStr + if as.IsSet(FlagAt) { + at := as.GetTime(FlagAt) + atH = time.Duration(at.Hour()) * time.Hour + atM = time.Duration(at.Minute()) * time.Minute } - newStart, err := time.Parse("2006-01-02 15:04", fmt.Sprintf("%s %s", dateStr, timeStr)) - if err != nil { - return fmt.Errorf("could not parse new start: %v", err) - } - e.Start = newStart + e.Start = on.Add(atH).Add(atM) } - if frStr != "" { // no check on at, can set a duration with at 00:00, making it not a whole day - fr, err := time.ParseDuration(frStr) - if err != nil { - return fmt.Errorf("%w: could not parse duration: %s", ErrInvalidArg, err) - } - e.Duration = fr + if as.IsSet(FlagFor) { + e.Duration = as.GetDuration(FlagFor) } - if err := eventRepo.Store(e); err != nil { + + if !e.Valid() { + return fmt.Errorf("event is unvalid") + } + + if err := update.eventRepo.Store(e); err != nil { return fmt.Errorf("could not store event: %v", err) } @@ -116,7 +116,7 @@ func (update *Update) Do() error { if err != nil { return fmt.Errorf("could not convert event to sync item: %v", err) } - if err := syncRepo.Store(it); err != nil { + if err := update.syncRepo.Store(it); err != nil { return fmt.Errorf("could not store sync item: %v", err) }