Documentation ¶
Overview ¶
Package timez contains time functionality.
Index ¶
- Constants
- Variables
- func DateUTC(t time.Time) string
- func FormatFunc(layout string) func(time.Time) string
- func MustParse(layout, value string) time.Time
- func NamedLayouts() []string
- func ParseDateOrTimestampUTC(s string) (time.Time, error)
- func ParseDateUTC(s string) (time.Time, error)
- func ParseLocalDate(s string) (time.Time, error)
- func ParseTimestampUTC(s string) (time.Time, error)
- func TimestampToDate(s string) string
- func TimestampToRFC3339(s string) string
- func TimestampUTC(t time.Time) string
Constants ¶
const ( // DefaultDatetime is the name of the default datetime layout. // Its value is NOT the actual layout value itself. // Use FormatFunc(DefaultDatetime) to get a format function. DefaultDatetime = rfc3339Z // DefaultDate is the name of the default date layout. // Its value is NOT the actual layout value itself. // Use FormatFunc(DefaultDate) to get a format function. DefaultDate = dateOnly // DefaultTime is the name of the default time layout. // Its value is NOT the actual layout value itself. // Use FormatFunc(DefaultTime) to get a format function. DefaultTime = timeOnly )
const ( // ISO8601 is (our definition of) the ISO8601 timestamp with millisecond // precision. ISO8601 = "2006-01-02T15:04:05.000Z07:00" // ISO8601Z is the same as ISO8601, but in zulu time. ISO8601Z = "2006-01-02T15:04:05.000Z" // RFC3339Variant is a variant using "-0700" suffix. RFC3339Variant = "2006-01-02T15:04:05-0700" // RFC3339Z is an RFC3339 format, in zulu time. RFC3339Z = "2006-01-02T15:04:05Z" // RFC3339NanoZ is time.RFC3339Nano in zulu time. RFC3339NanoZ = "2006-01-02T15:04:05.999999999Z" // ExcelLongDate is the "long date" used by Excel. ExcelLongDate = "Monday, January 2, 2006" // ExcelDatetimeMDYNoSeconds is a datetime format used by Excel. // The date part is MM/D/YY. ExcelDatetimeMDYNoSeconds = "01/2/06 15:04" // ExcelDatetimeMDYSeconds is similar to ExcelDatetimeMDYNoSeconds, // but includes a seconds component in the time. ExcelDatetimeMDYSeconds = "01/2/06 15:04:05" // DateHourMinuteSecond has date followed by time, including seconds. DateHourMinuteSecond = "2006-01-02 15:04:05" // DateHourMinute has date followed by time, not including seconds. DateHourMinute = "2006-01-02 15:04" )
Variables ¶
var TimestampLayouts = map[string]string{ "RFC3339": time.RFC3339, "RFC3339Z": RFC3339Z, "ISO8601": ISO8601, "ISO8601Z": ISO8601Z, "RFC3339Nano": time.RFC3339Nano, "RFC3339NanoZ": RFC3339NanoZ, "ANSIC": time.ANSIC, "UnixDate": time.UnixDate, "RubyDate": time.RubyDate, "RFC8222": time.RFC822, "RFC8222Z": time.RFC822Z, "RFC850": time.RFC850, "RFC1123": time.RFC1123, "RFC1123Z": time.RFC1123Z, "Stamp": time.Stamp, "StampMilli": time.StampMilli, "StampMicro": time.StampMicro, "StampNano": time.StampNano, "DateHourMinuteSecond": DateHourMinuteSecond, "DateHourMinute": DateHourMinute, "ExcelDatetimeMDYSeconds": ExcelDatetimeMDYSeconds, "ExcelDatetimeMDYNoSeconds": ExcelDatetimeMDYNoSeconds, }
TimestampLayouts is a map of timestamp layout names to layout string.
Functions ¶
func FormatFunc ¶
FormatFunc returns a time format function. If layout is a named layout (per NamedLayouts, ignoring case), a func for the named layout is returned. Otherwise layout is treated as a strftime layout (NOT as a stdlib time layout).
func NamedLayouts ¶
func NamedLayouts() []string
NamedLayouts returns a new slice containing the layout names supported by FormatFunc.
func ParseDateOrTimestampUTC ¶
ParseDateOrTimestampUTC attempts to parse s as either a date (see ParseDateUTC), or timestamp (see ParseTimestampUTC). The returned time is in UTC.
func ParseDateUTC ¶
ParseDateUTC accepts a date string s, returning the UTC midnight time of that date. Arg s must in format "2006-01-02".
func ParseLocalDate ¶
ParseLocalDate accepts a date string s, returning the local midnight time of that date. Arg s must in format "2006-01-02".
func ParseTimestampUTC ¶
ParseTimestampUTC is the counterpart of TimestampUTC. It attempts to parse s first in ISO8601, then time.RFC3339 format, falling back to the subtly different variants.
func TimestampToDate ¶
TimestampToDate takes a ISO8601, ISO8601_X or RFC3339 timestamp, and returns just the date component. On error, the empty string is returned.
func TimestampToRFC3339 ¶
TimestampToRFC3339 takes a ISO8601, ISO8601_X or RFC3339 timestamp, and returns RFC3339. That is, the milliseconds are dropped. On error, the empty string is returned.
func TimestampUTC ¶
TimestampUTC returns the ISO8601 representation of t in UTC.
Types ¶
This section is empty.