Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Contributor

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

avatar
Super Guru

@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.

avatar
Contributor

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

avatar
Super Guru

@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.

avatar
Super Guru

@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.