Newer
Older
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
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)
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
{
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 */
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
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':
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 {
res = ast_say_date_with_format(chan, time, ints, lang, "Ad 'digits/pt-de' B 'digits/pt-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 */
} 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, "Ad 'digits/pt-de' B 'digits/pt-de' Y", timezone);
}
}
break;
case 'R':
res = ast_say_date_with_format(chan, time, ints, lang, "H 'digits/pt-e' M", timezone);
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) {
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;
}
/* Taiwanese syntax */
Mark Spencer
committed
int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone)
{
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;
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
case 'd':
case 'e':
/* First - Thirtyfirst */
if (!(tm.tm_mday % 10) || (tm.tm_mday < 10)) {
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday);
res = wait_file(chan,ints,nextmsg,lang);
} else {
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%dh", tm.tm_mday - (tm.tm_mday % 10));
res = wait_file(chan,ints,nextmsg,lang);
if(!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/h-%d", tm.tm_mday % 10);
res = wait_file(chan,ints,nextmsg,lang);
}
}
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) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) / 10);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", (tm.tm_year - 100) % 10);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
if (!res) {
res = wait_file(chan,ints, "digits/year",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/1",lang);
if (!res) {
res = wait_file(chan,ints, "digits/9",lang);
}
if (!res) {
if (tm.tm_year <= 9) {
/* 1901 - 1909 */
res = wait_file(chan,ints, "digits/0",lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year);
res = wait_file(chan,ints,nextmsg,lang);
}
} else {
/* 1910 - 1999 */
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year / 10);
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_year % 10);
res = wait_file(chan,ints,nextmsg,lang);
}
}
}
}
if (!res) {
res = wait_file(chan,ints, "digits/year",lang);
}
}
break;
case 'I':
case 'l':
/* 12-Hour */
if (tm.tm_hour == 0)
snprintf(nextmsg,sizeof(nextmsg), "digits/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 */
if (!(tm.tm_hour % 10) || tm.tm_hour < 10) {
if (tm.tm_hour < 10) {
res = wait_file(chan, ints, "digits/0", lang);
}
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour);
res = wait_file(chan,ints,nextmsg,lang);
} else {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour - (tm.tm_hour % 10));
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_hour % 10);
res = wait_file(chan,ints,nextmsg,lang);
}
}
if (!res) {
res = wait_file(chan,ints, "digits/oclock",lang);
}
break;
case 'M':
/* Minute */
if (!(tm.tm_min % 10) || tm.tm_min < 10) {
if (tm.tm_min < 10) {
res = wait_file(chan, ints, "digits/0", lang);
}
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min);
res = wait_file(chan,ints,nextmsg,lang);
} else {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min - (tm.tm_min % 10));
Mark Spencer
committed
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_min % 10);
res = wait_file(chan,ints,nextmsg,lang);
Mark Spencer
committed
if (!res) {
res = wait_file(chan,ints, "digits/minute",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':
Mark Spencer
committed
/* 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, "YBdA", timezone);
Mark Spencer
committed
/* 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 {
Mark Spencer
committed
res = ast_say_date_with_format(chan, time, ints, lang, "YBdA", timezone);
}
}
break;
case 'R':
res = ast_say_date_with_format(chan, time, ints, lang, "HM", timezone);
break;
case 'S':
/* Seconds */
Mark Spencer
committed
if (!(tm.tm_sec % 10) || tm.tm_sec < 10) {
if (tm.tm_sec < 10) {
res = wait_file(chan, ints, "digits/0", lang);
}
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec);
res = wait_file(chan,ints,nextmsg,lang);
} else {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec - (tm.tm_sec % 10));
res = wait_file(chan,ints,nextmsg,lang);
if (!res) {
snprintf(nextmsg,sizeof(nextmsg), "digits/%d", tm.tm_sec % 10);
res = wait_file(chan,ints,nextmsg,lang);
}
}
if (!res) {
res = wait_file(chan,ints, "digits/second",lang);
}
break;
case 'T':
res = ast_say_date_with_format(chan, time, ints, lang, "HMS", timezone);
break;
case ' ':
case ' ':
/* Just ignore spaces and tabs */
Mark Spencer
committed
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_time(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
if (!strcasecmp(lang, "en") ) { /* English syntax */
return(ast_say_time_en(chan, t, ints, lang));
Mark Spencer
committed
} else if (!strcasecmp(lang, "de") ) { /* German syntax */
return(ast_say_time_de(chan, t, ints, lang));
} else if (!strcasecmp(lang, "fr") ) { /* French syntax */
return(ast_say_time_fr(chan, t, ints, lang));
} else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
return(ast_say_time_nl(chan, t, ints, lang));
} else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
return(ast_say_time_pt(chan, t, ints, lang));
} else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
return(ast_say_time_tw(chan, t, ints, lang));
} else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
return(ast_say_time_gr(chan, t, ints, lang));
}
/* Default to English */
return(ast_say_time_en(chan, t, ints, lang));
}
/* English syntax */
Mark Spencer
committed
int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
localtime_r(&t,&tm);
hour = tm.tm_hour;
if (!hour)
hour = 12;
else if (hour == 12)
pm = 1;
else if (hour > 12) {
hour -= 12;
pm = 1;
}
if (!res)
Mark Spencer
committed
res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
res = ast_streamfile(chan, "digits/oh", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
res = ast_streamfile(chan, "digits/oclock", lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (pm) {
if (!res)
res = ast_streamfile(chan, "digits/p-m", lang);
} else {
if (!res)
res = ast_streamfile(chan, "digits/a-m", lang);
}
if (!res)
res = ast_waitstream(chan, ints);
return res;
}
Mark Spencer
committed
/* German syntax */
int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
int res = 0;
localtime_r(&t,&tm);
if (!res)
Mark Spencer
committed
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
if (tm.tm_min > 0)
res = ast_say_number(chan, tm.tm_min, ints, lang, "f");
return res;
}
/* French syntax */
int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
int res = 0;
localtime_r(&t,&tm);
res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
if (tm.tm_min) {
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
}
return res;
}
Mark Spencer
committed
/* Dutch syntax */
int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
int res = 0;
localtime_r(&t,&tm);
if (!res)
res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
if (!res)
res = ast_streamfile(chan, "digits/nl-uur", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
if (tm.tm_min > 0)
res = ast_say_number(chan, tm.tm_min, ints, lang, NULL);
return res;
}
/* Portuguese syntax */
Mark Spencer
committed
int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
{
struct tm tm;
int res = 0;
int hour;
localtime_r(&t,&tm);
hour = tm.tm_hour;
if (!res)
res = ast_say_number(chan, hour, ints, lang, "f");
if (tm.tm_min) {
if (!res)
res = wait_file(chan, ints, "digits/pt-e", lang);
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
} else {
if (!res)
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);
}
if (!res)
res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
return res;
}
/* Taiwanese syntax */
Mark Spencer
committed
int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
{
struct tm tm;
int res = 0;
int hour, pm=0;
localtime_r(&t,&tm);
hour = tm.tm_hour;
if (!hour)
hour = 12;
else if (hour == 12)
pm = 1;
else if (hour > 12) {
hour -= 12;
pm = 1;
}
if (pm) {
if (!res)
res = ast_streamfile(chan, "digits/p-m", lang);
} else {
if (!res)
res = ast_streamfile(chan, "digits/a-m", lang);
}
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
if (!res)
res = ast_streamfile(chan, "digits/minute", lang);
if (!res)
res = ast_waitstream(chan, ints);
return res;
}
Mark Spencer
committed
int ast_say_datetime(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
if (!strcasecmp(lang, "en") ) { /* English syntax */
return(ast_say_datetime_en(chan, t, ints, lang));
Mark Spencer
committed
} else if (!strcasecmp(lang, "de") ) { /* German syntax */
return(ast_say_datetime_de(chan, t, ints, lang));
} else if (!strcasecmp(lang, "fr") ) { /* French syntax */
return(ast_say_datetime_fr(chan, t, ints, lang));
} else if (!strcasecmp(lang, "nl") ) { /* Dutch syntax */
return(ast_say_datetime_nl(chan, t, ints, lang));
} else if (!strcasecmp(lang, "pt") ) { /* Portuguese syntax */
return(ast_say_datetime_pt(chan, t, ints, lang));
} else if (!strcasecmp(lang, "tw") ) { /* Taiwanese syntax */
return(ast_say_datetime_tw(chan, t, ints, lang));
} else if (!strcasecmp(lang, "gr") ) { /* Greek syntax */
return(ast_say_datetime_gr(chan, t, ints, lang));
}
/* Default to English */
return(ast_say_datetime_en(chan, t, ints, lang));
}
/* English syntax */
Mark Spencer
committed
int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
{
struct tm tm;
char fn[256];
int res = 0;
int hour, pm=0;
localtime_r(&t,&tm);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
hour = tm.tm_hour;
if (!hour)
hour = 12;
else if (hour == 12)
pm = 1;
else if (hour > 12) {
hour -= 12;
pm = 1;
}
if (!res)
res = ast_say_number(chan, hour, ints, lang, (char *) NULL);
if (tm.tm_min > 9) {
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
} else if (tm.tm_min) {
if (!res)
res = ast_streamfile(chan, "digits/oh", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
} else {
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (pm) {
if (!res)
res = ast_streamfile(chan, "digits/p-m", lang);
} else {
if (!res)
res = ast_streamfile(chan, "digits/a-m", lang);
}
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
return res;
}
Mark Spencer
committed
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
/* German syntax */
int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
int res = 0;
localtime_r(&t,&tm);
res = ast_say_date(chan, t, ints, lang);
if (!res)
ast_say_time(chan, t, ints, lang);
return res;
}
/* French syntax */
int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
char fn[256];
int res = 0;
localtime_r(&t,&tm);
if (!res)
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
if (!res) {
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
if (tm.tm_min > 0) {
if (!res)
res = ast_say_number(chan, tm.tm_min, ints, lang, (char *) NULL);
}
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
return res;
}
/* Dutch syntax */
Mark Spencer
committed
int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
{
struct tm tm;
int res = 0;
localtime_r(&t,&tm);
res = ast_say_date(chan, t, ints, lang);
if (!res) {
res = ast_streamfile(chan, "digits/nl-om", lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
ast_say_time(chan, t, ints, lang);
return res;
}
/* Portuguese syntax */
Mark Spencer
committed
int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang)
char fn[256];
int res = 0;
int hour, pm=0;
snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
Mark Spencer
committed
res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);