Asterisk date readback issue

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

Howdy! Welcome to the forums.

What timezone is your Asterisk machine set to ?

Our Asterisk machine is set to EST timezone.

Dates, times, and zones can be relatively tricky! Keeping things in UTC as long as possible is often good practice, with only the presentation layer to the end user being utilized to show the “current” time.

Maybe sayDate is exposed in your bpmn-js library (not sure), so that you can use AGI SAY DATE instead of AGI SAY DATETIME ?

There’s not much difference between the date & time parameters, other than documentation:

SAY DATE offers:
date - Is number of seconds elapsed since 00:00:00 on January 1, 1970. Coordinated Universal Time (UTC).

SAY DATETIME offers:
time - Is number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).

However, SAY DATETIME does let you adjust for timezone:
timezone - Acceptable values can be found in /usr/share/zoneinfo Defaults to machine default.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.