On Mon, Jan 17, 2022 at 9:53 PM Corin Lawson <corin.law...@gmail.com> wrote: > > It seems obvious (to me) that the encoding.TextUnmarshaler interface could be > implemented for time.Duration (it is implemented for time.Time, afterall). > > The fact that it is not gives me pause... is there a good reason that the > stdlib has not done this? What issues am I facing if I do this: > https://go.dev/play/p/nHBfS7TJQtJ > > ``` > // UnmarshalText implements the encoding.TextUnmarshaler interface. > func (d *Duration) UnmarshalText(data []byte) error { > val, err := time.ParseDuration(string(data)) > *d = Duration(val) > return err > } > ```
A time.Duration is just an integer. The standard text marshaling and unmarshaling work fine. 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/CAOyqgcUbSaTJ15zT7ksQmDMaf2oq%2B0oY5uN-kzzKHXa-6JjnJw%40mail.gmail.com.