Categorygithub.com/imperfectgo/go-strftime
repositorypackage
0.0.0-20201217024309-32813ff65a33
Repository: https://github.com/imperfectgo/go-strftime.git
Documentation: pkg.go.dev

# README

go-strftime

GoDoc Build Status Go Report Card Coverage

High performance C99-compatible strftime formatter for Go.

Caveats

EXPERIMENTAL Please test before use.

Compatibility

SpecifierDescription
%aabbreviated weekday name (Sun)
%Afull weekday name (Sunday)
%babbreviated month name (Sep)
%Bfull month name (September)
%cthe same as time.ANSIC (%a %b %e %H:%M:%S %)
%C(year / 100) as number. Single digits are preceded by zero (20)
%dday of month as number. Single digits are preceded by zero (21)
%Dequivalent to %m/%d/%y (09/21/14)
%eday of month as number. Single digits are preceded by a blank (21)
%fmicrosecond as a six digit decimal number, zero-padded on the left (001234)
%Fequivalent to %Y-%m-%d (2014-09-21)
%glast two digits of ISO 8601 week-based year
%GISO 8601 week-based year
%hsame as %b
%Hthe hour (24 hour clock) as a number. Single digits are preceded by zero (15)
%Ithe hour (12 hour clock) as a number. Single digits are preceded by zero (03)
%jthe day of the year as a decimal number. Single digits are preced by zeros (264)
%mthe month as a decimal number. Single digits are preceded by a zero (09)
%Mthe minute as a decimal number. Single digits are preceded by a zero (32)
%na newline (\n)
%pAM or PM as appropriate
%Pam or pm as appropriate
%requivalent to %I:%M:%S %p
%Requivalent to %H:%M
%Sthe second as a number. Single digits are preceded by a zero (05)
%ta tab (\t)
%Tequivalent to %H:%M:%S
%uweekday as a decimal number, where Monday is 1
%Uweek of the year as a decimal number (Sunday is the first day of the week)
%VISO 8601 week of the year
%wthe weekday (Sunday as first day of the week) as a number. (0)
%Wweek of the year as a decimal number (Monday is the first day of the week)
%xequivalent to %m/%d/%Y
%Xequivalent to %H:%M:%S
%yyear without century as a number. Single digits are preceded by zero (14)
%Ythe year with century as a number (2014)
%zthe time zone offset from UTC (-0700)
%Ztime zone name (UTC)

Performance

Comparision with the standard library time.(*Time).Format():

> go test -tags bench -bench Bench -cpu 4 -benchmem .

goos: darwin
goarch: amd64
pkg: github.com/imperfectgo/go-strftime
BenchmarkStdTimeFormat-4         3844191               315 ns/op              32 B/op          1 allocs/op
BenchmarkGoStrftime-4            4354848               274 ns/op               0 B/op          0 allocs/op
PASS
ok      github.com/imperfectgo/go-strftime      3.013s

Comparision with other libraries:

> go test -tags benchcomp -bench Bench -cpu 4 -benchmem .

goos: darwin
goarch: amd64
pkg: github.com/imperfectgo/go-strftime
BenchmarkImperfectGo-4                   2713639               445 ns/op              64 B/op          1 allocs/op
BenchmarkImperfectGoNoAlloc-4            3081366               389 ns/op               0 B/op          0 allocs/op
BenchmarkTebeka-4                         311500              3930 ns/op             256 B/op         19 allocs/op
BenchmarkJehiah-4                         712195              1709 ns/op             256 B/op         17 allocs/op
BenchmarkFastly-4                        1934066               615 ns/op              80 B/op          5 allocs/op
BenchmarkLestrrat-4                      1000000              1037 ns/op             240 B/op          3 allocs/op
BenchmarkLestrratCachedString-4          2415724               498 ns/op             128 B/op          2 allocs/op
PASS
ok      github.com/imperfectgo/go-strftime      10.332s

License

This project can be treated as a derived work of time package from golang standard library.

Licensed under the Modified (3-clause) BSD license.