Tuesday formats Go time.Time values with Ruby-compatible strftime format
strings. It supports padding and case flags, field widths, fractional seconds,
epoch time, and colon-delimited timezone offsets.
Tuesday was developed for use by Liquid and Gojekyll.
go get github.com/osteele/tuesday@latestpackage main
import (
"fmt""time""github.com/osteele/tuesday"
)
funcmain() {
value:=time.Date(2026, 8, 11, 15, 4, 5, 123456789, time.UTC)
formatted, err:=tuesday.Strftime("%Y-%m-%d %H:%M:%S.%3N %:z", value)
iferr!=nil {
panic(err)
}
fmt.Println(formatted)
}Output:
2026-08-11 15:04:05.123 +00:00
Compile formats that are used repeatedly. A compiled formatter is immutable and safe for concurrent use:
formatter, err:=tuesday.Compile("%a, %b %d, %Y")
iferr!=nil {
panic(err)
}
formatted:=formatter.Format(value)Tuesday targets the formatting behavior of Ruby 3.4
Time#strftime. Its differential
test matrix also uses DateTime#strftime for %Q, which Ruby Time does not
implement. Tuesday additionally supports %+ as an extension; Ruby Time
does not implement %+, while Ruby DateTime prints the UTC offset rather
than the location name.
- Month and weekday names use Go's English names, corresponding to Ruby's C
locale. Locale-specific names are not supported;
EandOmodifiers use the corresponding unmodified conversion. %Zuses the name attached to the Gotime.Location. A numeric offset alone does not imply a timezone abbreviation.- Unsupported directives are copied to the result unchanged.
- Supported field widths greater than 1 MiB return an error to prevent excessive allocation.
%Q,%N,%L,%:z,%::z, and%:::zfollow the corresponding RubyDateTime, fractional-second, and timezone conventions.
The Ruby differential test is skipped when Ruby is unavailable. The checked-in Go tests remain sufficient to run the package test suite without Ruby.
go test ./...go test -fuzz=FuzzStrftimego test -bench=. -benchmemMIT License