Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add built in functions to convert timestamps to integers #1390

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tick/stateful/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func init() {
statelessFuncs["isPresent"] = isPresent{}

// Time functions
statelessFuncs["unixNano"] = unixNano{}
statelessFuncs["minute"] = minute{}
statelessFuncs["hour"] = hour{}
statelessFuncs["weekday"] = weekday{}
Expand Down Expand Up @@ -1135,6 +1136,30 @@ func init() {
timeFuncSignature[d] = ast.TInt
}

type unixNano struct {
}

func (unixNano) Reset() {
}

// Return the nanosecond unix timestamp for the given time.
func (unixNano) Call(args ...interface{}) (v interface{}, err error) {
if len(args) != 1 {
return 0, errors.New("unixNano expects exactly one argument")
}
switch a := args[0].(type) {
case time.Time:
v = int64(a.UnixNano())
default:
err = fmt.Errorf("cannot convert %T to time.Time", a)
}
return
}

func (unixNano) Signature() map[Domain]ast.ValueType {
return timeFuncSignature
}

type minute struct {
}

Expand Down