Documentation
¶
Index ¶
- Constants
- Variables
- func ExtendParserDefaults(opts ...ParserOption)
- func Parse(layout string, value string) (time.Time, error)
- func ResetParserDefaults()
- func SetParserDefaults(opts ...ParserOption)
- func SetStdClock(c Clock)
- type Clock
- type DateUnit
- type LayoutDetails
- type LayoutFormat
- type MutatingTime
- func (t *MutatingTime) SetDay(day int) *MutatingTime
- func (t *MutatingTime) SetHour(hour int) *MutatingTime
- func (t *MutatingTime) SetMinute(minute int) *MutatingTime
- func (t *MutatingTime) SetMonth(month time.Month) *MutatingTime
- func (t *MutatingTime) SetNanosecond(nanosecond int) *MutatingTime
- func (t *MutatingTime) SetSecond(second int) *MutatingTime
- func (t *MutatingTime) SetYear(v int) *MutatingTime
- func (t *MutatingTime) Time() time.Time
- func (t *MutatingTime) TruncateToDay() *MutatingTime
- type Parser
- type ParserOption
- func AcceptAliases() ParserOption
- func AcceptUnixMicro() ParserOption
- func AcceptUnixMilli() ParserOption
- func AcceptUnixNano() ParserOption
- func AcceptUnixSeconds() ParserOption
- func GetParserDefaults() []ParserOption
- func WithCustomAliases(customAliases map[string]func(time.Time) time.Time) ParserOption
- func WithCustomClock(c Clock) ParserOption
- func WithLayouts(layouts ...string) ParserOption
- type StdClock
- type TimeNamedWaypointFile
- type TimeNamedWaypointFiles
- type TraverseDirection
- type TraverseNodesMode
- type TraverseOption
- type Voyager
- type Waypoint
- type WaypointFile
- type WaypointFiles
- type WaypointGroup
- type WaypointString
- type WaypointStrings
Constants ¶
const ( LayoutFormatUndefined LayoutFormat = iota // LayoutFormatGo is a format that is supported by Go time.Parse LayoutFormatGo = 1 << (iota - 1) // LayoutFormatUnixTimestamp is a format that parses time from Unix timestamp (seconds or milliseconds) LayoutFormatUnixTimestamp )
const ( LayoutTimestampSeconds = "U@" LayoutTimestampMilliseconds = "U@000" LayoutTimestampMicroseconds = "U@000000" LayoutTimestampNanoseconds = "U@000000000" )
Variables ¶
var DateUnitsDict = struct { Day DateUnit Month DateUnit Year DateUnit UnixSecond DateUnit UnixMillisecond DateUnit UnixMicrosecond DateUnit UnixNanosecond DateUnit }{ Day: Day, Month: Month, Year: Year, UnixSecond: UnixSecond, UnixMillisecond: UnixMillisecond, UnixMicrosecond: UnixMicrosecond, UnixNanosecond: UnixNanosecond, }
DateUnitsDict holds all available DateUnits
var DefaultParser = func() *Parser { return NewParser(defaultParserOptions...) }
var LayoutFormatDict = struct { GoFormat LayoutFormat UnixTimestamp LayoutFormat }{ GoFormat: LayoutFormatGo, UnixTimestamp: LayoutFormatUnixTimestamp, }
LayoutFormatDict holds all available LayoutFormats
Functions ¶
func ExtendParserDefaults ¶
func ExtendParserDefaults(opts ...ParserOption)
func ResetParserDefaults ¶
func ResetParserDefaults()
func SetParserDefaults ¶
func SetParserDefaults(opts ...ParserOption)
func SetStdClock ¶
func SetStdClock(c Clock)
SetStdClock sets the default clock to use Note: this considered to be called from tests, so time.Now() is mockable
Types ¶
type DateUnit ¶
type DateUnit int
DateUnit stays for the unit of a date like Day/Month/Year/etc
const ( UnitUndefined DateUnit = iota // Day as day of the month // TODO(nice-to-have) support day of the week + day of the year Day DateUnit = 1 << (iota - 1) Week // not supported yet Month Quarter // not supported yet Year // UnixSecond as well as UnixMillisecond, UnixMicrosecond, UnixNanosecond // are special units for Unix timestamps UnixSecond UnixMillisecond UnixMicrosecond UnixNanosecond )
type LayoutDetails ¶
type LayoutDetails struct { // MinimalUnit e.g. Day for "2006-01-02" and Month for "2006-01" MinimalUnit DateUnit // Format is the format of the time used in the layout Format LayoutFormat // Units met in layout Units []DateUnit }
LayoutDetails stores parsed meta information about given layout string e.g. "2006-02-01"
func ParseLayout ¶
func ParseLayout(layout string) *LayoutDetails
Note: it's a pretty hacky/weak function, but we're OK with it for now
func (*LayoutDetails) HasUnit ¶
func (lm *LayoutDetails) HasUnit(q DateUnit) bool
type LayoutFormat ¶
type LayoutFormat int
func (LayoutFormat) String ¶
func (lf LayoutFormat) String() string
type MutatingTime ¶
type MutatingTime struct {
// contains filtered or unexported fields
}
MutatingTime is a wrapper of a standard time.Time so it can be mutated via helper methods
Example:
t, _ := time.Parse("...") Mutate(&t).SomeModifyingMethod() // leads to update the t
func Mutate ¶
func Mutate(v *time.Time) *MutatingTime
func (*MutatingTime) SetDay ¶
func (t *MutatingTime) SetDay(day int) *MutatingTime
SetDay overrides day of the time Note: Feb2 .SetDay(31) will lead to ~Mar2-3 (depending on days in Feb)
func (*MutatingTime) SetHour ¶
func (t *MutatingTime) SetHour(hour int) *MutatingTime
SetHour overrides hour of the time
func (*MutatingTime) SetMinute ¶
func (t *MutatingTime) SetMinute(minute int) *MutatingTime
SetMinute overrides minute of the time
func (*MutatingTime) SetMonth ¶
func (t *MutatingTime) SetMonth(month time.Month) *MutatingTime
SetMonth overrides month of the time
func (*MutatingTime) SetNanosecond ¶
func (t *MutatingTime) SetNanosecond(nanosecond int) *MutatingTime
SetNanosecond overrides nanosecond of the time
func (*MutatingTime) SetSecond ¶
func (t *MutatingTime) SetSecond(second int) *MutatingTime
SetSecond overrides second of the time
func (*MutatingTime) SetYear ¶
func (t *MutatingTime) SetYear(v int) *MutatingTime
SetYear overrides year of the time
func (*MutatingTime) Time ¶
func (t *MutatingTime) Time() time.Time
func (*MutatingTime) TruncateToDay ¶
func (t *MutatingTime) TruncateToDay() *MutatingTime
TruncateToDay overrides hour, minute, second, nanosecond to zero
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func NewParser ¶
func NewParser(options ...ParserOption) *Parser
func (*Parser) JustParse ¶
JustParse is a shortcut for Parse("", value) (so using all parser's accepted layouts)
type ParserOption ¶
type ParserOption func(*Parser)
func AcceptAliases ¶
func AcceptAliases() ParserOption
func AcceptUnixMicro ¶
func AcceptUnixMicro() ParserOption
func AcceptUnixMilli ¶
func AcceptUnixMilli() ParserOption
func AcceptUnixNano ¶
func AcceptUnixNano() ParserOption
func AcceptUnixSeconds ¶
func AcceptUnixSeconds() ParserOption
func GetParserDefaults ¶
func GetParserDefaults() []ParserOption
func WithCustomAliases ¶
func WithCustomClock ¶
func WithCustomClock(c Clock) ParserOption
func WithLayouts ¶
func WithLayouts(layouts ...string) ParserOption
type TimeNamedWaypointFile ¶
type TimeNamedWaypointFile struct { *WaypointFile // contains filtered or unexported fields }
TimeNamedWaypointFile is a Waypoint implementation for files/directories
func NewTimeNamedWaypointFile ¶
func NewTimeNamedWaypointFile(path string, fullLayout string, parentArg ...*TimeNamedWaypointFile) (*TimeNamedWaypointFile, error)
func (*TimeNamedWaypointFile) Time ¶
func (w *TimeNamedWaypointFile) Time() time.Time
type TimeNamedWaypointFiles ¶
type TimeNamedWaypointFiles []*TimeNamedWaypointFile
type TraverseDirection ¶
type TraverseDirection string
TraverseDirection is a direction for traversing (e.g. past or future)
const ( TraverseDirectionPast TraverseDirection = "past" TraverseDirectionFuture TraverseDirection = "future" )
type TraverseNodesMode ¶
type TraverseNodesMode string
TraverseNodesMode specifies which type of nodes to traverse (e.g. leaves only or containers only)
const ( TraverseLeavesOnly TraverseNodesMode = "leaves_only" TraverseContainersOnly TraverseNodesMode = "containers_only" TraverseAllNodes TraverseNodesMode = "all" )
type TraverseOption ¶
type TraverseOption func(*traverseConfig)
TraverseOption defines functional options for the Traverse function
func O_CONTAINERS_ONLY ¶
func O_CONTAINERS_ONLY() TraverseOption
O_CONTAINERS_ONLY returns a TraverseOption for traversing only container nodes
func O_FUTURE ¶
func O_FUTURE() TraverseOption
O_FUTURE returns a TraverseOption for traversing in Future direction
func O_LEAVES_ONLY ¶
func O_LEAVES_ONLY() TraverseOption
O_LEAVES_ONLY returns a TraverseOption for traversing only leaf nodes
func O_NON_CALENDAR ¶
func O_NON_CALENDAR() TraverseOption
O_NON_CALENDAR returns a TraverseOption for including non calendar nodes
func O_PAST ¶
func O_PAST() TraverseOption
O_PAST returns a TraverseOption for traversing in Past direction
type Voyager ¶
type Voyager struct {
// contains filtered or unexported fields
}
Voyager is a wrapper for a waypoint that allows for traversing through it
func NewVoyager ¶
func (*Voyager) Find ¶
Find returns the all found Waypoints that match given time (as a string) e.g. Find("yesterday") returns all waypoints whose time is in the "yesterday" range
type Waypoint ¶
type Waypoint interface { // Identifier returns the identifier of the object. // E.g. for file waypoints it can be file path. Identifier() string // Time returns the time of the object. Time() time.Time // IsContainer returns true if the object can contain other objects. // E.g. for directories, it should return true. IsContainer() bool // Children returns the children of the object if it's a container. // E.g. for directories, it should return the list of files and directories inside. Children() []Waypoint }
Waypoint is an interface for objects that have a time.
func AllChildren ¶
AllChildren is a helper function that gets ALL children of a waypoint (recursively)
func NewWaypointGroup ¶
NewWaypointGroup create a group for given waypoints
func WaypointsFromStrings ¶
type WaypointFile ¶
type WaypointFile struct {
// contains filtered or unexported fields
}
WaypointFile is a Waypoint implementation for files/directories
func NewWaypointFile ¶
func (*WaypointFile) Children ¶
func (w *WaypointFile) Children() []Waypoint
func (*WaypointFile) Identifier ¶
func (w *WaypointFile) Identifier() string
func (*WaypointFile) IsContainer ¶
func (w *WaypointFile) IsContainer() bool
func (*WaypointFile) Time ¶
func (w *WaypointFile) Time() time.Time
type WaypointFiles ¶
type WaypointFiles []*WaypointFile
type WaypointGroup ¶
type WaypointGroup struct {
// contains filtered or unexported fields
}
WaypointGroup stands for a simple implementation of Waypoint that is a container for other waypoints
func (*WaypointGroup) Children ¶
func (wg *WaypointGroup) Children() []Waypoint
func (*WaypointGroup) Identifier ¶
func (wg *WaypointGroup) Identifier() string
func (*WaypointGroup) IsContainer ¶
func (wg *WaypointGroup) IsContainer() bool
func (*WaypointGroup) Time ¶
func (wg *WaypointGroup) Time() time.Time
Time returns group's time. For now group itself doesn't have a specific time TODO(nice-to-have): this maybe configurable, e.g. no-time/min-time(children)/max-time(children)/time(children[0]), etc
type WaypointString ¶
type WaypointString struct {
// contains filtered or unexported fields
}
WaypointString is a Waypoint implementation for a string that represents time
func NewWaypointString ¶
func NewWaypointString(v string, layoutArg ...string) *WaypointString
func (*WaypointString) Children ¶
func (w *WaypointString) Children() []Waypoint
func (*WaypointString) Identifier ¶
func (w *WaypointString) Identifier() string
func (*WaypointString) IsContainer ¶
func (w *WaypointString) IsContainer() bool
func (*WaypointString) Time ¶
func (w *WaypointString) Time() time.Time
func (*WaypointString) Voyager ¶
func (w *WaypointString) Voyager(parserArg ...*Parser) *Voyager
type WaypointStrings ¶
type WaypointStrings []*WaypointString