Search code examples
gremlingremlin-servergremlinpython

Gremlin calculate date difference from today


Date was stored in gremlin. I want to get months between stored date and today.

Is it possible to write only using gremlin?


Solution

  • There is no way to do date calculations without using a lambda at this time:

    gremlin> import java.time.*
    ...
    gremlin> import java.time.temporal.*
    ...
    gremlin> g = TinkerGraph.open().traversal()
    ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
    gremlin> g.addV('event').property('d', new LocalDate(2020,8,1))
    ==>v[0]
    gremlin> g.V().values('d').map{ Period.between(it.get(), LocalDate.now()).getMonths() }
    ==>4
    

    If you stored your date as a long, I suppose that you could get the time difference without a lambda, but then you'd need to somehow calculate "months" from that.