♻️ Refactor Timestamp Generator to single function with options

This commit is contained in:
Dan Jones 2025-03-14 17:39:42 -05:00
commit 61a5199699
5 changed files with 113 additions and 67 deletions

38
gen_ts_examples_test.go Normal file
View file

@ -0,0 +1,38 @@
package nomino_test
import (
"fmt"
"time"
"codeberg.org/danjones000/nomino"
)
func ExampleTimestamp_withTime() {
tz, _ := time.LoadLocation("America/New_York")
ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz)
gen := nomino.Timestamp(nomino.TSTime(ts))
conf := nomino.NewConfig(nomino.WithGenerator(gen))
s, _ := nomino.Make(conf)
fmt.Println(s)
// Output: 2009-01-20T12-05-00-0500.txt
}
func ExampleTimestamp_withFormat() {
tz, _ := time.LoadLocation("America/New_York")
ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz)
gen := nomino.Timestamp(nomino.TSTime(ts), nomino.TSFormat("2006#01#02<>15|04|05-0700"))
conf := nomino.NewConfig(nomino.WithGenerator(gen))
s, _ := nomino.Make(conf)
fmt.Println(s)
// Output: 2009#01#20<>12|05|00-0500.txt
}
func ExampleTimestamp_withUTC() {
tz, _ := time.LoadLocation("America/New_York")
ts := time.Date(2009, time.January, 20, 12, 5, 0, 0, tz)
gen := nomino.Timestamp(nomino.TSTime(ts), nomino.TSUTC())
conf := nomino.NewConfig(nomino.WithGenerator(gen))
s, _ := nomino.Make(conf)
fmt.Println(s)
// Output: 2009-01-20T17-05-00.txt
}