@@ -38,12 +38,29 @@ type listFlagType struct {
3838}
3939
4040type artifactListOutput struct {
41- Digest string
42- Repository string
43- Size string
44- Tag string
45- Created string
46- VirtualSize string
41+ Digest string
42+ Repository string
43+ Size string
44+ Tag string
45+ created time.Time
46+ VirtualSize string
47+ virtualBytes int64
48+ }
49+
50+ // Created returns human-readable elapsed time since artifact was created
51+ func (a artifactListOutput ) Created () string {
52+ if a .created .IsZero () {
53+ return ""
54+ }
55+ return units .HumanDuration (time .Since (a .created )) + " ago"
56+ }
57+
58+ // CreatedAt returns the full timestamp string of when the artifact was created
59+ func (a artifactListOutput ) CreatedAt () string {
60+ if a .created .IsZero () {
61+ return ""
62+ }
63+ return a .created .String ()
4764}
4865
4966var (
@@ -109,23 +126,23 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
109126 artifactHash = artifactDigest .Encoded ()
110127 }
111128
112- var created string
129+ var createdTime time. Time
113130 createdAnnotation , ok := lr .Manifest .Annotations [imgspecv1 .AnnotationCreated ]
114131 if ok {
115- createdTime , err : = time .Parse (time .RFC3339Nano , createdAnnotation )
132+ createdTime , err = time .Parse (time .RFC3339Nano , createdAnnotation )
116133 if err != nil {
117134 return err
118135 }
119- created = units .HumanDuration (time .Since (createdTime )) + " ago"
120136 }
121137
122138 artifacts = append (artifacts , artifactListOutput {
123- Digest : artifactHash ,
124- Repository : named .Name (),
125- Size : units .HumanSize (float64 (lr .Artifact .TotalSizeBytes ())),
126- Tag : tag ,
127- Created : created ,
128- VirtualSize : fmt .Sprintf ("%d" , lr .Artifact .TotalSizeBytes ()),
139+ Digest : artifactHash ,
140+ Repository : named .Name (),
141+ Size : units .HumanSize (float64 (lr .Artifact .TotalSizeBytes ())),
142+ Tag : tag ,
143+ created : createdTime ,
144+ VirtualSize : fmt .Sprintf ("%d" , lr .Artifact .TotalSizeBytes ()),
145+ virtualBytes : lr .Artifact .TotalSizeBytes (),
129146 })
130147 }
131148
0 commit comments