Skip to content

Repository files navigation

Tuesday: Ruby-Compatible Strftime for Go

Test badgeGolangci-lint badgeCoveralls badgeGo Report Card badgeGo ReferenceMIT License

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.

Install

go get github.com/osteele/tuesday@latest

Usage

package 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)

Compatibility

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; E and O modifiers use the corresponding unmodified conversion.
  • %Z uses the name attached to the Go time.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 %:::z follow the corresponding Ruby DateTime, 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.

Development

go test ./...go test -fuzz=FuzzStrftimego test -bench=. -benchmem

References

License

MIT License

About

Ruby-compatible strftime for golang

Topics

Resources

Stars

13 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages