From 4bac58e10a500680a1f3e69dbb25e014c5065b7c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 7 May 2024 14:39:12 +0300 Subject: 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 Autosubmit: tazjin Tested-by: BuildkiteCI --- tools/when/when.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools') diff --git a/tools/when/when.go b/tools/when/when.go index 3102328fe9e0..316f021913ab 100644 --- a/tools/when/when.go +++ b/tools/when/when.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strconv" + "strings" "time" ) @@ -107,6 +108,13 @@ func main() { var err error 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:] { if !haveTime { if t, err = parseTime(arg); err == nil { -- cgit 1.4.1