We are using asterisk say data service for readback of date. We have integrated asterisk with bpmn-js, and use context to execute commands for say date in case of readback.
Following is the code which is used to readback datetime:
function sayDateTime(context, value, format, escapeDigits = "*") {
return context.sayDateTime(value, escapeDigits, format);
}
where:
- value is the seconds elapsed after epoch time (UTC).
- format is the format of readback (day, month, year).
And we are using following method to get milliseconds to pass to the function:
Here the formatted date is of following format: “YYYY-MM-DD” (example: 2024-03-11)
const [year, month, day] = formattedDate.split('-').map(Number);
const date = new Date(formattedDate);
let dateFormat = "";
if (dateReadbackPattern.includes("MM")) {
dateFormat += "B"; // Month
}
if (dateReadbackPattern.includes("DD")) {
dateFormat += "d"; // Day
}
if (dateReadbackPattern.includes("YYYY") || dateReadbackPattern.includes("YY")) {
dateFormat += "Y"; // Year
}
// Adjust for the timezone offset (to get the correct timestamp)
const adjustedDate = new Date(date.getTime() - (date.getTimezoneOffset() * 60 * 1000));
console.log(date.getTimezoneOffset());
// Get the timestamp in milliseconds (which is in the local time zone)
const localTimeInMillis = adjustedDate.getTime();
// Convert it to seconds (if you need it in seconds for sayDateTime)
const localTimeInSeconds = Math.floor(localTimeInMillis / 1000);
return AgiService.sayDateTime(agiContext, localTimeInSeconds, dateFormat, escapeDigits);
But the readback is happening one day earlier than the actual date. So, do we need to pass timezone as extra parameter, if yes, then how does asterisk uses that timezone for readback?
Can someone please explain how does asterisk evaluates time by considering the timezone which we provide (does it subtract or adds)?
Example: If we send milliseconds according to UTC as a parameter, then does asterisk apply extra addition or subtraction according to timezone?
Any help would be greatly appreciated!!