Skip to content

Commit

Permalink
Use nanoseconds since Unix Epoch as the package version.
Browse files Browse the repository at this point in the history
The Go epoch (Jan 1 year 1) was more than 2^63-1 nanoseconds ago, a
time.Duration/int64 can only represent a 290 years span or so.

People with packages that predate the world of modern computing and
the invention of the Go language itself will have issues with this.
  • Loading branch information
korfuri committed Jul 11, 2017
1 parent 8ab6f73 commit de2633d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packagegraph_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"golang.org/x/tools/go/loader"
)

var (
epoch = time.Unix(0, 0)
)

// ConstantVersion returns a versionF function that always replies
// with a constant version. Useful for experimenting, or for graphs
// who load from an immutable snapshot of the Go universe.
Expand Down Expand Up @@ -38,6 +42,6 @@ func FileMTimeVersion(prog loader.Program, pi loader.PackageInfo) (int64, error)
return -1, fmt.Errorf("Unable to determine the version of package %s", pi.Pkg.Path())
}
// newestMTime - epoch gives us a duration which is an int64
// of nanoseconds since the Go epoch (1/1/1 00:00:00 UTC).
return int64(newestMTime.UTC().Sub(time.Time{})), nil
// of nanoseconds since the Unix epoch
return int64(newestMTime.UTC().Sub(epoch)), nil
}

0 comments on commit de2633d

Please sign in to comment.