On Wed, Nov 9, 2022 at 9:00 AM Erez Rokah <e...@cloudquery.io> wrote: > > The string format used is `"2006-01-02 15:04:05.999999999 -0700 MST"` which > is `time.String()` internal format
Thanks. You originally asked whether this is a bug or not. I don't think this is a bug. It's true that it's not easy to use time.Parse to parse a string generated by time.String. That is perhaps unfortunate, but it's a consequence of how the various functions work. As I noted earlier the -m= has been around for a long time. I don't know what changed in Go 1.19. When I run your test with Go 1.18, it fails for me. Ian > On Wednesday, 9 November 2022 at 18:48:09 UTC+2 Ian Lance Taylor wrote: >> >> On Wed, Nov 9, 2022 at 8:33 AM Erez Rokah <er...@cloudquery.io> wrote: >> > >> > I'm not sure if this is a bug or not. The following test will print both >> > error messages: >> > >> > ``` >> > func TestTimeStringParse(t *testing.T) { >> > for i := 0; i < 100000; i++ { >> > timeString := time.Now().Add(time.Duration(rand.Int63())).String() >> > _, err := time.Parse(defaultStringFormat, timeString) >> > if err == nil { >> > t.Errorf("time.Parse(%q) should return error", timeString) >> > } else { >> > t.Errorf("time.Parse(%q) should not return error", timeString) >> > } >> > } >> > } >> > ``` >> > >> > The failure stems from Go 1.19 adding the extra text `m=+<int>` for the >> > monotonic clock. >> > This doesn't happen for every `time.String()` invocation, which is a bit >> > confusing. >> > I understand one shouldn't try to parse `time.String()`, especially with >> > the private format, however this does looks like something that worked >> > before Go 1.19. >> > >> > Would be glad to know what others think. >> >> >> What is defaultStringFormat? >> >> Adding m=<int> is not new in Go 1.19. >> >> Ian > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/bc51019f-9794-41eb-8a86-96234bc1ea11n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcW3XAGsc%2B_MRLi3bPNbYCS4okciZr5q%2BYCeMWKWemeYDw%40mail.gmail.com.