Fairly new to postman, but I’ve recently had a problem (which is now solved) with setting locale time for pre-requests and tests. Essentially when running the tests via collection runner the below attempted solution worked fine but, when running via newman (still on local machine) the locale times where not set in the same way. See below… forgive the code i’d regard myself as entry level test engineer…
So my questions are did i miss something obvious or is this a bug or an enhancement (the eventual solution was in fact a one liner in the shell script on server running the test to set ‘time’ as local so much of below was made redundant thankfully. A side note would be moment-timezone being made available as a lib would be ace.
// import moment library
var moment = require(‘moment’);
// create time value using js and set it to europe/london timezome
var dateNow = (new Date()).toLocaleString(‘en-GB’, { timeZone: ‘Europe/London’ });
// format into object matching FWS
var bst = dateNow.substr(0, dateNow.length - 3).replace(’,’, ‘’);
// create a date object 5 days ago
var fiveago = new Date(new Date() - (5 * 24 * 60 * 60 * 1000));
var fiveagoFormat = (fiveago.toLocaleString(‘en-GB’, { timeZone: ‘Europe/London’ }));
var nowLessFiveDays = fiveagoFormat.substr(0, fiveagoFormat.length - 3).replace(’,’, ‘’);
// create a date object 2 days ago
var twoago = new Date(new Date() - (2 * 24 * 60 * 60 * 1000));
var twoagoFormat = (twoago.toLocaleString(‘en-GB’, { timeZone: ‘Europe/London’ }));
var nowLessTwoDays = twoagoFormat.substr(0, twoagoFormat.length - 3).replace(’,’, ‘’);
// console log all the date objects for debugging assistance
console.log(“Moment timestamp…”, moment());
console.log(“dateNow…”, dateNow);
console.log(“BST time…”, bst);
console.log(“fiveago is…”, fiveago);
console.log(“fiveagoFormat is…”, fiveagoFormat);
console.log(‘variable nowLessFiveDays is…’, nowLessFiveDays);
console.log(“twoago is…”, twoago);
console.log(“twoagoFormat is…”, twoagoFormat);
console.log(‘variable nowLessTwoDays is…’, nowLessTwoDays);
log output from running inside postman…
Moment timestamp…
2020-04-08T13:32:36.106Z
dateNow…
08/04/2020, 14:32:36
BST time…
08/04/2020 14:32
fiveago is…
Fri Apr 03 2020 14:32:36 GMT+0100 (BST)
fiveagoFormat is…
03/04/2020, 14:32:36
variable nowLessFiveDays is…
03/04/2020 14:32
twoago is…
Mon Apr 06 2020 14:32:36 GMT+0100 (BST)
twoagoFormat is…
06/04/2020, 14:32:36
variable nowLessTwoDays is…
06/04/2020 14:32
POST approval time
03/04/2020 14:32
(edited)
14:40
log output when run from newman runner in cli
‘Moment timestamp…’, ‘2020-04-08T13:28:12.404Z’
│
│ ‘dateNow…’, ‘4/8/2020, 2:28:12 PM’
│ ‘BST time…’, ‘4/8/2020 2:28:12’
│ ‘fiveago is…’, ‘2020-04-03T13:28:12.403Z’
│ ‘fiveagoFormat is…’, ‘4/3/2020, 2:28:12 PM’[39
│ m
│ ‘variable nowLessFiveDays is…’, ‘4/3/2020 2:28:
│ 12’
│ ‘twoago is…’, ‘2020-04-06T13:28:12.404Z’
│ ‘twoagoFormat is…’, ‘4/6/2020, 2:28:12 PM’
│ ‘variable nowLessTwoDays is…’, ‘4/6/2020 2:28:1
│ 2’
│ ‘POST approval time’, ‘4/3/2020 2:28:12’