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!!
-
Did you check documentation for the AGI command? Looks like your method is missing an argument. docs.asterisk.org/Asterisk_18_Documentation/API_Documentation/…miken32– miken322024年12月30日 18:57:21 +00:00Commented Dec 30, 2024 at 18:57
1 Answer 1
https://docs.asterisk.org/Latest_API/API_Documentation/AGI_Commands/say_datetime/
As you see it has timezone. So can be two variants
- You are not sending timezone
- library you are using don't know about that param.
You can debug asterisk by doing
asterisk -r
agi set debug on
Comments
Explore related questions
See similar questions with these tags.