From cb5f7a4a2b817fc4665920d26f76959182ba010f Mon Sep 17 00:00:00 2001 From: cscanlin Date: Tue, 12 Mar 2024 17:24:31 -0700 Subject: [PATCH] add epoch file to time resource output Signed-off-by: cscanlin --- README.md | 1 + in_command.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 316b833..b6ac693 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/in_command.go b/in_command.go index 4ea96cf..2c2954d 100644 --- a/in_command.go +++ b/in_command.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "time" "github.com/concourse/time-resource/models" @@ -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}