internal/testing/sample: use UTC for time

Use UTC for sample.CommitTime, instead of the local timezone.  This
avoids time-dependent test failure due to a mismatch between the
database's timezone (UTC) and the test runner's local time.

As an example, say a developer runs `go test` on a machine in the US
Eastern timezone (UTC-5). Consider TestFetchPackageVersionsDetails in
internal/frontend/versions_test.go. This test compares commit times
from the DB and from the local machine, formatted as date strings.

From 7pm (5 hours before the date changes) until midnight, this test
will fail because the Eastern day is one less than the UTC day. For
instance, at 8pm EST on a Wednesday, it is 1am UTC on a Thursday.

After this CL, all times are UTC, so the days will be same.

Change-Id: Ia7bfc964c650aebbc6d20be1feda3e61fc8f2449
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/289949
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/frontend/versions_test.go b/internal/frontend/versions_test.go
index ae88ed8..7985311 100644
--- a/internal/frontend/versions_test.go
+++ b/internal/frontend/versions_test.go
@@ -7,7 +7,6 @@
 import (
 	"context"
 	"testing"
-	"time"
 
 	"github.com/google/go-cmp/cmp"
 	"golang.org/x/pkgsite/internal"
@@ -19,7 +18,6 @@
 var (
 	modulePath1 = "test.com/module"
 	modulePath2 = "test.com/module/v2"
-	commitTime  = sample.CommitTime.In(time.UTC).Format("Jan _2, 2006")
 )
 
 func sampleModule(modulePath, version string, versionType version.Type, packages ...*internal.Unit) *internal.Module {
@@ -39,7 +37,7 @@
 		vs[i] = &VersionSummary{
 			Version:    version,
 			Link:       linkify(path, version),
-			CommitTime: commitTime,
+			CommitTime: absoluteTime(sample.CommitTime),
 		}
 	}
 	return vs
diff --git a/internal/testing/sample/sample.go b/internal/testing/sample/sample.go
index 4df0df6..17b2f24 100644
--- a/internal/testing/sample/sample.go
+++ b/internal/testing/sample/sample.go
@@ -87,7 +87,7 @@
 // Microsecond precision:
 //   https://www.postgresql.org/docs/9.1/datatype-datetime.html
 func NowTruncated() time.Time {
-	return time.Now().Truncate(time.Microsecond)
+	return time.Now().In(time.UTC).Truncate(time.Microsecond)
 }
 
 func DefaultModule() *internal.Module {