Skip to content

Commit 3206a27

Browse files
committed
refactor: simplify duration calculations in age.go
Removed redundant variable assignments in the Age and Duration functions. Refactored the PRDuration function to reduce nesting and improve readability. No functional changes were made.
1 parent 50f58bf commit 3206a27

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

pkg/formatting/age.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ func Age(t *metav1.Time, c clockwork.Clock) string {
1111
if t.IsZero() {
1212
return nonAttributedStr
1313
}
14-
15-
dur := c.Since(t.Time)
16-
return durafmt.ParseShort(dur).String() + " ago"
14+
return durafmt.ParseShort(c.Since(t.Time)).String() + " ago"
1715
}
1816

1917
func Duration(t1, t2 *metav1.Time) string {
2018
if t1.IsZero() || t2.IsZero() {
2119
return nonAttributedStr
2220
}
23-
24-
dur := t2.Sub(t1.Time)
25-
return durafmt.ParseShort(dur).String()
21+
return durafmt.ParseShort(t2.Sub(t1.Time)).String()
2622
}
2723

2824
// PRDuration calculates the duration of a repository run, given its status.
@@ -35,11 +31,10 @@ func PRDuration(runStatus v1alpha1.RepositoryRunStatus) string {
3531

3632
lasttime := runStatus.CompletionTime
3733
if lasttime == nil {
38-
if len(runStatus.Conditions) > 0 {
39-
lasttime = &runStatus.Conditions[0].LastTransitionTime.Inner
40-
} else {
34+
if len(runStatus.Conditions) == 0 {
4135
return nonAttributedStr
4236
}
37+
lasttime = &runStatus.Conditions[0].LastTransitionTime.Inner
4338
}
4439

4540
return Duration(runStatus.StartTime, lasttime)
@@ -49,6 +44,5 @@ func Timeout(t *metav1.Duration) string {
4944
if t == nil {
5045
return nonAttributedStr
5146
}
52-
5347
return durafmt.Parse(t.Duration).String()
5448
}

0 commit comments

Comments
 (0)