isoTimestamp returns some random timestamp
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
Can confirm the same behaviour. Maybe the documentation is wrong and a random timestamp is meant?
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.
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.
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
@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"))
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)
Hi @swobi71
I will check with the team and add timestamp by millisecond in a different PR.
Created a separate issue to track this https://github.com/usebruno/bruno/issues/4631#issuecomment-2884226488