-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.go
41 lines (32 loc) · 835 Bytes
/
time.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
package utils
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ParseTimestamp Converts timestamp to time
func ParseTimestamp(timestamp string) (time.Time, error) {
return time.Parse(time.RFC3339, timestamp)
}
// ParseTimestampNillable Converts timestamp to time or nil
func ParseTimestampNillable(timestamp string) *time.Time {
t, err := ParseTimestamp(timestamp)
if err != nil {
return nil
}
return &t
}
// FormatTimestamp Converts time to formatted timestamp
func FormatTimestamp(timestamp time.Time) string {
emptyTime := time.Time{}
if timestamp != emptyTime {
return timestamp.Format(time.RFC3339)
}
return ""
}
// FormatTime Converts kubernetes time to formatted timestamp
func FormatTime(time *metav1.Time) string {
if time != nil {
return FormatTimestamp(time.Time)
}
return ""
}