Hi, I'm looking for a way to show event dates with a local time.
The use case is to ask respondents to indicate their availability for 4 dates. For example, an event would take place on August 29, 14:00 UTC. When viewed by a respondent in CET+2 timezone (or -120 offset) would be displayed as.
[]August 29 16:00 CET+2
This is what I've tried so far. Seemed to be working, but I must have changed something as it no longer does.
1 - Get the offset and store it as embedded data
var offset = new Date().getTimezoneOffset();
console.log(offset);
Qualtrics.SurveyEngine.setEmbeddedData('offset', offset);
2 - Get the timezone and store it as embedded data
const [timeZone] = new Date().toString().match(/([A-Z]+[+-][0-9]+)/);
Qualtrics.SurveyEngine.setEmbeddedData('timezone', timeZone);
3 - Use the timezone to manipulate event date and times
var answer = "${e://Field/timezone}";
const date1 = new Date('August 29, 2022 16:00:00' + answer);
const date2 = new Date('August 29, 2022 18:00:00' + answer);
const date3 = new Date('August 30, 2022 17:00:00' + answer);
const date4 = new Date('August 29, 2022 19:00:00' + answer);
console.log(date1);
console.log(date2);
console.log(date3);
console.log(date4);
4 - And store dates with local time as embedded data for display
Qualtrics.SurveyEngine.setEmbeddedData('session1', date1);
Qualtrics.SurveyEngine.setEmbeddedData('session2', date2);
Qualtrics.SurveyEngine.setEmbeddedData('session3', date3);
Qualtrics.SurveyEngine.setEmbeddedData('session4', date4);
I'm at a loss. Also tried using Luxon (i.e. Moment) js library, but ran into other issues. Does anyone have recommendations on a better approach or can point out where I'm going wrong?
How to show event dates with local time
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
