> The standard text marshaling and unmarshaling work fine. Ok, I get you.
I guess I'm looking for something a little more human friendly than nanoseconds! In that case I'll proceed with my new-type, thanks! On Wednesday, 19 January 2022 at 3:19:44 pm UTC+11 Ian Lance Taylor wrote: > On Mon, Jan 17, 2022 at 9:53 PM Corin Lawson <corin....@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/cb41ae9b-fd60-42db-988d-236a0cc67761n%40googlegroups.com.