Newer
Older
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':
/* Month enumerated */
res = ast_say_enumeration(chan, (tm.tm_mon + 1), ints, lang, (char *) NULL);
break;
case 'd':
case 'e':
/* First - Thirtyfirst */
Mark Spencer
committed
res = ast_say_enumeration(chan, tm.tm_mday, ints, lang, (char *) NULL);
break;
case 'Y':
/* Year */
if (tm.tm_year > 99) {
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
Tilghman Lesher
committed
} 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. */
Tilghman Lesher
committed
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);
Tilghman Lesher
committed
res |= ast_say_number(chan, tm.tm_year, ints, lang, (char *) NULL);
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
}
}
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;
}
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
3269
3270
3271
3272
3273
3274
3275
3276
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
3302
3303
3304
3305
3306
/* 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];
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);
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
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 {
res = ast_say_date_with_format(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);
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
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
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;
}
Mark Spencer
committed
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
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
/* 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];
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
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
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
3535
3536
3537
3538
3539
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 {
res = ast_say_date_with_format(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 */
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
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
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
3625
/* 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;
}
/* 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
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
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
*
* 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];
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);
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
}
}
break;
case 'R':
res = ast_say_date_with_format(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':
res = ast_say_date_with_format(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 */
case 'c':
res = ast_say_date_with_format_he(chan, time,
ints, lang, IL_DATE_STR_FULL, timezone);
break;
case 'x':
res = ast_say_date_with_format_he(chan, time,
ints, lang, IL_DATE_STR, timezone);
break;
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
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
/* 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);
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 {
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 */
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 */
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);
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
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;