Newer
Older
Tilghman Lesher
committed
res |= ast_say_number(chan, tm.tm_year, ints, lang, (char *) NULL);
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
}
}
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 */
if (format[offset] == 'H') {
/* e.g. oh-eight */
if (tm.tm_hour < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
}
} else {
/* e.g. eight */
if (tm.tm_hour == 0) {
res = wait_file(chan,ints, "digits/oh",lang);
}
}
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':
Kevin P. Fleming
committed
case 'N':
/* Minute */
if (tm.tm_min == 0) {
Kevin P. Fleming
committed
if (format[offset] == 'M') {
res = wait_file(chan, ints, "digits/oclock", lang);
} else {
res = wait_file(chan, ints, "digits/hundred", lang);
}
} else if (tm.tm_min < 10) {
res = wait_file(chan,ints, "digits/oh",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
res = wait_file(chan,ints,nextmsg,lang);
}
} else {
Kevin P. Fleming
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 */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
Mark Spencer
committed
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Mark Spencer
committed
gettimeofday(&now,NULL);
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&tmnow,timezone);
Mark Spencer
committed
/* 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() */
Kevin P. Fleming
committed
beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
Mark Spencer
committed
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);
Tilghman Lesher
committed
} else if (beg_today - 86400 * 6 < time) {
/* Within the last week */
res = ast_say_date_with_format_en(chan, time, ints, lang, "A", timezone);
} else if (beg_today - 2628000 < time) {
/* Less than a month ago - "Sunday, October third" */
res = ast_say_date_with_format_en(chan, time, ints, lang, "ABd", timezone);
} else if (beg_today - 15768000 < time) {
/* Less than 6 months ago - "August seventh" */
res = ast_say_date_with_format_en(chan, time, ints, lang, "Bd", timezone);
Mark Spencer
committed
} else {
Tilghman Lesher
committed
/* More than 6 months ago - "April nineteenth two thousand three" */
res = ast_say_date_with_format_en(chan, time, ints, lang, "BdY", timezone);
Mark Spencer
committed
}
}
break;
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
Mark Spencer
committed
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Mark Spencer
committed
gettimeofday(&now,NULL);
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&tmnow,timezone);
Mark Spencer
committed
/* 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() */
Kevin P. Fleming
committed
beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
Mark Spencer
committed
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 */
Tilghman Lesher
committed
res = ast_say_date_with_format_en(chan, time, ints, lang, "A", timezone);
} else if (beg_today - 2628000 < time) {
/* Less than a month ago - "Sunday, October third" */
res = ast_say_date_with_format_en(chan, time, ints, lang, "ABd", timezone);
} else if (beg_today - 15768000 < time) {
/* Less than 6 months ago - "August seventh" */
res = ast_say_date_with_format_en(chan, time, ints, lang, "Bd", timezone);
Mark Spencer
committed
} else {
Tilghman Lesher
committed
/* More than 6 months ago - "April nineteenth two thousand three" */
res = ast_say_date_with_format_en(chan, time, ints, lang, "BdY", timezone);
Mark Spencer
committed
}
}
break;
case 'R':
Tilghman Lesher
committed
res = ast_say_date_with_format_en(chan, time, ints, lang, "HM", timezone);
Mark Spencer
committed
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 {
Kevin P. Fleming
committed
res = ast_say_number(chan, tm.tm_sec, ints, lang, (char *) NULL);
Mark Spencer
committed
}
break;
case 'T':
Tilghman Lesher
committed
res = ast_say_date_with_format_en(chan, time, ints, lang, "HMS", timezone);
Mark Spencer
committed
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;
}
/* Danish syntax */
int ast_say_date_with_format_da(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];
Tilghman Lesher
committed
if (!format)
format = "A dBY HMS";
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
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
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
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;
case 'm':
/* Month enumerated */
res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");
break;
case 'd':
case 'e':
/* First - Thirtyfirst */
res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");
break;
case 'Y':
/* Year */
{
int year = tm.tm_year + 1900;
if (year > 1999) { /* year 2000 and later */
res = ast_say_number(chan, year, ints, lang, (char *) NULL);
} else {
if (year < 1100) {
/* I'm not going to handle 1100 and prior */
/* We'll just be silent on the year, instead of bombing out. */
} else {
/* year 1100 to 1999. will anybody need this?!? */
/* say 1967 as 'nineteen hundred seven and sixty' */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (year / 100) );
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
res = wait_file(chan,ints, "digits/hundred",lang);
if (!res && year % 100 != 0) {
res = ast_say_number(chan, (year % 100), ints, lang, (char *) NULL);
}
}
}
}
}
break;
case 'I':
case 'l':
/* 12-Hour */
res = wait_file(chan,ints,"digits/oclock",lang);
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);
if (!res) {
res = wait_file(chan,ints,nextmsg,lang);
}
break;
case 'H':
/* 24-Hour, single digit hours preceeded by "oh" (0) */
if (tm.tm_hour < 10 && tm.tm_hour > 0) {
res = wait_file(chan,ints, "digits/0",lang);
}
/* FALLTRHU */
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
break;
case 'M':
/* Minute */
if (tm.tm_min > 0 || format[offset+ 1 ] == 'S' ) { /* zero 'digits/0' only if seconds follow (kind of a hack) */
res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
}
if ( !res && format[offset + 1] == 'S' ) { /* minutes only if seconds follow (kind of a hack) */
if (tm.tm_min == 1) {
res = wait_file(chan,ints,"digits/minute",lang);
} else {
res = wait_file(chan,ints,"digits/minutes",lang);
}
}
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 */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&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() */
Kevin P. Fleming
committed
beg_today = tt - (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 {
Tilghman Lesher
committed
res = ast_say_date_with_format_da(chan, time, ints, lang, "AdBY", timezone);
}
}
break;
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&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() */
Kevin P. Fleming
committed
beg_today = tt - (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 */
Tilghman Lesher
committed
res = ast_say_date_with_format_da(chan, time, ints, lang, "A", timezone);
Tilghman Lesher
committed
res = ast_say_date_with_format_da(chan, time, ints, lang, "AdBY", timezone);
Tilghman Lesher
committed
res = ast_say_date_with_format_da(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':
Tilghman Lesher
committed
res = ast_say_date_with_format_da(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
/* German syntax */
int ast_say_date_with_format_de(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];
Tilghman Lesher
committed
if (!format)
format = "A dBY HMS";
Mark Spencer
committed
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
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;
case 'm':
/* Month enumerated */
res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, "m");
break;
case 'd':
case 'e':
/* First - Thirtyfirst */
res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, "m");
break;
case 'Y':
/* Year */
{
int year = tm.tm_year + 1900;
if (year > 1999) { /* year 2000 and later */
res = ast_say_number(chan, year, ints, lang, (char *) NULL);
} else {
if (year < 1100) {
/* I'm not going to handle 1100 and prior */
/* We'll just be silent on the year, instead of bombing out. */
} else {
/* year 1100 to 1999. will anybody need this?!? */
/* say 1967 as 'neunzehn hundert sieben und sechzig' */
Mark Spencer
committed
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (year / 100) );
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
res = wait_file(chan,ints, "digits/hundred",lang);
if (!res && year % 100 != 0) {
res = ast_say_number(chan, (year % 100), 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);
if (!res) {
res = wait_file(chan,ints,"digits/oclock",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/oclock",lang);
}
break;
case 'M':
/* Minute */
if (tm.tm_min > 0 || format[offset+ 1 ] == 'S' ) { /* zero 'digits/0' only if seconds follow (kind of a hack) */
res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
}
if ( !res && format[offset + 1] == 'S' ) { /* minutes only if seconds follow (kind of a hack) */
if (tm.tm_min == 1) {
res = wait_file(chan,ints,"digits/minute",lang);
} else {
res = wait_file(chan,ints,"digits/minutes",lang);
}
}
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 */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
Mark Spencer
committed
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Mark Spencer
committed
gettimeofday(&now,NULL);
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&tmnow,timezone);
Mark Spencer
committed
/* 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() */
Kevin P. Fleming
committed
beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
Mark Spencer
committed
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 {
Tilghman Lesher
committed
res = ast_say_date_with_format_de(chan, time, ints, lang, "AdBY", timezone);
Mark Spencer
committed
}
}
break;
case 'q':
/* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
Mark Spencer
committed
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Mark Spencer
committed
gettimeofday(&now,NULL);
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&tmnow,timezone);
Mark Spencer
committed
/* 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 */
Tilghman Lesher
committed
res = ast_say_date_with_format_de(chan, time, ints, lang, "A", timezone);
Mark Spencer
committed
} else {
Tilghman Lesher
committed
res = ast_say_date_with_format_de(chan, time, ints, lang, "AdBY", timezone);
Mark Spencer
committed
}
}
break;
case 'R':
Tilghman Lesher
committed
res = ast_say_date_with_format_de(chan, time, ints, lang, "HM", timezone);
Mark Spencer
committed
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':
Tilghman Lesher
committed
res = ast_say_date_with_format_de(chan, time, ints, lang, "HMS", timezone);
Mark Spencer
committed
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;
}
/* TODO: this probably is not the correct format for doxygen remarks */
/** ast_say_date_with_format_he Say formmated date in Hebrew
*
* \ref ast_say_date_with_format_en for the details of the options
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
*
* Changes from the English version:
*
* * don't replicate in here the logic of ast_say_number_full_he
*
* * year is always 4-digit (because it's simpler)
*
* * added c, x, and X. Mainly for my tests
*
* * The standard "long" format used in Hebrew is AdBY, rather than ABdY
*
* TODO:
* * A "ha" is missing in the standard date format, before the 'd'.
* * The numbers of 3000--19000 are not handled well
**/
#define IL_DATE_STR "AdBY"
#define IL_TIME_STR "IMp"
#define IL_DATE_STR_FULL IL_DATE_STR " 'digits/at' " IL_TIME_STR
int ast_say_date_with_format_he(struct ast_channel *chan, time_t time,
const char *ints, const char *lang, const char *format,
const char *timezone)
{
/* TODO: This whole function is cut&paste from
* ast_say_date_with_format_en . Is that considered acceptable?
**/
struct tm tm;
int res=0, offset, sndoffset;
char sndfile[256], nextmsg[256];
Tilghman Lesher
committed
if (!format)
format = IL_DATE_STR_FULL;
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
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;
case 'd':
case 'e': /* Day of the month */
/* I'm not sure exactly what the parameters
* audiofd and ctrlfd to
* ast_say_number_full_he mean, but it seems
* safe to pass -1 there.
*
* At least in one of the pathes :-(
*/
res = ast_say_number_full_he(chan, tm.tm_mday,
ints, lang, "m", -1, -1
);
break;
case 'Y': /* Year */
res = ast_say_number_full_he(chan, tm.tm_year+1900,
ints, lang, "f", -1, -1
);
break;
case 'I':
case 'l': /* 12-Hour */
{
int hour = tm.tm_hour;
hour = hour%12;
if (hour == 0) hour=12;
res = ast_say_number_full_he(chan, hour,
ints, lang, "f", -1, -1
);
}
break;
case 'H':
case 'k': /* 24-Hour */
/* With 'H' there is an 'oh' after a single-
* digit hour */
if ((format[offset] == 'H') &&
(tm.tm_hour <10)&&(tm.tm_hour>0)
) { /* e.g. oh-eight */
res = wait_file(chan,ints, "digits/oh",lang);
}
res = ast_say_number_full_he(chan, tm.tm_hour,
ints, lang, "f", -1, -1
);
break;
case 'M': /* Minute */
res = ast_say_number_full_he(chan, tm.tm_min,
ints, lang,"f", -1, -1
);
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 "date" */
case 'q':
/* Shorthand for "" (today), "Yesterday", A
* (weekday), or "date" */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
char todo = format[offset]; /* The letter to format*/
gettimeofday(&now,NULL);
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&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() */
Kevin P. Fleming
committed
beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec);
if (beg_today < time) {
/* Today */
if (todo == 'Q') {
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 ((todo != 'Q') &&
(beg_today - 86400 * 6 < time))
{
/* Within the last week */
res = ast_say_date_with_format_he(chan,
time, ints, lang,
"A", timezone);
res = ast_say_date_with_format_he(chan,
time, ints, lang,
IL_DATE_STR, timezone);
}
}
break;
case 'R':
Tilghman Lesher
committed
res = ast_say_date_with_format_he(chan, time, ints, lang, "HM", timezone);
break;
case 'S': /* Seconds */
res = ast_say_number_full_he(chan, tm.tm_sec,
ints, lang, "f", -1, -1
);
break;
case 'T':
Tilghman Lesher
committed
res = ast_say_date_with_format_he(chan, time, ints, lang, "HMS", timezone);
break;
/* c, x, and X seem useful for testing. Not sure
* if thiey're good for the general public */
Tilghman Lesher
committed
case 'c':
res = ast_say_date_with_format_he(chan, time,
ints, lang, IL_DATE_STR_FULL, timezone);
break;
Tilghman Lesher
committed
case 'x':
res = ast_say_date_with_format_he(chan, time,
ints, lang, IL_DATE_STR, timezone);
break;
Tilghman Lesher
committed
case 'X': /* Currently not locale-dependent...*/
res = ast_say_date_with_format_he(chan, time,
ints, lang, IL_TIME_STR, 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
/* 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];
Tilghman Lesher
committed
if (format == NULL)
format = "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y 'digits/at' IMp";
Mark Spencer
committed
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
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);
Mark Spencer
committed
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 */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&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() */
Kevin P. Fleming
committed
beg_today = tt - (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 {
Tilghman Lesher
committed
res = ast_say_date_with_format_es(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 */
Tilghman Lesher
committed
/* XXX As emphasized elsewhere, this should the native way in your
* language to say the date, with changes in what you say, depending
* upon how recent the date is. XXX */
{
struct timeval now;
struct tm tmnow;
Kevin P. Fleming
committed
time_t beg_today, tt;
Kevin P. Fleming
committed
tt = now.tv_sec;
ast_localtime(&tt,&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() */
Kevin P. Fleming
committed
beg_today = tt - (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 */
Tilghman Lesher
committed
res = ast_say_date_with_format_es(chan, time, ints, lang, "A", timezone);
Tilghman Lesher
committed
res = ast_say_date_with_format_es(chan, time, ints, lang, "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y", timezone);
}
}
break;
case 'R':
Tilghman Lesher
committed
res = ast_say_date_with_format_es(chan, time, ints, lang, "H 'digits/y' M", timezone);
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
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':
Tilghman Lesher
committed
res = ast_say_date_with_format_es(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];
Tilghman Lesher
committed
if (format == NULL)
format = "AdBY 'digits/at' IMp";
ast_localtime(&time,&tm,timezone);