-
Notifications
You must be signed in to change notification settings - Fork 81
/
age.go
51 lines (41 loc) · 1.08 KB
/
age.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package formatting
import (
"github.com/hako/durafmt"
"github.com/jonboulle/clockwork"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func Age(t *metav1.Time, c clockwork.Clock) string {
if t.IsZero() {
return nonAttributedStr
}
dur := c.Since(t.Time)
return durafmt.ParseShort(dur).String() + " ago"
}
func Duration(t1, t2 *metav1.Time) string {
if t1.IsZero() || t2.IsZero() {
return nonAttributedStr
}
dur := t2.Time.Sub(t1.Time)
return durafmt.ParseShort(dur).String()
}
func PRDuration(runStatus v1alpha1.RepositoryRunStatus) string {
if runStatus.StartTime == nil {
return nonAttributedStr
}
lasttime := runStatus.CompletionTime
if lasttime == nil {
if len(runStatus.Conditions) > 0 {
lasttime = &runStatus.Status.Conditions[0].LastTransitionTime.Inner
} else {
return nonAttributedStr
}
}
return Duration(runStatus.StartTime, lasttime)
}
func Timeout(t *metav1.Duration) string {
if t == nil {
return nonAttributedStr
}
return durafmt.Parse(t.Duration).String()
}