Skip to content

time: Time.String formats negative monotonic times incorrectly #18993

@cespare

Description

@cespare

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

tip (go version devel +0c9325e Wed Feb 8 17:54:06 2017 +0000 linux/amd64)

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

package main

import (
	"fmt"
	"time"
)

func main() {
	time.Sleep(200 * time.Millisecond)
	t := time.Now()
	fmt.Println(t)
	t = t.Add(-time.Second)
	fmt.Println(t)
}

This printed

2017-02-08 10:34:35.543437741 -0800 PST m=+0.200282679
2017-02-08 10:34:34.543437741 -0800 PST m=-1.200282679

Given the first timestamp, the second line should instead have been

2017-02-08 10:34:34.543437741 -0800 PST m=-0.799717321

Looks like that method could also use a test. If it's OK, I'll send a CL.

/cc @rsc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions