datetime

package
v0.0.0-...-5e0ed37 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package datetime offers transforms useful for processing timestamps

Index

Constants

This section is empty.

Variables

View Source
var Day = &pipescript.Transform{
	Name:        "day",
	Description: "Returns the number of days since Jan 1 1970 in the given time zone.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = int64(tval.Sub(st) / (24 * time.Hour))
		return out, nil
	}),
}
View Source
var Dayhour = &pipescript.Transform{
	Name:        "dayhour",
	Description: "Returns the hour in a day during which the datapoint happened.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = tval.Hour()
		return out, nil
	}),
}
View Source
var Hour = &pipescript.Transform{
	Name:        "hour",
	Description: "Returns the number of hours since Jan 1 1970 in the given time zone.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = int64(tval.Sub(st) / time.Hour)
		return out, nil
	}),
}
View Source
var Month = &pipescript.Transform{
	Name:        "month",
	Description: "Returns the number of months since Jan 1 1970 in the given time zone.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = int64(12*(tval.Year()-1970) + int(tval.Month()))
		return out, nil
	}),
}
View Source
var Monthday = &pipescript.Transform{
	Name:        "monthday",
	Description: "Returns the number of day in the datapoint's month (int)",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = tval.Day()
		return out, nil
	}),
}
View Source
var Tshift = pipescript.Transform{
	Name:          "tshift",
	Description:   "Shift the datapoint timestamp by a constant number of seconds",
	Documentation: string(resources.MustAsset("docs/transforms/tshift.md")),
	Args: []pipescript.TransformArg{
		{
			Description: "The number of seconds to shift the timestamp",
			Type:        pipescript.ConstArgType,
		},
	},
	Constructor: func(transform *pipescript.Transform, consts []interface{}, pipes []*pipescript.Pipe) (pipescript.TransformIterator, error) {
		shiftby, ok := pipescript.Float(consts[0])
		if !ok {
			return nil, errors.New("Must shift by a number")
		}
		return tshiftIterator{shiftby}, nil
	},
}
View Source
var Week = &pipescript.Transform{
	Name:        "week",
	Description: "Returns the number of weeks since Jan 5 1970 (First Monday after unix time) in the given time zone.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)

		st = time.Date(1970, time.January, 5, 0, 0, 0, 0, tz)
		out.Data = int64(tval.Sub(st) / (7 * 24 * time.Hour))
		return out, nil
	}),
}
View Source
var Weekday = &pipescript.Transform{
	Name:        "weekday",
	Description: "Returns the weekday during which the datapoint happened ('Monday','Tuesday'...)",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "string",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = tval.Weekday().String()
		return out, nil
	}),
}
View Source
var Year = &pipescript.Transform{
	Name:        "year",
	Description: "Returns the year of the datapoint in the given time zone.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = tval.Year()
		return out, nil
	}),
}
View Source
var Yearday = &pipescript.Transform{
	Name:        "yearday",
	Description: "Returns the day of the year during which the datapoint happened [1,365] non-leap, and [1,366] for leap years.",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "integer",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = tval.YearDay()
		return out, nil
	}),
}
View Source
var Yearmonth = &pipescript.Transform{
	Name:        "yearmonth",
	Description: "Returns the month name during which the datapoint happened ('January','February'...)",
	Args: []pipescript.TransformArg{
		timezoneArg,
	},
	OutputSchema: map[string]interface{}{
		"type": "string",
	},
	Constructor: NewTimeBasic(0, func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error) {
		tval := dp.Time().In(tz)
		out.Data = tval.Month().String()
		return out, nil
	}),
}

Functions

func NewTimeBasic

func NewTimeBasic(tzarg int, f TimeBasicFunc) pipescript.TransformConstructor

func Register

func Register()

Types

type TimeBasicFunc

type TimeBasicFunc func(dp *pipescript.Datapoint, args []*pipescript.Datapoint, consts []interface{}, pipes []*pipescript.Pipe, tz *time.Location, st time.Time, out *pipescript.Datapoint) (*pipescript.Datapoint, error)

Jump to

Keyboard shortcuts

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