Awesome Go

tuesday

CategoryDate and Time
SubcategoryDate and Time
Stars13

Ruby-compatible Strftime function

About tuesday

Tuesday: Ruby-Compatible Strftime for Go

Test badge Golangci-lint badge Coveralls badge Go Report Card badge Go Reference MIT 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"
)

func main() {
	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)
	if err != 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")
if err != 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=FuzzStrftime
go test -bench=. -benchmem

References

License

MIT License

Frequently Asked Questions

What is tuesday?

tuesday is a Date and Time library for the Go programming language. Ruby-compatible Strftime function

How do I install tuesday?

Install tuesday with the Go module system using `go get osteele/tuesday`. Check the repository for the current installation instructions.

What category does tuesday belong to?

tuesday is listed under Date and Time, specifically Date and Time.

← Back to Date and Time