feat(tools/when): try to parse input as one segment first

Before getting clever about durations & stuff, try to parse the whole thing at
once. This is useful for plain timestamps that contain spaces, like `2024-01-01
15:00:01` for example.

Change-Id: I50b0ee8488c153b4e6db75abaea409d55c0b92d6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11600
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2024-05-07 14:39:12 +03:00 committed by clbot
parent 51ce40c599
commit 4bac58e10a

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -107,6 +108,13 @@ func main() {
var err error var err error
var haveTime, haveDuration bool var haveTime, haveDuration bool
// Try to parse entire input as one full thing, before getting more
// clever.
if t, err = parseTime(strings.Join(os.Args[1:], " ")); err == nil {
printTime(t)
return
}
for _, arg := range os.Args[1:] { for _, arg := range os.Args[1:] {
if !haveTime { if !haveTime {
if t, err = parseTime(arg); err == nil { if t, err = parseTime(arg); err == nil {