From b0fa96a32dc8b4b04dcb4d4e4765c67a7d275b9e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 16 Feb 2009 22:24:25 +0000 Subject: [PATCH] mod_say_en: add short form date/time (MODAPP-180) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12072 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 3 +- src/mod/say/mod_say_en/mod_say_en.c | 58 +++++++++++++++++++++++++++-- src/switch_ivr_play_say.c | 1 + 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index b6c555aaa6..dce378e277 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -281,7 +281,8 @@ typedef enum { SST_POSTAL_ADDRESS, SST_ACCOUNT_NUMBER, SST_NAME_SPELLED, - SST_NAME_PHONETIC + SST_NAME_PHONETIC, + SST_SHORT_DATE_TIME } switch_say_type_t; typedef enum { diff --git a/src/mod/say/mod_say_en/mod_say_en.c b/src/mod/say/mod_say_en/mod_say_en.c index 04debd0b31..ce4f32e667 100644 --- a/src/mod/say/mod_say_en/mod_say_en.c +++ b/src/mod/say/mod_say_en/mod_say_en.c @@ -263,9 +263,9 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay, switch_input_args_t *args) { int32_t t; - switch_time_t target = 0; - switch_time_exp_t tm; - uint8_t say_date = 0, say_time = 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; switch_channel_t *channel = switch_core_session_get_channel(session); const char *tz = switch_channel_get_variable(channel, "timezone"); @@ -351,19 +351,24 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay, 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) { int check = atoi(tz); if (check) { switch_time_exp_tz(&tm, target, check); + switch_time_exp_tz(&tm_now, target_now, check); } else { switch_time_exp_tz_name(tz, &tm, target); + switch_time_exp_tz_name(tz, &tm_now, target_now); } } else { switch_time_exp_lt(&tm, target); + switch_time_exp_lt(&tm_now, target_now); } switch (type) { @@ -375,15 +380,59 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay, break; case SST_CURRENT_TIME: say_time = 1; + break; + case SST_SHORT_DATE_TIME: + say_time = 1; + if (tm.tm_year != tm_now.tm_year) { + say_date = 1; + break; + } + if (tm.tm_yday == tm_now.tm_yday) { + say_today = 1; + break; + } + if (tm.tm_yday == tm_now.tm_yday - 1) { + say_yesterday = 1; + break; + } + if (tm.tm_yday >= tm_now.tm_yday - 5) { + say_dow = 1; + break; + } + if (tm.tm_mon != tm_now.tm_mon) { + say_month = say_day = say_dow = 1; + break; + } + + say_month = say_day = say_dow = 1; + break; default: break; } - if (say_date) { + if (say_today) { + say_file("time/today.wav"); + } + if (say_yesterday) { + say_file("time/yesterday.wav"); + } + if (say_dow) { say_file("time/day-%d.wav", tm.tm_wday); + } + + if (say_date) { + say_year = say_month = say_day = say_dow = 1; + say_today = say_yesterday = 0; + } + + if (say_month) { say_file("time/mon-%d.wav", tm.tm_mon); + } + if (say_day) { say_num(tm.tm_mday, SSM_COUNTED); + } + if (say_year) { say_num(tm.tm_year + 1900, SSM_PRONOUNCED); } @@ -495,6 +544,7 @@ static switch_status_t en_say(switch_core_session_t *session, char *tosay, switc case SST_CURRENT_DATE: case SST_CURRENT_TIME: case SST_CURRENT_DATE_TIME: + case SST_SHORT_DATE_TIME: say_cb = en_say_time; break; case SST_IP_ADDRESS: diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 752182fc11..e554522c28 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -62,6 +62,7 @@ static char *SAY_TYPE_NAMES[] = { "ACCOUNT_NUMBER", "NAME_SPELLED", "NAME_PHONETIC", + "SHORT_DATE_TIME", NULL };