This should be good enough to justify what is a zero duration.
在 2016年1月21日星期四 UTC+8下午12:57:26,peterGo写道:
>
> Simon,
>
> By design, the Go answer to problems like this is often a simple function.
> For example,
>
> package main
>
> import (
> "fmt"
> "time"
> )
>
> type DurationZero struct{ time.Duration }
>
> func (d DurationZero) String() string {
> if d.Duration == 0 {
> return "0s"
> }
> return fmt.Sprint(d.Duration)
> }
>
> func main() {
> var d time.Duration
> fmt.Println(DurationZero{d})
> d = 7 * time.Second
> fmt.Println(DurationZero{d})
> d = 42 * time.Nanosecond
> fmt.Println(DurationZero{d})
> }
>
> Output:
>
> 0s
> 7s
> 42ns
>
>
> https://play.golang.org/p/p9Av-oYMaE
>
> Peter
>
> On Wednesday, January 20, 2016 at 7:09:35 PM UTC-5, simon place wrote:
>>
>> see; http://play.golang.org/p/NQy0qmjEX3
>>
>>
>>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.