[Asterisk-code-review] main/say.c: Support future dates with Q and q format params (asterisk[18.2])

Shloime Rosenblum asteriskteam at digium.com
Sun Sep 19 15:12:29 CDT 2021


Shloime Rosenblum has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16492 )


Change subject: main/say.c: Support future dates with Q and q format params
......................................................................

main/say.c: Support future dates with Q and q format params

The current versions do not support future dates in all say application when using the 'Q' or 'q' format parameter and says "today" for everything that is greater than today

ASTERISK-29637

Change-Id: I1fb1cef0ce3c18d87b1fc94ea309d13bc344af02
---
M main/say.c
1 file changed, 83 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/92/16492/1

diff --git a/main/say.c b/main/say.c
index fcab7fd..478f93c 100644
--- a/main/say.c
+++ b/main/say.c
@@ -4199,22 +4199,57 @@
 					/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
 					/* In any case, it saves not having to do ast_mktime() */
 					beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
-					if (beg_today < t) {
+					if (beg_today + 15768000 < t) {
+						/* More than 6 months from now - "April nineteenth two thousand three" */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
+					} 
+					else if (beg_today + 2628000 < t)
+					{
+						/* Less than 6 months from now - "August seventh" */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
+					}
+					else if (beg_today + 86400 * 6 < t)
+					{
+						/* Less than a month from now - "Sunday, October third" */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
+					}
+					else if (beg_today + 172800 < t)
+					{
+						/* Within the next week */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
+					}
+					else if (beg_today + 86400 < t)
+					{
+						/* Tomorrow */
+						res = wait_file(chan, ints, "digits/tomorrow", lang);
+					}
+					else if (beg_today < t)
+					{
 						/* Today */
 						res = wait_file(chan, ints, "digits/today", lang);
-					} else if (beg_today - 86400 < t) {
+					}
+					else if (beg_today - 86400 < t)
+					{
 						/* Yesterday */
 						res = wait_file(chan, ints, "digits/yesterday", lang);
-					} else if (beg_today - 86400 * 6 < t) {
+					}
+					else if (beg_today - 86400 * 6 < t)
+					{
 						/* Within the last week */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
-					} else if (beg_today - 2628000 < t) {
+					}
+					else if (beg_today - 2628000 < t)
+					{
 						/* Less than a month ago - "Sunday, October third" */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
-					} else if (beg_today - 15768000 < t) {
+					}
+					else if (beg_today - 15768000 < t)
+					{
 						/* Less than 6 months ago - "August seventh" */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
-					} else {
+					}
+					else
+					{
 						/* More than 6 months ago - "April nineteenth two thousand three" */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
 					}
@@ -4235,21 +4270,57 @@
 					/* This might be slightly off, if we transcend a leap second, but never more off than 1 second */
 					/* In any case, it saves not having to do ast_mktime() */
 					beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
-					if (beg_today < t) {
+					if (beg_today + 15768000 < t) {
+						/* More than 6 months from now - "April nineteenth two thousand three" */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
+					} 
+					else if (beg_today + 2628000 < t)
+					{
+						/* Less than 6 months from now - "August seventh" */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
+					}
+					else if (beg_today + 86400 * 6 < t)
+					{
+						/* Less than a month from now - "Sunday, October third" */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
+					}
+					else if (beg_today + 172800 < t)
+					{
+						/* Within the next week */
+						res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
+					}
+					else if (beg_today + 86400 < t)
+					{
+						/* Tomorrow */
+						res = wait_file(chan, ints, "digits/tomorrow", lang);
+					}
+					else if (beg_today < t)
+					{
 						/* Today */
-					} else if ((beg_today - 86400) < t) {
+						res = wait_file(chan, ints, "digits/today", lang);
+					}
+					else if (beg_today - 86400 < t)
+					{
 						/* Yesterday */
 						res = wait_file(chan, ints, "digits/yesterday", lang);
-					} else if (beg_today - 86400 * 6 < t) {
+					}
+					else if (beg_today - 86400 * 6 < t)
+					{
 						/* Within the last week */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "A", tzone);
-					} else if (beg_today - 2628000 < t) {
+					}
+					else if (beg_today - 2628000 < t)
+					{
 						/* Less than a month ago - "Sunday, October third" */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "ABd", tzone);
-					} else if (beg_today - 15768000 < t) {
+					}
+					else if (beg_today - 15768000 < t)
+					{
 						/* Less than 6 months ago - "August seventh" */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "Bd", tzone);
-					} else {
+					}
+					else
+					{
 						/* More than 6 months ago - "April nineteenth two thousand three" */
 						res = ast_say_date_with_format_en(chan, t, ints, lang, "BdY", tzone);
 					}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16492
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18.2
Gerrit-Change-Id: I1fb1cef0ce3c18d87b1fc94ea309d13bc344af02
Gerrit-Change-Number: 16492
Gerrit-PatchSet: 1
Gerrit-Owner: Shloime Rosenblum <shloimerosenblum at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210919/0fd79435/attachment-0001.html>


More information about the asterisk-code-review mailing list