From 1af608d7c9e95da2464c6d9f8a10f6064b4b7cc1 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 10 Mar 2025 11:52:55 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20UTC=20time-based=20generators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generators.go | 10 ++++++++++ generators_test.go | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/generators.go b/generators.go index 403f440..db2bce1 100644 --- a/generators.go +++ b/generators.go @@ -47,3 +47,13 @@ func WithFormattedTime(t time.Time, f string) Option { }) } } + +const FileTimestampNoTZ string = "2006-01-02_03-05-06" + +func WithTimestampUTC() Option { + return WithTimeUTC(time.Now()) +} + +func WithTimeUTC(t time.Time) Option { + return WithFormattedTime(t.UTC(), FileTimestampNoTZ) +} diff --git a/generators_test.go b/generators_test.go index fb3f8c3..6f4cc2d 100644 --- a/generators_test.go +++ b/generators_test.go @@ -50,3 +50,12 @@ func TestWithTime(t *testing.T) { assert.NoError(t, err) assert.Equal(t, d.Format(FileTimestamp), st) } + +func TestWithTimestampUTC(t *testing.T) { + var c config + WithTimestampUTC()(&c) + n := time.Now() + st, err := c.generator() + assert.NoError(t, err) + assert.Equal(t, n.UTC().Format(FileTimestampNoTZ), st) +}