(start Wall, value string)
| 170 | var commitmentWindowDurationRE = regexp.MustCompile(`^(\d+)([mhd])$`) |
| 171 | |
| 172 | func commitmentWindowEnd(start Wall, value string) (Wall, error) { |
| 173 | bad := fmt.Errorf("--window %q: want a duration (90m, 2h, 3d) or an end wall (2026-11-09T17:00)", value) |
| 174 | base := start.naive() |
| 175 | wall := func(at time.Time) Wall { |
| 176 | return Wall{Year: at.Year(), Month: at.Month(), Day: at.Day(), Hour: at.Hour(), Minute: at.Minute(), Second: at.Second(), AllDay: start.AllDay} |
| 177 | } |
| 178 | if m := commitmentWindowDurationRE.FindStringSubmatch(value); m != nil { |
| 179 | n, err := strconv.Atoi(m[1]) |
| 180 | if err != nil || n <= 0 || n > 100000 { |
| 181 | return Wall{}, bad |
| 182 | } |
| 183 | if m[2] == "d" { |
| 184 | return wall(base.AddDate(0, 0, n)), nil |
| 185 | } |
| 186 | if start.AllDay { |
| 187 | return Wall{}, fmt.Errorf("--window %q: an all-day start takes a window in days (3d) or an end date", value) |
| 188 | } |
| 189 | unit := time.Minute |
| 190 | if m[2] == "h" { |
| 191 | unit = time.Hour |
| 192 | } |
| 193 | return wall(base.Add(time.Duration(n) * unit)), nil |
| 194 | } |
| 195 | if d, err := time.ParseDuration(value); err == nil { |
| 196 | if d <= 0 || start.AllDay { |
| 197 | return Wall{}, bad |
| 198 | } |
| 199 | return wall(base.Add(d)), nil |
| 200 | } |
| 201 | if end, err := ParseWall(value); err == nil { |
| 202 | return end, nil |
| 203 | } |
| 204 | return Wall{}, bad |
| 205 | } |
| 206 | |
| 207 | // CommitmentResolve is the body of POST .../commitment/resolve. |
| 208 | type CommitmentResolve struct { |
no test coverage detected