Skip to content

Commit

Permalink
Merged pull request #1390 from influxdata/md-convert-time-to-value
Browse files Browse the repository at this point in the history
WIP: Add built in functions to convert timestamps to integers
  • Loading branch information
nathanielc committed Jul 25, 2017
2 parents fc8f75d + f4fd104 commit def1693
Showing 1 changed file with 25 additions and 0 deletions.
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

0 comments on commit def1693

Please sign in to comment.