Skip to content

Commit 066d411

Browse files
committed
chore: parse Created time on container with CreatedTime
1 parent 0397086 commit 066d411

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/api/container.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ const (
2424

2525
type Container struct {
2626
types.ContainerJSON
27+
// created caches the parsed creation time by CreatedTime.
28+
created time.Time
29+
}
30+
31+
// CreatedTime returns the time when the container was created parsed from the Created field.
32+
func (c *Container) CreatedTime() time.Time {
33+
if c.created.IsZero() {
34+
created, err := time.Parse(time.RFC3339Nano, c.Created)
35+
if err != nil {
36+
return time.Time{}
37+
}
38+
c.created = created
39+
}
40+
return c.created
2741
}
2842

2943
// Healthy determines if the container is running and healthy.

0 commit comments

Comments
 (0)