bruno icon indicating copy to clipboard operation
bruno copied to clipboard

isoTimestamp returns some random timestamp

Open rayrapetyan opened this issue 8 months ago • 6 comments

I have checked the following:

  • [x] I have searched existing issues and found nothing related to my issue.

This bug is:

  • [ ] making Bruno unusable for me
  • [x] slowing me down but I'm able to continue working
  • [x] annoying
  • [ ] this feature was working in a previous version but is broken in the current release.

Bruno version

2.2.0

Operating System

Linux, Ubuntu 24

Describe the bug

Simply put {{$isoTimestamp}} as one of the request body parameters.

Expected: should be converted into current timestamp Actual: some random timestamp from past or the future

.bru file to reproduce the bug

No response

Screenshots/Live demo link

Image

rayrapetyan avatar May 09 '25 01:05 rayrapetyan

Can confirm the same behaviour. Maybe the documentation is wrong and a random timestamp is meant?

fantpmas avatar May 09 '25 06:05 fantpmas

I don't think it's a documentation bug, postman uses the same variable: https://learning.postman.com/docs/tests-and-scripts/write-scripts/variables-list/. Also, there are 3 other variables ({{$randomDate*}}) for random timestamps.

rayrapetyan avatar May 09 '25 14:05 rayrapetyan

Same problem with normal timestamp. It also give back time in the future :-)

I need the unix time stamp for authorization against one of our api servers.

Image

sww-jm avatar May 13 '25 06:05 sww-jm

Currently we are using random time to generate this

 timestamp: () => faker.date.anytime().getTime().toString(),
  isoTimestamp: () => faker.date.anytime().toISOString(),

see https://github.com/usebruno/bruno/blob/main/packages/bruno-common/src/utils/faker-functions.ts will get this updated

anusree-bruno avatar May 13 '25 12:05 anusree-bruno

@sww-jm I use this little Pre Request script:

function getCurrentTimestamp() {
  return new Date().getTime();
}

bru.setVar("currentTimestamp", getCurrentTimestamp());

You then can use {{currentTimestamp}} in your requests.

If you add the following lines to the Pre Request script you can see the difference to {{$timestamp}} in the Developer Tools console:

bru.setVar("myTimestamp", "{{$timestamp}}");

console.log(bru.getVar("currentTimestamp"))
console.log(bru.getVar("myTimestamp")) 

swobi71 avatar May 14 '25 18:05 swobi71

ah, very nice! (and dividing by 1000 to get the timestamp in seconds totally makes sense)

maybe you could add a new variable "timestamp_ms" which contains the timestamp in milliseconds? (this could be useful if consecutive requests in a fast succession need a unique timestamp)

swobi71 avatar May 15 '25 15:05 swobi71

Hi @swobi71

I will check with the team and add timestamp by millisecond in a different PR.

anusree-bruno avatar May 31 '25 14:05 anusree-bruno

Created a separate issue to track this https://github.com/usebruno/bruno/issues/4631#issuecomment-2884226488

anusree-bruno avatar Jul 19 '25 11:07 anusree-bruno