0

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!!

asked Dec 3, 2024 at 10:47
1

1 Answer 1

0

https://docs.asterisk.org/Latest_API/API_Documentation/AGI_Commands/say_datetime/

As you see it has timezone. So can be two variants

  1. You are not sending timezone
  2. library you are using don't know about that param.

You can debug asterisk by doing

asterisk -r
agi set debug on
answered Jan 15, 2025 at 15:15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.