Datetime advanced filtering

Datetime advanced filtering

Hello!

Is it possible to somehow “add 1 hour” (or similar operations) to a variable that contains a Datetime value?

What I want to do

query getNeighbourhood($ts: string)
{  
  NEIGHBOURHOOD as var(func: type(Connection)) @filter(ge(connection.ts, $ts-1hour) AND le(connection.ts, $ts+1hour)) @cascade {
    connection.duration
    ...
    connection.ts
    ~host.originated @filter(eq(host.ip, "9.66.11.14")) {
      name : host.ip
    }
  }

  getNeighbourhood(func: uid(NEIGHBOURHOOD)) {
    expand(Connection)
  }
}

Where $ts contains for example 2019-03-19T14:59:00.0Z.

What I did

query getNeighbourhood($ts: string)
{  
  NEIGHBOURHOOD as var(func: type(Connection)) @filter(ge(connection.ts, $ts) AND le(connection.ts, $ts)) @cascade {
    connection.duration
    ...
    connection.ts
    ~host.originated @filter(eq(host.ip, "9.66.11.14")) {
      name : host.ip
    }
  }

  getNeighbourhood(func: uid(NEIGHBOURHOOD)) {
    expand(Connection)
  }
}

What almost seems to work is this conversion:

time as connection.ts
interval_start: math(since(time)-3600)  # 3600 is 1 hour in seconds
interval_end: math(since(time)+3600)

But I can not figure out how to use it in @filter directive (if interval_start and interval_end were variables, they would have to be transformed to a Datetime type again).

Tha value of variable $ts is taken from a different query and it would be very convenient if the interval could be created solely in Dgraph. Although external processing of $ts variable value is possible, I believe it is not such a complex requirement on filtering capabilities and I am unable to make it work just because of my lack of experience with Dgraph.

Maybe you could add your voice to:

1 Like