Support Questions

Find answers, ask questions, and share your expertise

How to decrease Epoch time length and perform substract operation for find one minute ago time.

Explorer

Hi Everyone, 

 

I have a use case, where i need to generate timestamp in Epoch UTC format till seconds 1662371646, and perform Substract operation for generate one minute ago time in same format. 

below is my Jolt Spec :

 

[

  {
    "operation": "default",
    "spec": {
      "currenttime": "${now():toNumber()}"
      
    }
  },
    {
    "operation": "modify-overwrite-beta",
    "spec": {
      "timeOneMinu": "=Subtract(@(1,currenttime),60)"
    }
  }
]

 

Output : 

 

{
	"currenttime": "1662372281",
	"timeOneMinu": "1662372221"
}

 

Please suggest, How we can do this. 

4 REPLIES 4

Master Collaborator

@samrathal ,

 

Doesn't your JOLT spec solve your own problem?

 

Cheers,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

Explorer

@araujo 
No, I'm getting the same current time in "timeOneMinu", Subtraction is not performing. 

Master Collaborator

@samrathal ,

 

What about this:

[
  {
    "operation": "default",
    "spec": {
      "currenttime": "${now():toNumber()}",
      "timeOneMinu": "${now():toNumber():minus(60)}"
    }
  }
]
--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

Master Collaborator

@samrathal ,

 

Is seems that "subtract" only works for integers and your value is a long. The longSubtract function only works if longs are passed as parameters and I don't know if there's a way to specify a long literal in Jolt (I tried 60L but that doesn't work).

 

The following does a little bit more work but also achieves what you want:

 

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "currenttime": "=toLong(${now():toNumber()})",
      "minute": "=toLong(60)"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "timeOneMinu": "=longSubtract(@(1,currenttime), @(1,minute))"
    }
  },
  {
    "operation": "remove",
    "spec": {
      "minute": ""
    }
  }
]

 

 

Output:

{
	"currenttime": 1662417935173,
	"timeOneMinu": 1662417935113
}

Cheers,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.