timeutil

package
v0.0.0-...-4be01c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: AGPL-3.0, AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormat = errors.New(`Invalid Format`)
View Source
var ErrInvalidTimeFormat = errors.New(`Invalid time format`)
View Source
var Formats = map[string]TimeFormat{}

Functions

func DefaultTimeInYear

func DefaultTimeInYear(year int, tz *time.Location) time.Time

func Register

func Register(name string, format TimeFormat)

Types

type DefaultTimeFormat

type DefaultTimeFormat struct{}

func (DefaultTimeFormat) Convert

func (DefaultTimeFormat) Convert(h RawTime) (Time, error)

func (DefaultTimeFormat) ConvertWithConverter

func (DefaultTimeFormat) ConvertWithConverter(converter *TimeConverter, t Time) time.Time

func (DefaultTimeFormat) ConvertWithYear

func (DefaultTimeFormat) ConvertWithYear(t Time, year int, tz *time.Location) time.Time

func (DefaultTimeFormat) ExtractRaw

func (DefaultTimeFormat) ExtractRaw(logLine string) (RawTime, string, int, error)

type RFC3339TimeFormat

type RFC3339TimeFormat struct{}

func (RFC3339TimeFormat) Convert

func (RFC3339TimeFormat) Convert(h RawTime) (Time, error)

func (RFC3339TimeFormat) ConvertWithConverter

func (RFC3339TimeFormat) ConvertWithConverter(converter *TimeConverter, t Time) time.Time

func (RFC3339TimeFormat) ConvertWithYear

func (RFC3339TimeFormat) ConvertWithYear(t Time, _ int, tz *time.Location) time.Time

func (RFC3339TimeFormat) ExtractRaw

func (RFC3339TimeFormat) ExtractRaw(logLine string) (RawTime, string, int, error)

type RawTime

type RawTime struct {
	Time   string
	Month  string
	Day    string
	Hour   string
	Minute string
	Second string

	// optional value, available in some syslog configurations
	Year string
}

type Time

type Time struct {
	Month  time.Month
	Year   uint16
	Day    uint8
	Hour   uint8
	Minute uint8
	Second uint8
}

func (Time) Time

func (t Time) Time(year int, tz *time.Location) time.Time

func (Time) Unix

func (t Time) Unix(year int, tz *time.Location) int64

Follows convention from time.Data():

The month, day, hour, min, sec, and nsec values may be outside their usual ranges
and will be normalized during the conversion. For example, October 32 converts to November 1.

type TimeConverter

type TimeConverter struct {
	// contains filtered or unexported fields
}

func NewTimeConverter

func NewTimeConverter(initialTime time.Time, clock timeutil.Clock,
	newYearNotifier func(int, Time, Time),
) TimeConverter

func (*TimeConverter) Convert

func (c *TimeConverter) Convert(t Time) time.Time

type TimeFormat

type TimeFormat interface {
	ExtractRaw(string) (h RawTime, remaining string, patternLen int, err error)
	Convert(RawTime) (Time, error)
	ConvertWithYear(Time, int, *time.Location) time.Time
	ConvertWithConverter(*TimeConverter, Time) time.Time
}

func Get

func Get(name string) (TimeFormat, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL