Skip to content

Commit

Permalink
Use go library for git date parsing
Browse files Browse the repository at this point in the history
This way we do not rely on gnu date and just parse the time with the
corresponding golang library.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Aug 14, 2023
1 parent 1bf6b4c commit 2b64c76
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 2b64c76

Please sign in to comment.