From a8c5a0c87bf97ad0f84df2ad53d6eef2a951eee9 Mon Sep 17 00:00:00 2001
From: Hristo Trendev <htrendev@gmail.com>
Date: Tue, 2 Dec 2014 17:08:12 +0100
Subject: [PATCH] add timezone support to mod_say_{de,es,ja,nl,th,zh}

This is nothing more than a shameless copy/paste from another mod_say
module, which already had timezone support. It simply checks if the
timezone variable is set and if it contains a valid timezone, then this
timezone will be used when announcing times/dates.

FS-7048 #resolve
---
 src/mod/say/mod_say_de/mod_say_de.c | 15 ++++++++++++++-
 src/mod/say/mod_say_es/mod_say_es.c | 15 ++++++++++++++-
 src/mod/say/mod_say_ja/mod_say_ja.c | 15 ++++++++++++++-
 src/mod/say/mod_say_nl/mod_say_nl.c | 15 ++++++++++++++-
 src/mod/say/mod_say_th/mod_say_th.c | 15 ++++++++++++++-
 src/mod/say/mod_say_zh/mod_say_zh.c | 15 ++++++++++++++-
 6 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/src/mod/say/mod_say_de/mod_say_de.c b/src/mod/say/mod_say_de/mod_say_de.c
index 2116942ca2..00af9dd1fe 100644
--- a/src/mod/say/mod_say_de/mod_say_de.c
+++ b/src/mod/say/mod_say_de/mod_say_de.c
@@ -226,6 +226,8 @@ static switch_status_t de_say_time(switch_core_session_t *session, char *tosay,
 	switch_time_t target = 0;
 	switch_time_exp_t tm;
 	uint8_t say_date = 0, say_time = 0;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	const char *tz = switch_channel_get_variable(channel, "timezone");
 
 	if (say_args->type == SST_TIME_MEASUREMENT) {
 		int64_t hours = 0;
@@ -314,7 +316,18 @@ static switch_status_t de_say_time(switch_core_session_t *session, char *tosay,
 	} else {
 		target = switch_micro_time_now();
 	}
-	switch_time_exp_lt(&tm, target);
+
+	if (tz) {
+		int check = atoi(tz);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
+		if (check) {
+			switch_time_exp_tz(&tm, target, check);
+		} else {
+			switch_time_exp_tz_name(tz, &tm, target);
+		}
+	} else {
+		switch_time_exp_lt(&tm, target);
+	}
 
 	switch (say_args->type) {
 	case SST_CURRENT_DATE_TIME:
diff --git a/src/mod/say/mod_say_es/mod_say_es.c b/src/mod/say/mod_say_es/mod_say_es.c
index efda97b468..8de56e861e 100644
--- a/src/mod/say/mod_say_es/mod_say_es.c
+++ b/src/mod/say/mod_say_es/mod_say_es.c
@@ -220,6 +220,8 @@ static switch_status_t es_say_time(switch_core_session_t *session, char *tosay,
 	switch_time_t target = 0;
 	switch_time_exp_t tm;
 	uint8_t say_date = 0, say_time = 0;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	const char *tz = switch_channel_get_variable(channel, "timezone");
 
 	if (say_args->type == SST_TIME_MEASUREMENT) {
 		int64_t hours = 0;
@@ -304,7 +306,18 @@ static switch_status_t es_say_time(switch_core_session_t *session, char *tosay,
 	} else {
 		target = switch_micro_time_now();
 	}
-	switch_time_exp_lt(&tm, target);
+
+	if (tz) {
+		int check = atoi(tz);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
+		if (check) {
+			switch_time_exp_tz(&tm, target, check);
+		} else {
+			switch_time_exp_tz_name(tz, &tm, target);
+		}
+	} else {
+		switch_time_exp_lt(&tm, target);
+	}
 
 	switch (say_args->type) {
 	case SST_CURRENT_DATE_TIME:
diff --git a/src/mod/say/mod_say_ja/mod_say_ja.c b/src/mod/say/mod_say_ja/mod_say_ja.c
index 76d2ac69f9..72c7c38131 100644
--- a/src/mod/say/mod_say_ja/mod_say_ja.c
+++ b/src/mod/say/mod_say_ja/mod_say_ja.c
@@ -248,6 +248,8 @@ static switch_status_t ja_say_time(switch_core_session_t *session, char *tosay,
 	switch_time_exp_t tm;
 	uint8_t say_date = 0;
 	uint8_t say_time = 0;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	const char *tz = switch_channel_get_variable(channel, "timezone");
 
 	int mod_min;
 	char buffer[3];
@@ -322,7 +324,18 @@ static switch_status_t ja_say_time(switch_core_session_t *session, char *tosay,
 		target = switch_time_make(t, 0);
 	else
 		target = switch_micro_time_now();
-	switch_time_exp_lt(&tm, target);
+
+	if (tz) {
+		int check = atoi(tz);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
+		if (check) {
+			switch_time_exp_tz(&tm, target, check);
+		} else {
+			switch_time_exp_tz_name(tz, &tm, target);
+		}
+	} else {
+		switch_time_exp_lt(&tm, target);
+	}
 
 	switch (say_args->type) {
 	case SST_CURRENT_DATE_TIME:
diff --git a/src/mod/say/mod_say_nl/mod_say_nl.c b/src/mod/say/mod_say_nl/mod_say_nl.c
index f6dec530d1..6ab2bb98bb 100644
--- a/src/mod/say/mod_say_nl/mod_say_nl.c
+++ b/src/mod/say/mod_say_nl/mod_say_nl.c
@@ -178,6 +178,8 @@ static switch_status_t nl_say_time(switch_core_session_t *session, char *tosay,
 	switch_time_t target = 0;
 	switch_time_exp_t tm;
 	uint8_t say_date = 0, say_time = 0;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	const char *tz = switch_channel_get_variable(channel, "timezone");
 
 	if (say_args->type == SST_TIME_MEASUREMENT) {
 		int64_t hours = 0;
@@ -262,7 +264,18 @@ static switch_status_t nl_say_time(switch_core_session_t *session, char *tosay,
 	} else {
 		target = switch_micro_time_now();
 	}
-	switch_time_exp_lt(&tm, target);
+
+	if (tz) {
+		int check = atoi(tz);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
+		if (check) {
+			switch_time_exp_tz(&tm, target, check);
+		} else {
+			switch_time_exp_tz_name(tz, &tm, target);
+		}
+	} else {
+		switch_time_exp_lt(&tm, target);
+	}
 
 	switch (say_args->type) {
 	case SST_CURRENT_DATE_TIME:
diff --git a/src/mod/say/mod_say_th/mod_say_th.c b/src/mod/say/mod_say_th/mod_say_th.c
index ac60b01d9a..a78251a024 100644
--- a/src/mod/say/mod_say_th/mod_say_th.c
+++ b/src/mod/say/mod_say_th/mod_say_th.c
@@ -234,6 +234,8 @@ static switch_status_t th_say_time(switch_core_session_t *session, char *tosay,
 	int32_t t;
 	switch_time_t target = 0;
 	switch_time_exp_t tm;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	const char *tz = switch_channel_get_variable(channel, "timezone");
 #if 0
 	switch_time_t this_morning;
 	switch_time_exp_t tm2;
@@ -323,7 +325,18 @@ static switch_status_t th_say_time(switch_core_session_t *session, char *tosay,
 		target = switch_time_make(t, 0);
 	else
 		target = switch_micro_time_now();
-	switch_time_exp_lt(&tm, target);
+
+	if (tz) {
+		int check = atoi(tz);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
+		if (check) {
+			switch_time_exp_tz(&tm, target, check);
+		} else {
+			switch_time_exp_tz_name(tz, &tm, target);
+		}
+	} else {
+		switch_time_exp_lt(&tm, target);
+	}
 
 	switch (say_args->type) {
 	case SST_CURRENT_DATE_TIME:
diff --git a/src/mod/say/mod_say_zh/mod_say_zh.c b/src/mod/say/mod_say_zh/mod_say_zh.c
index 457654396d..f84932dd5c 100644
--- a/src/mod/say/mod_say_zh/mod_say_zh.c
+++ b/src/mod/say/mod_say_zh/mod_say_zh.c
@@ -198,6 +198,8 @@ static switch_status_t zh_say_time(switch_core_session_t *session, char *tosay,
 	int32_t t;
 	switch_time_t target = 0;
 	switch_time_exp_t tm;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	const char *tz = switch_channel_get_variable(channel, "timezone");
 #if 0
 	switch_time_t this_morning;
 	switch_time_exp_t tm2;
@@ -287,7 +289,18 @@ static switch_status_t zh_say_time(switch_core_session_t *session, char *tosay,
 		target = switch_time_make(t, 0);
 	else
 		target = switch_micro_time_now();
-	switch_time_exp_lt(&tm, target);
+
+	if (tz) {
+		int check = atoi(tz);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
+		if (check) {
+			switch_time_exp_tz(&tm, target, check);
+		} else {
+			switch_time_exp_tz_name(tz, &tm, target);
+		}
+	} else {
+		switch_time_exp_lt(&tm, target);
+	}
 
 	switch (say_args->type) {
 	case SST_CURRENT_DATE_TIME: