chen3feng / article

本人的文章和笔记,充当懒人 Blog 来用。
9 stars 1 forks source link

A new go TimeFormatter design #30

Open chen3feng opened 2 years ago

chen3feng commented 2 years ago
package timeformat

type Formatter interface {
    func Print(io.Writer, time.Time)
    func ToString(time.Time) string
    func AppendBuffer([]byte, time.Time) []byte
    func Parse(value string) (Time, error)
    func ParseBuffer(io.Reader) (Time, error)
    func ParseBytes([]byte, time.Time) (Time, []byte, error)
}

func Go(layout string) Formatter
func C(layout string) Formatter
func Java(layout string) Formatter
func Predefined(layout ???) Formatter
const (
    ISO_8601 = ...
    AscTime = ...
    HTTP-date
    RFC_2822 = ...
    RFC_3339 = ...
)

Ref

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=net-6.0#datetime-values-and-their-string-representations https://pkg.go.dev/time#pkg-constants https://colobu.com/2021/10/10/faster-time-parsing/ https://github.com/itchyny/timefmt-go https://github.com/phuslu/fasttime https://github.com/lestrrat-go/strftime https://github.com/kpango/fastime