Skip to content

Commit

Permalink
Merge pull request #91 from saschagrunert/build-date
Browse files Browse the repository at this point in the history
Use go library for git date parsing
  • Loading branch information
k8s-ci-robot authored Aug 14, 2023
2 parents 1bf6b4c + 2b64c76 commit e16435f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mage/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package mage

import (
"fmt"
"strconv"
"time"

"github.com/uwu-tools/magex/shx"
)
Expand Down Expand Up @@ -58,12 +60,11 @@ func getBuildDateTime() (string, error) {
return "", err
}
if result != "" {
sourceDateEpoch := fmt.Sprintf("@%s", result)
date, err := shx.Output("date", "-u", "-d", sourceDateEpoch, "+%Y-%m-%dT%H:%M:%SZ")
parsedInt, err := strconv.ParseInt(result, 10, 64)
if err != nil {
return "", err
return "", fmt.Errorf("parse source date epoch to int: %w", err)
}
return date, nil
return time.Unix(parsedInt, 0).UTC().Format(time.RFC3339), nil
}

return shx.Output("date", "+%Y-%m-%dT%H:%M:%SZ")
Expand Down

0 comments on commit e16435f

Please sign in to comment.