update cmd
This commit is contained in:
parent
f132031dc6
commit
82a7944136
|
@ -84,31 +84,31 @@ func (update *Update) Do() error {
|
||||||
if as.Main != "" {
|
if as.Main != "" {
|
||||||
e.Title = as.Main
|
e.Title = as.Main
|
||||||
}
|
}
|
||||||
if onStr != "" || atStr != "" {
|
if as.IsSet(FlagOn) || as.IsSet(FlagAt) {
|
||||||
oldStart := e.Start
|
on := time.Date(e.Start.Year(), e.Start.Month(), e.Start.Day(), 0, 0, 0, 0, time.UTC)
|
||||||
dateStr := oldStart.Format("2006-01-02")
|
atH := time.Duration(e.Start.Hour()) * time.Hour
|
||||||
if onStr != "" {
|
atM := time.Duration(e.Start.Minute()) * time.Minute
|
||||||
dateStr = onStr
|
|
||||||
|
if as.IsSet(FlagOn) {
|
||||||
|
on = as.GetTime(FlagOn)
|
||||||
}
|
}
|
||||||
timeStr := oldStart.Format("15:04")
|
if as.IsSet(FlagAt) {
|
||||||
if atStr != "" {
|
at := as.GetTime(FlagAt)
|
||||||
timeStr = atStr
|
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))
|
e.Start = on.Add(atH).Add(atM)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not parse new start: %v", err)
|
|
||||||
}
|
|
||||||
e.Start = newStart
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if frStr != "" { // no check on at, can set a duration with at 00:00, making it not a whole day
|
if as.IsSet(FlagFor) {
|
||||||
fr, err := time.ParseDuration(frStr)
|
e.Duration = as.GetDuration(FlagFor)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%w: could not parse duration: %s", ErrInvalidArg, err)
|
|
||||||
}
|
|
||||||
e.Duration = fr
|
|
||||||
}
|
}
|
||||||
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)
|
return fmt.Errorf("could not store event: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ func (update *Update) Do() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not convert event to sync item: %v", err)
|
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)
|
return fmt.Errorf("could not store sync item: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue