Skip to content

Commit

Permalink
add epoch file to time resource output
Browse files Browse the repository at this point in the history
  • Loading branch information
cscanlin-kwh committed Mar 13, 2024
1 parent 451833d commit f46b019
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ given version, or if there is no version given.
Fetches the given timestamp. Creates two files:
1. `input` which contains the request provided by Concourse
1. `timestamp` which contains the fetched version in the following format: `2006-01-02 15:04:05.999999999 -0700 MST`
1. `epoch` which contains the fetched version as a Unix epoch Timestamp (integer only)
#### Parameters
Expand Down
9 changes: 8 additions & 1 deletion in_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"time"

"github.com/concourse/time-resource/models"
Expand Down Expand Up @@ -38,10 +39,16 @@ func (*InCommand) Run(destination string, request models.InRequest) (models.InRe

timeFile, err := os.Create(filepath.Join(destination, "timestamp"))
if err != nil {
return models.InResponse{}, fmt.Errorf("creating input file: %w", err)
return models.InResponse{}, fmt.Errorf("creating timestamp file: %w", err)
}
timeFile.WriteString(versionTime.Format("2006-01-02 15:04:05.999999999 -0700 MST"))

epochFile, err := os.Create(filepath.Join(destination, "epoch"))
if err != nil {
return models.InResponse{}, fmt.Errorf("creating epoch file: %w", err)
}
epochFile.WriteString(strconv.FormatInt(versionTime.Unix(), 10))

inVersion := models.Version{Time: versionTime}
response := models.InResponse{Version: inVersion}

Expand Down

0 comments on commit f46b019

Please sign in to comment.