Newer
Older
Mark Spencer
committed
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
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) {
res = ast_say_number(chan, tm.tm_sec, ints, lang, "f");
if (!res) {
res = wait_file(chan,ints, "digits/seconds",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;
}
/* Spanish syntax */
int ast_say_date_with_format_es(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++) {
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';
snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile);
res = wait_file(chan,ints,nextmsg,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':
/* First - Twelfth */
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'd':
case 'e':
/* First - Thirtyfirst */
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
break;
case 'Y':
/* Year */
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
break;
case 'I':
case 'l':
/* 12-Hour */
if (tm.tm_hour == 0)
snprintf(nextmsg,sizeof(nextmsg), "digits/12");
else if (tm.tm_hour > 12)
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
else
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'H':
case 'k':
/* 24-Hour */
res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL);
if (!res) {
if (tm.tm_hour != 0) {
int remainder = tm.tm_hour;
if (tm.tm_hour > 20) {
res = wait_file(chan,ints, "digits/20",lang);
remainder -= 20;
}
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
break;
case 'M':
/* Minute */
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
break;
case 'P':
case 'p':
/* AM/PM */
if (tm.tm_hour > 12)
res = wait_file(chan, ints, "digits/p-m", lang);
else if (tm.tm_hour && tm.tm_hour < 12)
res = wait_file(chan, ints, "digits/a-m", lang);
break;
case 'Q':
/* Shorthand for "Today", "Yesterday", or ABdY */
{
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 {
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
}
}
break;
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
{
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 */
Mark Spencer
committed
res = wait_file(chan,ints, "digits/today",lang);
} 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 {
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
}
}
break;
case 'R':
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/y' M", timezone);
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
break;
case 'S':
/* Seconds */
if (tm.tm_sec == 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else if (tm.tm_sec < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
}
} else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else {
int ten, one;
ten = (tm.tm_sec / 10) * 10;
one = (tm.tm_sec % 10);
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
/* Fifty, not fifty-zero */
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,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;
}
Mark Spencer
committed
/* French syntax
oclock = heure
*/
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)
{
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++) {
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;
Mark Spencer
committed
case 'm':
/* First - Twelfth */
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'd':
case 'e':
Mark Spencer
committed
/* First */
if (tm.tm_mday == 1) {
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
res = wait_file(chan,ints,nextmsg,lang);
} else {
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char * ) NULL);
}
break;
case 'Y':
/* Year */
if (tm.tm_year > 99) {
Mark Spencer
committed
res = wait_file(chan,ints, "digits/2",lang);
if (!res) {
res = wait_file(chan,ints, "digits/thousand",lang);
}
if (tm.tm_year > 100) {
if (!res) {
res = ast_say_number(chan, tm.tm_year - 100, ints, lang, (char * ) NULL);
}
}
} 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. */
} else {
res = wait_file(chan,ints, "digits/19",lang);
if (!res) {
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_year, ints, lang, (char * ) NULL);
}
}
}
break;
case 'I':
case 'l':
/* 12-Hour */
if (tm.tm_hour == 0)
snprintf(nextmsg,sizeof(nextmsg), "digits/12");
else if (tm.tm_hour > 12)
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
else
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'H':
case 'k':
/* 24-Hour */
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
if (!res) {
Mark Spencer
committed
if (format[offset] == 'H') {
res = wait_file(chan,ints, "digits/oclock",lang);
}
}
break;
case 'M':
/* Minute */
Mark Spencer
committed
res = wait_file(chan,ints, "digits/oclock",lang);
if (res) break;
if (tm.tm_min == 0) break;
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
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':
Mark Spencer
committed
/* 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 {
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "AdBY", timezone);
}
}
break;
case 'q':
Mark Spencer
committed
/* 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 {
Mark Spencer
committed
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 */
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char * ) NULL);
if (!res) {
res = wait_file(chan,ints, "digits/second",lang);
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
}
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;
}
Mark Spencer
committed
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)
{
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++) {
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++)
Mark Spencer
committed
sndfile[sndoffset] = format[offset];
sndfile[sndoffset] = '\0';
Mark Spencer
committed
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;
Mark Spencer
committed
case 'm':
/* First - Twelfth */
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'd':
case 'e':
Mark Spencer
committed
/* First day of the month is spelled as ordinal */
if (tm.tm_mday == 1) {
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
res = wait_file(chan,ints,nextmsg,lang);
} else {
if (!res) {
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
}
}
break;
case 'Y':
/* Year */
Mark Spencer
committed
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
if (tm.tm_year > 99) {
res = wait_file(chan,ints, "digits/ore-2000",lang);
if (tm.tm_year > 100) {
if (!res) {
/* This works until the end of 2021 */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
res = wait_file(chan,ints,nextmsg,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. */
} else {
res = wait_file(chan,ints, "digits/ore-1900",lang);
if ((!res) && (tm.tm_year != 0)) {
if (tm.tm_year <= 21) {
/* 1910 - 1921 */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
res = wait_file(chan,ints,nextmsg,lang);
} else {
/* 1922 - 1999, but sounds badly in 1928, 1931, 1938, etc... */
int ten, one;
ten = tm.tm_year / 10;
one = tm.tm_year % 10;
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
}
}
}
break;
case 'I':
case 'l':
/* 12-Hour */
if (tm.tm_hour == 0)
snprintf(nextmsg,sizeof(nextmsg), "digits/12");
else if (tm.tm_hour > 12)
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
else
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
Mark Spencer
committed
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'H':
case 'k':
/* 24-Hour */
Mark Spencer
committed
if (tm.tm_hour == 0) {
res = wait_file(chan,ints, "digits/ore-mezzanotte",lang);
} else if (tm.tm_hour == 1) {
res = wait_file(chan,ints, "digits/ore-una",lang);
} else {
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
}
case 'M':
/* Minute */
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
break;
case 'P':
case 'p':
/* AM/PM */
Mark Spencer
committed
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 ABdY */
{
Mark Spencer
committed
struct timeval now;
struct tm tmnow;
time_t beg_today;
Mark Spencer
committed
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 {
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone);
}
}
break;
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
{
struct timeval now;
struct tm tmnow;
time_t beg_today;
Mark Spencer
committed
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 {
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "AdB", timezone);
}
}
break;
case 'R':
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
break;
case 'S':
/* Seconds */
if (tm.tm_sec == 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else if (tm.tm_sec < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
}
} else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else {
int ten, one;
ten = (tm.tm_sec / 10) * 10;
one = (tm.tm_sec % 10);
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
/* Fifty, not fifty-zero */
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
Mark Spencer
committed
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;
}
/* Dutch syntax */
Mark Spencer
committed
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)
{
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++) {
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;
Mark Spencer
committed
case 'm':
/* First - Twelfth */
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
res = wait_file(chan,ints,nextmsg,lang);
break;
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
case 'd':
case 'e':
/* First - Thirtyfirst */
res = ast_say_number(chan, tm.tm_mday, ints, lang, NULL);
break;
case 'Y':
/* Year */
if (tm.tm_year > 99) {
res = wait_file(chan,ints, "digits/2",lang);
if (!res) {
res = wait_file(chan,ints, "digits/thousand",lang);
}
if (tm.tm_year > 100) {
if (!res) {
/* This works until the end of 2020 */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year - 100);
res = wait_file(chan,ints,nextmsg,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. */
} else {
res = wait_file(chan,ints, "digits/19",lang);
if (!res) {
if (tm.tm_year <= 9) {
/* 1901 - 1909 */
res = wait_file(chan,ints, "digits/oh",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
res = wait_file(chan,ints,nextmsg,lang);
}
} else if (tm.tm_year <= 20) {
/* 1910 - 1920 */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
res = wait_file(chan,ints,nextmsg,lang);
} else {
/* 1921 - 1999 */
int ten, one;
ten = tm.tm_year / 10;
one = tm.tm_year % 10;
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten * 10);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
}
}
}
break;
case 'I':
case 'l':
/* 12-Hour */
if (tm.tm_hour == 0)
snprintf(nextmsg,sizeof(nextmsg), "digits/12");
else if (tm.tm_hour > 12)
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - 12);
else
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'H':
case 'k':
/* 24-Hour */
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
if (!res) {
res = wait_file(chan,ints, "digits/nl-uur",lang);
}
break;
case 'M':
/* Minute */
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
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 ABdY */
{
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, "ABdY", timezone);
}
}
break;
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
{
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, "ABdY", timezone);
}
}
break;
case 'R':
res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
break;
case 'S':
/* Seconds */
if (tm.tm_sec == 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else if (tm.tm_sec < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
}
} else if ((tm.tm_sec < 21) || (tm.tm_sec % 10 == 0)) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else {
int ten, one;
ten = (tm.tm_sec / 10) * 10;
one = (tm.tm_sec % 10);
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", ten);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
/* Fifty, not fifty-zero */
if (one != 0) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", one);
res = wait_file(chan,ints,nextmsg,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 */
Mark Spencer
committed
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)
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
{
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++) {
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';
snprintf(nextmsg,sizeof(nextmsg), "%s", sndfile);
res = wait_file(chan,ints,nextmsg,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;
Mark Spencer
committed
case 'm':
/* First - Twelfth */
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mon +1);
res = wait_file(chan,ints,nextmsg,lang);
break;
case 'd':
case 'e':
/* First - Thirtyfirst */
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
break;
case 'Y':
/* Year */
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
break;
case 'I':
case 'l':
/* 12-Hour */
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
if (tm.tm_hour == 0) {
if (format[offset] == 'I')
res = wait_file(chan, ints, "digits/pt-ah", lang);
if (!res)
res = wait_file(chan, ints, "digits/pt-meianoite", lang);
}
else if (tm.tm_hour == 12) {
if (format[offset] == 'I')
res = wait_file(chan, ints, "digits/pt-ao", lang);
if (!res)
res = wait_file(chan, ints, "digits/pt-meiodia", lang);
}
else {
if (format[offset] == 'I') {
res = wait_file(chan, ints, "digits/pt-ah", lang);
if ((tm.tm_hour % 12) != 1)
if (!res)
res = wait_file(chan, ints, "digits/pt-sss", lang);
}
if (!res)
res = ast_say_number(chan, (tm.tm_hour % 12), ints, lang, "f");
}
break;
case 'H':
case 'k':
/* 24-Hour */
res = ast_say_number(chan, -tm.tm_hour, ints, lang, NULL);
if (!res) {
if (tm.tm_hour != 0) {
int remainder = tm.tm_hour;
if (tm.tm_hour > 20) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", remainder);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
break;
case 'M':
/* Minute */
if (tm.tm_min == 0) {
res = wait_file(chan, ints, "digits/pt-hora", lang);
if (tm.tm_hour != 1)
if (!res)
res = wait_file(chan, ints, "digits/pt-sss", lang); } else {
res = wait_file(chan,ints,"digits/pt-e",lang);
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
}
break;
case 'P':