mirror of
https://github.com/tw93/Mole.git
synced 2026-02-11 11:49:22 +00:00
test: stabilize formatUnusedTime by using UTC baseline
This commit is contained in:
@@ -310,6 +310,7 @@ func TestCalculateNameWidth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatUnusedTime(t *testing.T) {
|
func TestFormatUnusedTime(t *testing.T) {
|
||||||
|
now := time.Now().UTC()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
daysAgo int
|
daysAgo int
|
||||||
@@ -334,8 +335,8 @@ func TestFormatUnusedTime(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var lastAccess time.Time
|
var lastAccess time.Time
|
||||||
if tt.daysAgo >= 0 {
|
if tt.daysAgo >= 0 {
|
||||||
// Create a time that is tt.daysAgo days in the past
|
// Use a fixed UTC baseline to avoid DST-related flakiness.
|
||||||
lastAccess = time.Now().AddDate(0, 0, -tt.daysAgo)
|
lastAccess = now.Add(-time.Duration(tt.daysAgo) * 24 * time.Hour)
|
||||||
}
|
}
|
||||||
// If daysAgo < 0, lastAccess remains zero value
|
// If daysAgo < 0, lastAccess remains zero value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user