Problem Statement:
Given DAY, i.e. (time zone: Pacific) 2017-11-17, need a converter to produce UTC time period for telemetry reading, i.e. start=2017-11-17T08:00:00.000000Z&end=2017-11-18T07:59:59.999999Z.
Is there such a formula or method to do this?
Thanks in advance for your help!
Tien.
akshaybist
(Akshay Bist)
November 21, 2017, 2:38am
2
You can require moment , which is available in the Postman Sandbox for this.
This pre-request script should work
const moment = require('moment');
const today = moment();
pm.globals.set('startDayUTC', today.startOf('day').toISOString());
pm.globals.set('endDayUTC', today.endOf('day').toISOString());
This will pick the local timezone of the computer running the collection. If you want to force to PST, then initialize today
like so
const today = moment().zone(420); // PST offset from UTC in minutes
// Or for UTC
const today = moment.utc();
More on setting timezone offset in moment here
4 Likes
Thank you for your help, Akshay. I will check this out!! And update the post accordingly.
Thanks,
Tien
works awesome as I finally got around to making use of this !!
Chris
(Chris)
March 8, 2018, 12:37am
6
@akshaybist , the real MVP.