✨ Add UTC time-based generators
This commit is contained in:
parent
ee627547a8
commit
1af608d7c9
2 changed files with 19 additions and 0 deletions
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,3 +50,12 @@ func TestWithTime(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, d.Format(FileTimestamp), st)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue