update cmd
This commit is contained in:
parent
f132031dc6
commit
82a7944136
|
@ -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)
|
||||
if as.IsSet(FlagFor) {
|
||||
e.Duration = as.GetDuration(FlagFor)
|
||||
}
|
||||
e.Duration = fr
|
||||
|
||||
if !e.Valid() {
|
||||
return fmt.Errorf("event is unvalid")
|
||||
}
|
||||
if err := eventRepo.Store(e); err != nil {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue