Epoch time with 18 digits

Hi @mark.sadegursky!

I tried my best but looks like we need process.hrtime() in order to make it work.
However, process module is not available as discussed here :frowning_face:

If this module was available, it would be possible to utilise one of external libraries such as this one to make it work by leveraging eval() function, e.g.

In pre-request:

pm.sendRequest('https://peterolson.github.io/BigInteger.js/BigInteger.min.js', (err, res) => {
    if (err) {
        console.log(err)
    } else {
        pm.environment.set('bigInt', res.text())
    }
})

In test script:

eval(pm.environment.get('bigInt'))
//const loadNs = process.hrtime();
const loadMs = new Date().getTime();
const diffNs = [ 8, 886896255 ] // should really be process.hrtime(loadNs)
const value = bigInt(loadMs).times(1e6).add(bigInt(diffNs[0]).times(1e9).plus(diffNs[1])).toString();
console.log(value)

I hope you find this helpful a bit :slightly_smiling_face:

1 Like