Documentation ¶
Index ¶
- func ConvertTimeToken(input string) (string, error)
- func HasGoTimeToken(layout string) bool
- type EsTimeParser
- func (p EsTimeParser) FormatNumber(t time.Time) int64
- func (p EsTimeParser) FormatString(t time.Time, idx uint) string
- func (t EsTimeParser) Layout() []string
- func (t EsTimeParser) ParseJson(data []byte) (time.Time, error)
- func (t EsTimeParser) ParseNumber(n int64) (time.Time, error)
- func (t EsTimeParser) ParseString(s string) (time.Time, error)
- type FormatError
- type MultiLayout
- type NumberParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertTimeToken ¶
ConvertTimeToken converts Java Time tokens included in input into Go std time counterparts. input is still allowed to have Go std time token. Conversion for those tokens are no-op.
This functions does not process the optional part (enclosed by a `[` and a `]`) of time tokens. The input must be treated by optionalstring package if you wish to use the optional format.
Allowed input tokens are what they are for https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html. But this package omits support for tokens described below as the std time package does not support it:
- G(era, AD; Anno Domini; A)
- Q/q(quarter-of-year, 3; 03; Q3; 3rd quarter)
- Y(week-based-year, 1996; 96)
- w(week-of-week-based-year, 27)
- W(week-of-month, 4)
- e/c(localized day-of-week, 2; 02; Tue; Tuesday; T)
- F(week-of-month, 3)
- K(hour-of-am-pm (0-11), 0)
- k(clock-hour-of-am-pm (1-24), 0)
- A(milli-of-day, 1234)
- n(nano-of-second, 987654321)
- N(nano-of-day, 1234000000)
- V(time-zone ID, America/Los_Angeles; Z; -08:30)
- O(localized zone-offset, GMT+8; GMT+08:00; UTC-08:00;)
`S` is omitted since Go supports fraction-of-time only when there is a preceding dot character. You can still use `S` but only with a leading dot.
Its detailed conversion rule is defined as a following conversion table:
var tokenTable = map[timeFormatToken]goTimeFmtToken{ `uuuu`: `2006`, `uu`: `06`, `yyyy`: `2006`, `yy`: `06`, `DDD`: `002`, `M`: `1`, `MM`: `01`, `L`: `1`, `LL`: `01`, `d`: `2`, `dd`: `02`, `EEEE`: `Monday`, `EEE`: `Mon`, `a`: `PM`, `hh`: `03`, `h`: `3`, `HH`: `15`, `mm`: `04`, `m`: `4`, `ss`: `05`, `s`: `5`, `z`: `MST`, `XXX`: `Z070000`, `XX`: `Z0700`, `X`: `Z07`, `xxx`: `-070000`, `xx`: `-0700`, `x`: `-07`, `Z`: `Z0700`, // further more `MMMM`: `January`, `MMM`: `Jan`, // preservation for Go tokens. `MST`: `MST`, `Z070000`: `Z070000`, `Z07`: `Z07`, `Z07:00:00`: `Z07:00:00`, `-0700`: `-0700`, `-070000`: `-070000`, `-07`: `-07`, `-07:00`: `-07:00`, `-07:00:00`: `-07:00:00`, }
func HasGoTimeToken ¶
Types ¶
type EsTimeParser ¶
type EsTimeParser struct {
// contains filtered or unexported fields
}
func FromGoTimeLayout ¶
func FromGoTimeLayout(layouts []string, numParser NumberParser) (EsTimeParser, error)
func FromGoTimeLayoutUnsafe ¶
func FromGoTimeLayoutUnsafe(layouts []string, numParser NumberParser) EsTimeParser
func FromJavaDateTimeLike ¶
func FromJavaDateTimeLike(layouts []string, numParser NumberParser) (EsTimeParser, error)
func (EsTimeParser) FormatNumber ¶
func (p EsTimeParser) FormatNumber(t time.Time) int64
func (EsTimeParser) FormatString ¶
func (p EsTimeParser) FormatString(t time.Time, idx uint) string
func (EsTimeParser) Layout ¶
func (t EsTimeParser) Layout() []string
func (EsTimeParser) ParseNumber ¶
func (t EsTimeParser) ParseNumber(n int64) (time.Time, error)
func (EsTimeParser) ParseString ¶
func (t EsTimeParser) ParseString(s string) (time.Time, error)
type FormatError ¶
type FormatError struct {
// contains filtered or unexported fields
}
func (*FormatError) Error ¶
func (e *FormatError) Error() string
type MultiLayout ¶
type MultiLayout struct {
// contains filtered or unexported fields
}
MultiLayout is a set of time token layouts which can be used with time.Parse() or time.ParseInLocation. Layouts are internally sorted descendent order, longer is placed first.
func NewMultiLayout ¶
func NewMultiLayout(layouts []string) (MultiLayout, error)
NewMultiLayout clones, sorts, dedups and validates input layouts.
Sorting is stable: It sorts layouts by length in descending order, breaking ties by string comparison in descending order.
Each one of layouts must have at least a single Go std's time layout token. Otherwise it returns an error.
func NewMultiLayoutUnsafe ¶
func NewMultiLayoutUnsafe(layouts []string) MultiLayout
NewMultiLayoutUnsafe returns MultiLayout without any safety checking which is otherwise employed in NewMultiLayout.
Do not use this function unless a caller knows layouts are sorted, being valid that the time.Parse cause no error and dedupped.
func (MultiLayout) AddLayout ¶
func (l MultiLayout) AddLayout(layout ...string) (MultiLayout, error)
func (MultiLayout) Clone ¶
func (l MultiLayout) Clone() []string
func (MultiLayout) ParseInLocation ¶
type NumberParser ¶
type NumberParser string
NumberParser is a parser which decodes JSON number to time.Time. It only can be "epoch_millis" or "epoch_second".
const ( None NumberParser = "" Millis NumberParser = "epoch_millis" Second NumberParser = "epoch_second" )
func NumParser ¶
func NumParser(numberFmt string) NumberParser
Directories ¶
Path | Synopsis |
---|---|
builtinlayouts is collection of date formats built in Elasticsearch
|
builtinlayouts is collection of date formats built in Elasticsearch |