add Polish language support to Voicemail, with some minor modifications that
authorRussell Bryant <russell@russellbryant.com>
Sat, 6 May 2006 02:05:18 +0000 (02:05 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 6 May 2006 02:05:18 +0000 (02:05 +0000)
include formatting fixes, making it so variables aren't declared in the
middle of a block, and various other little code cleanups
(issue #6970, supczinskib)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@25159 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c
say.c

index fccc9e0..bfa3ba1 100644 (file)
@@ -37,6 +37,8 @@
  * 07-11-2005 : An issue with voicemail synchronization has been fixed by GDS Partners (www.gdspartners.com)
  *                              Stojan Sljivic <stojan.sljivic@gdspartners.com>
  *
+ * 12-04-2006 : Support for Polish added by DIR (www.dir.pl)
+ *                              Bartosz Supczinski <Bartosz.Supczinski@dir.pl>
  */
 
 #include <stdlib.h>
@@ -161,6 +163,7 @@ static int load_config(void);
        \arg \b fr - French
        \arg \b it = Italian
        \arg \b nl - Dutch
+       \arg \b pt - Polish
        \arg \b pt - Portuguese
        \arg \b gr - Greek
        \arg \b no - Norwegian
@@ -180,6 +183,16 @@ NB these are plural:
 \arg \b vm-INBOX       nieuwe (nl)
 \arg \b vm-Old         oude (nl)
 
+Polish uses:
+\arg \b vm-new-a       'new', feminine singular accusative
+\arg \b vm-new-e       'new', feminine plural accusative
+\arg \b vm-new-ych     'new', feminine plural genitive
+\arg \b vm-old-a       'old', feminine singular accusative
+\arg \b vm-old-e       'old', feminine plural accusative
+\arg \b vm-old-ych     'old', feminine plural genitive
+\arg \b digits/1-a     'one', not always same as 'digits/1'
+\arg \b digits/2-ie    'two', not always same as 'digits/2'
+
 Swedish uses:
 \arg \b vm-nytt                singular of 'new'
 \arg \b vm-nya         plural of 'new'
@@ -3688,10 +3701,12 @@ static int play_message_datetime(struct ast_channel *chan, struct ast_vm_user *v
 #endif
        if (the_zone)
                res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, the_zone->msg_format, the_zone->timezone);
-       else if(!strcasecmp(chan->language,"se"))       /* SWEDISH syntax */
-               res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' dB 'digits/at' k 'and' M", NULL);
-       else if(!strcasecmp(chan->language,"no"))       /* NORWEGIAN syntax */
-               res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q 'digits/at' HM", NULL);
+       else if(!strcasecmp(chan->language,"pl"))       /* POLISH syntax */
+               res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q HM", NULL);
+       else if(!strcasecmp(chan->language,"se"))       /* SWEDISH syntax */
+               res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' dB 'digits/at' k 'and' M", NULL);
+       else if(!strcasecmp(chan->language,"no"))       /* NORWEGIAN syntax */
+               res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q 'digits/at' HM", NULL);
        else if(!strcasecmp(chan->language,"de"))       /* GERMAN syntax */
                res = ast_say_date_with_format(chan, t, AST_DIGIT_ANY, chan->language, "'vm-received' Q 'digits/at' HM", NULL);
        else if (!strcasecmp(chan->language,"nl"))      /* DUTCH syntax */
@@ -3788,9 +3803,37 @@ static int play_message_duration(struct ast_channel *chan, struct vm_state *vms,
 
        ast_log(LOG_DEBUG, "VM-Duration: duration is: %d seconds converted to: %d minutes\n", durations, durationm);
 
-       if((!res)&&(durationm>=minduration)) {
-               res = ast_say_number(chan, durationm, AST_DIGIT_ANY, chan->language, (char *) NULL);
-               res = wait_file2(chan, vms, "vm-minutes");
+       if ((!res) && (durationm >= minduration)) {
+               res = wait_file2(chan, vms, "vm-duration");
+
+               /* POLISH syntax */
+               if (!strcasecmp(chan->language, "pl")) {
+                       div_t num = div(durationm, 10);
+
+                       if (durationm == 1) {
+                               res = ast_play_and_wait(chan, "digits/1z");
+                               res = res ? res : ast_play_and_wait(chan, "vm-minute-ta");
+                       } else if (num.rem > 1 && num.rem < 5 && num.quot != 1) {
+                               if (num.rem == 2) {
+                                       if (!num.quot) {
+                                               res = ast_play_and_wait(chan, "digits/2-ie");
+                                       } else {
+                                               res = say_and_wait(chan, durationm - 2 , chan->language);
+                                               res = res ? res : ast_play_and_wait(chan, "digits/2-ie");
+                                       }
+                               } else {
+                                       res = say_and_wait(chan, durationm, chan->language);
+                               }
+                               res = res ? res : ast_play_and_wait(chan, "vm-minute-ty");
+                       } else {
+                               res = say_and_wait(chan, durationm, chan->language);
+                               res = res ? res : ast_play_and_wait(chan, "vm-minute-t");
+                       }
+               /* DEFAULT syntax */
+               } else {
+                       res = ast_say_number(chan, durationm, AST_DIGIT_ANY, chan->language, NULL);
+                       res = wait_file2(chan, vms, "vm-minutes");
+               }
        }
        return res;
 }
@@ -3810,21 +3853,45 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
        else if (vms->curmsg == vms->lastmsg)
                res = wait_file2(chan, vms, "vm-last");         /* "last" */
        if (!res) {
-               if (!strcasecmp(chan->language, "se")) {             /* SWEDISH syntax */
-                       res = wait_file2(chan, vms, "vm-meddelandet");  /* "message" */
-               }
-               else {
-                       res = wait_file2(chan, vms, "vm-message");      /* "message" */
-               }
-               if (vms->curmsg && (vms->curmsg != vms->lastmsg)) {
+               /* POLISH syntax */
+               if (!strcasecmp(chan->language, "pl")) { 
+                       if (vms->curmsg && (vms->curmsg != vms->lastmsg)) {
+                               int ten, one;
+                               char nextmsg[256];
+                               ten = (vms->curmsg + 1) / 10;
+                               one = (vms->curmsg + 1) % 10;
+                               
+                               if (vms->curmsg < 20) {
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/n-%d", vms->curmsg + 1);
+                                       res = wait_file2(chan, vms, nextmsg);
+                               } else {
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/n-%d", ten * 10);
+                                       res = wait_file2(chan, vms, nextmsg);
+                                       if (one > 0) {
+                                               if (!res) {
+                                                       snprintf(nextmsg, sizeof(nextmsg), "digits/n-%d", one);
+                                                       res = wait_file2(chan, vms, nextmsg);
+                                               }
+                                       }
+                               }
+                       }
                        if (!res)
-                               res = ast_say_number(chan, vms->curmsg + 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
+                               res = wait_file2(chan, vms, "vm-message");
+               } else {
+                       if (!strcasecmp(chan->language, "se")) /* SWEDISH syntax */
+                               res = wait_file2(chan, vms, "vm-meddelandet");  /* "message" */
+                       else /* DEFAULT syntax */
+                               res = wait_file2(chan, vms, "vm-message");
+                       if (vms->curmsg && (vms->curmsg != vms->lastmsg)) {
+                               if (!res)
+                                       res = ast_say_number(chan, vms->curmsg + 1, AST_DIGIT_ANY, chan->language, NULL);
+                       }
                }
        }
 
        /* Retrieve info from VM attribute file */
        make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
-       snprintf(filename,sizeof(filename), "%s.txt", vms->fn2);
+       snprintf(filename, sizeof(filename), "%s.txt", vms->fn2);
        RETRIEVE(vms->curdir, vms->curmsg);
        msg_cfg = ast_config_load(filename);
        if (!msg_cfg) {
@@ -3980,14 +4047,26 @@ static int vm_play_folder_name_gr(struct ast_channel *chan, char *mbox)
 
        if (!strcasecmp(mbox, "vm-INBOX") || !strcasecmp(mbox, "vm-Old")){
                cmd = ast_play_and_wait(chan, buf); /* "NEA / PALIA" */
-               if (cmd)
-               return cmd;
-               return ast_play_and_wait(chan, "vm-messages"); /* "messages" -> "MYNHMATA" */
+               return cmd ? cmd : ast_play_and_wait(chan, "vm-messages"); /* "messages" -> "MYNHMATA" */
        } else {
                cmd = ast_play_and_wait(chan, "vm-messages"); /* "messages" -> "MYNHMATA" */
-               if (cmd)
-                       return cmd;
-               return ast_play_and_wait(chan, mbox); /* friends/family/work... -> "FILWN"/"OIKOGENIAS"/"DOULEIAS"*/
+               return cmd ? cmd : ast_play_and_wait(chan, mbox); /* friends/family/work... -> "FILWN"/"OIKOGENIAS"/"DOULEIAS"*/
+       }
+}
+
+static int vm_play_folder_name_pl(struct ast_channel *chan, char *mbox)
+{
+       int cmd;
+
+       if (!strcasecmp(mbox, "vm-INBOX") || !strcasecmp(mbox, "vm-Old")) {
+               if (!strcasecmp(mbox, "vm-INBOX"))
+                       cmd = ast_play_and_wait(chan, "vm-new-e");
+               else
+                       cmd = ast_play_and_wait(chan, "vm-old-e");
+               return cmd ? cmd : ast_play_and_wait(chan, "vm-messages");
+       } else {
+               cmd = ast_play_and_wait(chan, "vm-messages");
+               return cmd ? cmd : ast_play_and_wait(chan, mbox);
        }
 }
 
@@ -3997,16 +4076,14 @@ static int vm_play_folder_name(struct ast_channel *chan, char *mbox)
 
        if (!strcasecmp(chan->language, "it") || !strcasecmp(chan->language, "es") || !strcasecmp(chan->language, "fr") || !strcasecmp(chan->language, "pt")) { /* Italian, Spanish, French or Portuguese syntax */
                cmd = ast_play_and_wait(chan, "vm-messages"); /* "messages */
-               if (cmd)
-                       return cmd;
-               return ast_play_and_wait(chan, mbox);
+               return cmd ? cmd : ast_play_and_wait(chan, mbox);
        } else if (!strcasecmp(chan->language, "gr")){
                return vm_play_folder_name_gr(chan, mbox);
+       } else if (!strcasecmp(chan->language, "pl")){
+               return vm_play_folder_name_pl(chan, mbox);
        } else {  /* Default English */
                cmd = ast_play_and_wait(chan, mbox);
-               if (cmd)
-                       return cmd;
-               return ast_play_and_wait(chan, "vm-messages"); /* "messages */
+               return cmd ? cmd : ast_play_and_wait(chan, "vm-messages"); /* "messages */
        }
 }
 
@@ -4138,6 +4215,77 @@ static int vm_intro_it(struct ast_channel *chan, struct vm_state *vms)
        return res ? -1 : 0;
 }
 
+/* POLISH syntax */
+static int vm_intro_pl(struct ast_channel *chan, struct vm_state *vms)
+{
+       /* Introduce messages they have */
+       int res;
+       div_t num;
+
+       if (!vms->oldmessages && !vms->newmessages) {
+               res = ast_play_and_wait(chan, "vm-no");
+               res = res ? res : ast_play_and_wait(chan, "vm-messages");
+               return res;
+       } else {
+               res = ast_play_and_wait(chan, "vm-youhave");
+       }
+
+       if (vms->newmessages) {
+               num = div(vms->newmessages, 10);
+               if (vms->newmessages == 1) {
+                       res = ast_play_and_wait(chan, "digits/1-a");
+                       res = res ? res : ast_play_and_wait(chan, "vm-new-a");
+                       res = res ? res : ast_play_and_wait(chan, "vm-message");
+               } else if (num.rem > 1 && num.rem < 5 && num.quot != 1) {
+                       if (num.rem == 2) {
+                               if (!num.quot) {
+                                       res = ast_play_and_wait(chan, "digits/2-ie");
+                               } else {
+                                       res = say_and_wait(chan, vms->newmessages - 2 , chan->language);
+                                       res = res ? res : ast_play_and_wait(chan, "digits/2-ie");
+                               }
+                       } else {
+                               res = say_and_wait(chan, vms->newmessages, chan->language);
+                       }
+                       res = res ? res : ast_play_and_wait(chan, "vm-new-e");
+                       res = res ? res : ast_play_and_wait(chan, "vm-messages");
+               } else {
+                       res = say_and_wait(chan, vms->newmessages, chan->language);
+                       res = res ? res : ast_play_and_wait(chan, "vm-new-ych");
+                       res = res ? res : ast_play_and_wait(chan, "vm-messages");
+               }
+               if (!res && vms->oldmessages)
+                       res = ast_play_and_wait(chan, "vm-and");
+       }
+       if (!res && vms->oldmessages) {
+               num = div(vms->oldmessages, 10);
+               if (vms->oldmessages == 1) {
+                       res = ast_play_and_wait(chan, "digits/1-a");
+                       res = res ? res : ast_play_and_wait(chan, "vm-old-a");
+                       res = res ? res : ast_play_and_wait(chan, "vm-message");
+               } else if (num.rem > 1 && num.rem < 5 && num.quot != 1) {
+                       if (num.rem == 2) {
+                               if (!num.quot) {
+                                       res = ast_play_and_wait(chan, "digits/2-ie");
+                               } else {
+                                       res = say_and_wait(chan, vms->oldmessages - 2 , chan->language);
+                                       res = res ? res : ast_play_and_wait(chan, "digits/2-ie");
+                               }
+                       } else {
+                               res = say_and_wait(chan, vms->oldmessages, chan->language);
+                       }
+                       res = res ? res : ast_play_and_wait(chan, "vm-old-e");
+                       res = res ? res : ast_play_and_wait(chan, "vm-messages");
+               } else {
+                       res = say_and_wait(chan, vms->oldmessages, chan->language);
+                       res = res ? res : ast_play_and_wait(chan, "vm-old-ych");
+                       res = res ? res : ast_play_and_wait(chan, "vm-messages");
+               }
+       }
+
+       return res;
+}
+
 /* SWEDISH syntax */
 static int vm_intro_se(struct ast_channel *chan, struct vm_state *vms)
 {
@@ -4647,6 +4795,8 @@ static int vm_intro(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm
                return vm_intro_cz(chan, vms);
        } else if (!strcasecmp(chan->language, "gr")) { /* GREEK syntax */
                return vm_intro_gr(chan, vms);
+       } else if (!strcasecmp(chan->language, "pl")) { /* POLISH syntax */
+               return vm_intro_pl(chan, vms);
        } else if (!strcasecmp(chan->language, "se")) { /* SWEDISH syntax */
                return vm_intro_se(chan, vms);
        } else if (!strcasecmp(chan->language, "no")) { /* NORWEGIAN syntax */
diff --git a/say.c b/say.c
index d50bb11..b8f0e11 100644 (file)
--- a/say.c
+++ b/say.c
@@ -350,6 +350,7 @@ static int ast_say_date_with_format_he(struct ast_channel *chan, time_t time, co
 static int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
 static int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
 static int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
+static int ast_say_date_with_format_pl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
 static int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
 static int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
 static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone);
@@ -1666,6 +1667,7 @@ static void powiedz(struct ast_channel *chan, const char *language, int audiofd,
        }
        if (i == 0) {
                pl_odtworz_plik(chan, language, audiofd, ctrlfd, ints, odm->cyfry[0]);
+               return;
        }
 
        m1000E6 = i % 1000000000;
@@ -1755,7 +1757,7 @@ Sounds needed:
 19             dziewietnascie
 19m            dziewietnastu
 1z             jedna
-2              dwie
+2              dwa
 20             dwadziescia
 200            dwiescie
 200m           dwustu
@@ -1847,7 +1849,7 @@ and combinations of eg.: 20_1, 30m_3m, etc...
        if (odmiana_nieosobowa == NULL) {
                odmiana_nieosobowa = (odmiana *) malloc(sizeof(odmiana));
 
-               odmiana_nieosobowa->separator_dziesiatek = "_";
+               odmiana_nieosobowa->separator_dziesiatek = " ";
 
                memcpy(odmiana_nieosobowa->cyfry, nijaki_cyfry, sizeof(odmiana_nieosobowa->cyfry));
                memcpy(odmiana_nieosobowa->cyfry2, nijaki_cyfry2, sizeof(odmiana_nieosobowa->cyfry));
@@ -2926,6 +2928,8 @@ static int say_date_with_format(struct ast_channel *chan, time_t time, const cha
                return(ast_say_date_with_format_it(chan, time, ints, lang, format, timezone));
        } else if (!strcasecmp(lang, "nl") ) {  /* Dutch syntax */
                return(ast_say_date_with_format_nl(chan, time, ints, lang, format, timezone));
+       } else if (!strcasecmp(lang, "pl") ) {  /* Polish syntax */
+               return(ast_say_date_with_format_pl(chan, time, ints, lang, format, timezone));
        } else if (!strcasecmp(lang, "pt") ) {  /* Portuguese syntax */
                return(ast_say_date_with_format_pt(chan, time, ints, lang, format, timezone));
        } else if (!strcasecmp(lang, "tw") || !strcasecmp(lang, "zh") ) {       /* Taiwanese / Chinese syntax */
@@ -4651,6 +4655,220 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const cha
        return res;
 }
 
+/* Polish syntax */
+int ast_say_date_with_format_pl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
+{
+       struct tm tm;
+       int res=0, offset, sndoffset;
+       char sndfile[256], nextmsg[256];
+
+       ast_localtime(&time,&tm,timezone);
+
+       for (offset = 0 ; format[offset] != '\0' ; offset++) {
+               int remainder;
+               ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+               switch (format[offset]) {
+                       /* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
+                       case '\'':
+                               /* Literal name of a sound file */
+                               sndoffset = 0;
+                               for (sndoffset = 0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
+                                       sndfile[sndoffset] = format[offset];
+                               sndfile[sndoffset] = '\0';
+                               res = wait_file(chan, ints, sndfile, lang);
+                               break;
+                       case 'A':
+                       case 'a':
+                               /* Sunday - Saturday */
+                               snprintf(nextmsg, sizeof(nextmsg), "digits/day-%d", tm.tm_wday);
+                               res = wait_file(chan, ints, nextmsg, lang);
+                               break;
+                       case 'B':
+                       case 'b':
+                       case 'h':
+                               /* January - December */
+                               snprintf(nextmsg, sizeof(nextmsg), "digits/mon-%d", tm.tm_mon);
+                               res = wait_file(chan, ints, nextmsg, lang);
+                               break;
+                       case 'm':
+                               /* Month enumerated */
+                               res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, NULL);
+                               break;
+                       case 'd':
+                       case 'e':
+                               /* First - Thirtyfirst */
+                               remainder = tm.tm_mday;
+                               if (tm.tm_mday > 20) {
+                                       res = wait_file(chan, ints, "digits/h-20", lang);
+                                       remainder -= 20;
+                               }
+                               if (!res) {
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/h-%d", remainder);
+                                       res = wait_file(chan, ints, nextmsg, lang);
+                               }
+                               break;
+                       case 'Y':
+                               /* Year */
+                               if (tm.tm_year > 100) {
+                                       res = wait_file(chan, ints, "digits/2", lang);
+                                       if (!res)
+                                               res = wait_file(chan, ints, "digits/1000.2",lang);
+                                       if (tm.tm_year > 100) {
+                                               if (!res)
+                                                       res = ast_say_enumeration(chan, tm.tm_year - 100, ints, lang, NULL);
+                                       }
+                               } else if (tm.tm_year == 100) {
+                                       res = wait_file(chan, ints, "digits/h-2000", lang);
+                               } else {
+                                       if (tm.tm_year < 1) {
+                                               /* I'm not going to handle 1900 and prior */
+                                               /* We'll just be silent on the year, instead of bombing out. */
+                                               break;
+                                       } else {
+                                               res = wait_file(chan, ints, "digits/1000", lang);
+                                               if (!res) {
+                                                       wait_file(chan, ints, "digits/900", lang);
+                                                       res = ast_say_enumeration(chan, tm.tm_year, ints, lang, NULL);
+                                               }
+                                       }
+                               }
+                               if (!res)
+                                       wait_file(chan, ints, "digits/year", lang);
+                               break;
+                       case 'I':
+                       case 'l':
+                               /* 12-Hour */
+                               if (tm.tm_hour == 0)
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/t-12");
+                               else if (tm.tm_hour > 12)
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour - 12);
+                               else 
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour);
+
+                               res = wait_file(chan, ints, nextmsg, lang);
+                               break;
+                       case 'H':
+                       case 'k':
+                               /* 24-Hour */
+                               if (tm.tm_hour != 0) {
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/t-%d", tm.tm_hour);
+                                       res = wait_file(chan, ints, nextmsg, lang);
+                               } else 
+                                       res = wait_file(chan, ints, "digits/t-24", lang);
+                               break;
+                       case 'M':
+                       case 'N':
+                               /* Minute */
+                               if (tm.tm_min == 0) {
+                                       if (format[offset] == 'M') {
+                                               res = wait_file(chan, ints, "digits/oclock", lang);
+                                       } else {
+                                               res = wait_file(chan, ints, "digits/100", lang);
+                                       }
+                               } else
+                                       res = ast_say_number(chan, tm.tm_min, ints, lang, "f"); 
+                               break;
+                       case 'P':
+                       case 'p':
+                               /* AM/PM */
+                               if (tm.tm_hour > 11)
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/p-m");
+                               else
+                                       snprintf(nextmsg, sizeof(nextmsg), "digits/a-m");
+                               res = wait_file(chan, ints, nextmsg, lang);
+                               break;
+                       case 'Q':
+                               /* Shorthand for "Today", "Yesterday", or AdBY */
+                               {
+                                       struct timeval now;
+                                       struct tm tmnow;
+                                       time_t beg_today;
+
+                                       gettimeofday(&now, NULL);
+                                       ast_localtime(&now.tv_sec,&tmnow, timezone);
+                                       /* 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 < time) {
+                                               /* Today */
+                                               res = wait_file(chan, ints, "digits/today", lang);
+                                       } else if (beg_today - 86400 < time) {
+                                               /* Yesterday */
+                                               res = wait_file(chan, ints, "digits/yesterday", lang);
+                                       } else {
+                                               res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
+                                       }
+                               }
+                               break;
+                       case 'q':
+                               /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
+                               {
+                                       struct timeval now;
+                                       struct tm tmnow;
+                                       time_t beg_today;
+
+                                       gettimeofday(&now, NULL);
+                                       ast_localtime(&now.tv_sec, &tmnow, timezone);
+                                       /* 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 < time) {
+                                               /* Today */
+                                       } else if ((beg_today - 86400) < time) {
+                                               /* Yesterday */
+                                               res = wait_file(chan, ints, "digits/yesterday", lang);
+                                       } else if (beg_today - 86400 * 6 < time) {
+                                               /* Within the last week */
+                                               res = ast_say_date_with_format(chan, time, ints, lang, "A", timezone);
+                                       } else {
+                                               res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
+                                       }
+                               }
+                               break;
+                       case 'R':
+                               res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
+                               break;
+                       case 'S':
+                               /* Seconds */
+                               res = wait_file(chan, ints, "digits/and", lang);
+                               if (!res) {
+                                       if (tm.tm_sec == 1) {
+                                               res = wait_file(chan, ints, "digits/1z", lang);
+                                               if (!res)
+                                                       res = wait_file(chan, ints, "digits/second-a", lang);
+                                       } else {
+                                               res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
+                                               if (!res) {
+                                                       int ten, one;
+                                                       ten = tm.tm_sec / 10;
+                                                       one = tm.tm_sec % 10;
+                                                       
+                                                       if (one > 1 && one < 5 && ten != 1)
+                                                               res = wait_file(chan,ints, "digits/seconds",lang);
+                                                       else
+                                                               res = wait_file(chan,ints, "digits/second",lang);
+                                               }
+                                       }
+                               }
+                               break;
+                       case 'T':
+                               res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
+                               break;
+                       case ' ':
+                       case '  ':
+                               /* Just ignore spaces and tabs */
+                               break;
+                       default:
+                               /* Unknown character */
+                               ast_log(LOG_WARNING, "Unknown character in datetime format %s: %c at pos %d\n", format, format[offset], offset);
+               }
+               /* Jump out on DTMF */
+               if (res)
+                       break;
+       }
+       return res;
+}
+
 /* Portuguese syntax */
 int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
 {