FS-10008: [mod_say_en] Add military time to say_en #resolve
This commit is contained in:
parent
d8c9b1ed16
commit
eee5abcc0c
|
@ -184,7 +184,7 @@ static switch_status_t en_say_general_count(switch_say_file_handle_t *sh, char *
|
|||
|
||||
static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args)
|
||||
{
|
||||
int32_t t;
|
||||
int32_t t = 0;
|
||||
switch_time_t target = 0, target_now = 0;
|
||||
switch_time_exp_t tm, tm_now;
|
||||
uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0;
|
||||
|
@ -192,6 +192,7 @@ static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, sw
|
|||
|
||||
tz = switch_say_file_handle_get_variable(sh, "timezone");
|
||||
|
||||
|
||||
if (say_args->type == SST_TIME_MEASUREMENT) {
|
||||
int64_t hours = 0;
|
||||
int64_t minutes = 0;
|
||||
|
@ -215,6 +216,7 @@ static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, sw
|
|||
}
|
||||
free(tme);
|
||||
} else {
|
||||
|
||||
if ((seconds = atol(tosay)) <= 0) {
|
||||
seconds = (int64_t) switch_epoch_time_now(NULL);
|
||||
}
|
||||
|
@ -271,12 +273,22 @@ static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, sw
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if ((t = atol(tosay)) > 0) {
|
||||
if (strchr(tosay, ':')) {
|
||||
switch_time_t tme = switch_str_time(tosay);
|
||||
t = (int32_t) ((tme) / (int64_t) (1000000));
|
||||
|
||||
target = switch_time_make(t, 0);
|
||||
target_now = switch_micro_time_now();
|
||||
} else {
|
||||
target = switch_micro_time_now();
|
||||
target_now = switch_micro_time_now();
|
||||
}
|
||||
|
||||
if (!t) {
|
||||
if ((t = atol(tosay)) > 0) {
|
||||
target = switch_time_make(t, 0);
|
||||
target_now = switch_micro_time_now();
|
||||
} else {
|
||||
target = switch_micro_time_now();
|
||||
target_now = switch_micro_time_now();
|
||||
}
|
||||
}
|
||||
|
||||
if (tz) {
|
||||
|
@ -369,34 +381,64 @@ static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, sw
|
|||
}
|
||||
|
||||
if (say_time) {
|
||||
int32_t hour = tm.tm_hour, pm = 0;
|
||||
int32_t hour = tm.tm_hour, pm = 0, mil = 0;
|
||||
|
||||
if (say_args->method == SSM_ITERATED) {
|
||||
mil = 1;
|
||||
}
|
||||
|
||||
if (say_date || say_today || say_yesterday || say_dow) {
|
||||
switch_say_file(sh, "time/at");
|
||||
}
|
||||
|
||||
if (hour > 12) {
|
||||
hour -= 12;
|
||||
pm = 1;
|
||||
mil++;
|
||||
} else if (hour == 12) {
|
||||
pm = 1;
|
||||
} else if (hour == 0) {
|
||||
hour = 12;
|
||||
pm = 0;
|
||||
if (mil) {
|
||||
if (tm.tm_min == 0) {
|
||||
hour = 24;
|
||||
}
|
||||
} else {
|
||||
hour = 12;
|
||||
pm = 0;
|
||||
}
|
||||
}
|
||||
|
||||
say_num(sh, hour, SSM_PRONOUNCED);
|
||||
if (mil) {
|
||||
|
||||
if (hour < 10) {
|
||||
say_num(sh, 0, SSM_PRONOUNCED);
|
||||
}
|
||||
|
||||
say_num(sh, hour, SSM_PRONOUNCED);
|
||||
|
||||
if (tm.tm_min > 9) {
|
||||
say_num(sh, tm.tm_min, SSM_PRONOUNCED);
|
||||
} else if (tm.tm_min) {
|
||||
say_num(sh, 0, SSM_PRONOUNCED);
|
||||
say_num(sh, tm.tm_min, SSM_PRONOUNCED);
|
||||
} else {
|
||||
switch_say_file(sh, "digits/hundred");
|
||||
}
|
||||
|
||||
switch_say_file(sh, "time/hours");
|
||||
|
||||
if (tm.tm_min > 9) {
|
||||
say_num(sh, tm.tm_min, SSM_PRONOUNCED);
|
||||
} else if (tm.tm_min) {
|
||||
switch_say_file(sh, "time/oh");
|
||||
say_num(sh, tm.tm_min, SSM_PRONOUNCED);
|
||||
} else {
|
||||
switch_say_file(sh, "time/oclock");
|
||||
}
|
||||
say_num(sh, hour, SSM_PRONOUNCED);
|
||||
|
||||
if (tm.tm_min > 9) {
|
||||
say_num(sh, tm.tm_min, SSM_PRONOUNCED);
|
||||
} else if (tm.tm_min) {
|
||||
switch_say_file(sh, "time/oh");
|
||||
say_num(sh, tm.tm_min, SSM_PRONOUNCED);
|
||||
} else {
|
||||
switch_say_file(sh, "time/oclock");
|
||||
}
|
||||
|
||||
switch_say_file(sh, "time/%s", pm ? "p-m" : "a-m");
|
||||
switch_say_file(sh, "time/%s", pm ? "p-m" : "a-m");
|
||||
}
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
|
|
@ -1919,22 +1919,46 @@ SWITCH_DECLARE(switch_status_t) switch_find_interface_ip(char *buf, int len, int
|
|||
SWITCH_DECLARE(switch_time_t) switch_str_time(const char *in)
|
||||
{
|
||||
switch_time_exp_t tm = { 0 }, local_tm = { 0 };
|
||||
int proceed = 0, ovector[30];
|
||||
int proceed = 0, ovector[30], time_only = 0;
|
||||
switch_regex_t *re = NULL;
|
||||
char replace[1024] = "";
|
||||
switch_time_t ret = 0, local_time = 0;
|
||||
char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
|
||||
char *pattern2 = "^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})";
|
||||
char *pattern3 = "^(\\d*):{0,1}(\\d*):{0,1}(\\d*)$";
|
||||
|
||||
switch_time_exp_lt(&tm, switch_micro_time_now());
|
||||
tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = tm.tm_usec = 0;
|
||||
|
||||
if (!(proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
switch_regex_safe_free(re);
|
||||
proceed = switch_regex_perform(in, pattern2, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
|
||||
|
||||
if ((time_only = switch_regex_perform(in, pattern3, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
tm.tm_hour = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_sec = 0;
|
||||
} else {
|
||||
tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = tm.tm_usec = 0;
|
||||
|
||||
if (!(proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
switch_regex_safe_free(re);
|
||||
proceed = switch_regex_perform(in, pattern2, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (proceed) {
|
||||
|
||||
if (proceed || time_only) {
|
||||
|
||||
if (time_only > 1) {
|
||||
switch_regex_copy_substring(in, ovector, time_only, 1, replace, sizeof(replace));
|
||||
tm.tm_hour = atoi(replace);
|
||||
}
|
||||
|
||||
if (time_only > 2) {
|
||||
switch_regex_copy_substring(in, ovector, time_only, 2, replace, sizeof(replace));
|
||||
tm.tm_min = atoi(replace);
|
||||
}
|
||||
|
||||
if (time_only > 3) {
|
||||
switch_regex_copy_substring(in, ovector, time_only, 3, replace, sizeof(replace));
|
||||
tm.tm_sec = atoi(replace);
|
||||
}
|
||||
|
||||
if (proceed > 1) {
|
||||
switch_regex_copy_substring(in, ovector, proceed, 1, replace, sizeof(replace));
|
||||
|
@ -1965,7 +1989,7 @@ SWITCH_DECLARE(switch_time_t) switch_str_time(const char *in)
|
|||
switch_regex_copy_substring(in, ovector, proceed, 6, replace, sizeof(replace));
|
||||
tm.tm_sec = atoi(replace);
|
||||
}
|
||||
|
||||
|
||||
switch_regex_safe_free(re);
|
||||
|
||||
switch_time_exp_get(&local_time, &tm);
|
||||
|
|
Loading…
Reference in New Issue