Skip to content

time: print more than just "0" for a zero duration (revert?) #14058

Closed
@robpike

Description

@robpike

http://play.golang.org/p/pIagpaYGak

package main

import "fmt"
import "time"

func main() {
    var t time.Duration
    t = 1e3
    fmt.Printf("%s\n", t)
    t -= 1e3
    fmt.Printf("%s\n", t)
    t -= 1e3
    fmt.Printf("%s\n", t)
    t = 1e6
    fmt.Printf("%s\n", t)
    t -= 1e6
    fmt.Printf("%s\n", t)
    t -= 1e6
    fmt.Printf("%s\n", t)
    t = 1e9
    fmt.Printf("%s\n", t)
    t -= 1e9
    fmt.Printf("%s\n", t)
    t -= 1e9
    fmt.Printf("%s\n", t)
}

prints

1µs
0
-1µs
1ms
0
-1ms
1s
0
-1s

It should show either ns because that's the internal resolution or s because that's the SI unit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions