1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 16:49:41 +00:00

test: stabilize formatUnusedTime by using UTC baseline

This commit is contained in:
Tw93
2026-01-22 17:24:55 +08:00
parent 6be7f7d0f8
commit d862d58672

View File

@@ -310,6 +310,7 @@ func TestCalculateNameWidth(t *testing.T) {
}
func TestFormatUnusedTime(t *testing.T) {
now := time.Now().UTC()
tests := []struct {
name string
daysAgo int
@@ -334,8 +335,8 @@ func TestFormatUnusedTime(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var lastAccess time.Time
if tt.daysAgo >= 0 {
// Create a time that is tt.daysAgo days in the past
lastAccess = time.Now().AddDate(0, 0, -tt.daysAgo)
// Use a fixed UTC baseline to avoid DST-related flakiness.
lastAccess = now.Add(-time.Duration(tt.daysAgo) * 24 * time.Hour)
}
// If daysAgo < 0, lastAccess remains zero value