Documentation
¶
Overview ¶
Package strftime parses and formats instants with strftime-style formats, the ones Polars, chrono, Python and C share: "%Y-%m-%d %H:%M:%S".
Why not Go's layouts ¶
time.Parse reads a layout by example — "2006-01-02" — so translating a strftime format into one would hand every literal in the format to Go's matcher too: a literal "1" in "Q1 %Y" reads as a month, and "Mon" as a weekday. A format here is compiled into directives and literals, and only the directives are fields.
What it reads ¶
%Y year, four digits, or signed past 0000–9999 (+10000) %m month 01–12 %d day 01–31 %e day, space-padded %y year 00–99: 00–69 are 2000–2069 and 70–99 are 1970–1999, as chrono reads them %j day of year 001–366 %H hour 00–23 %I hour 01–12 %p AM/PM %M minute 00–59 %S second 00–59 %f fraction, 1–9 digits as written %.f the same after a dot, optional %.3f %.6f %.9f a dot and exactly 3, 6, 9 digits %3f %6f %9f the same, no dot %b %h month abbreviation %B month name %a weekday abbreviation %A weekday %z offset +hhmm, read with or without the colon %:z offset +hh:mm %Z zone name (formatting only) %T %H:%M:%S %D %m/%d/%y %F %Y-%m-%d %R %H:%M %% a percent sign
Names are English. Parsing is strict about shape: a number takes at most its width, a date must exist (no 30 February), and the whole input must be consumed. A weekday name is read and not checked against the date.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fields ¶
type Fields struct {
Year, Month, Day int
Hour, Minute, Second int
Nanos int
Offset int
HasDate, HasTime, HasZone bool
}
Fields is what a parse found. Year, Month and Day are a calendar date when HasDate is set; Offset is seconds east of UTC when HasZone is.
type Format ¶
type Format struct {
// What the directives can supply, for the callers that refuse a format that
// cannot say what their type needs. HasDate is any part of a date, which is
// what a Time cannot format; ParsesDate is a whole one — a year with a month
// and a day, or with %j — which is what Parse needs to produce a date at all.
HasDate, HasTime, HasZone bool
ParsesDate bool
// HasZoneName is %Z, which is formatted and cannot be read back.
HasZoneName bool
// contains filtered or unexported fields
}
Format is a compiled format.
func (*Format) Append ¶
Append formats t, in its own location, onto dst. zone reports whether t's zone is meaningful: a naive instant has none, and %z and %Z refuse to invent one.