diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index 6479f7c7099b63a9febe27d2a967b2f1acf4575e..4960ecf9971239073afc886a693ddb2eedd9433b 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -715,8 +715,9 @@ static int get_date(char *s, int len)
 {
 	struct tm tm;
 	time_t t;
+
 	t = time(0);
-	localtime_r(&t,&tm);
+	ast_localtime(&t, &tm, NULL);
 	return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
 }
 
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 710072d91e97fb6ea9d6c3a0bcc15da5389878fe..8b934fbd846880744afe828301fa243e29fa7e66 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -2239,7 +2239,7 @@ static int get_date(char *s, int len)
 	struct tm tm;
 	time_t t;
 	t = time(0);
-	localtime_r(&t,&tm);
+	ast_localtime(&t, &tm, NULL);
 	return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
 }
 
@@ -4380,10 +4380,10 @@ static int play_message_datetime(struct ast_channel *chan, struct ast_vm_user *v
 /* No internal variable parsing for now, so we'll comment it out for the time being */
 #if 0
 	/* Set the DIFF_* variables */
-	localtime_r(&t, &time_now);
+	ast_localtime(&t, &time_now, NULL);
 	tv_now = ast_tvnow();
 	tnow = tv_now.tv_sec;
-	localtime_r(&tnow,&time_then);
+	ast_localtime(&tnow, &time_then, NULL);
 
 	/* Day difference */
 	if (time_now.tm_year == time_then.tm_year)
diff --git a/cdr/cdr_csv.c b/cdr/cdr_csv.c
index cbfe80fd0a59f6855e96a943e79cd4fdbfc86643..f40f555a8d58e18b099a75cd9b54a2fb128276d7 100644
--- a/cdr/cdr_csv.c
+++ b/cdr/cdr_csv.c
@@ -200,7 +200,7 @@ static int append_date(char *buf, struct timeval tv, size_t bufsize)
 	if (usegmtime) {
 		gmtime_r(&t,&tm);
 	} else {
-		localtime_r(&t,&tm);
+		ast_localtime(&t, &tm, NULL);
 	}
 	strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
 	return append_string(buf, tmp, bufsize);
diff --git a/cdr/cdr_manager.c b/cdr/cdr_manager.c
index bd6ef67098b8d2e3e91a8ba0aae280eabf333f34..352d7d400deaaffccc0643a4b28ce0b8a36fb61b 100644
--- a/cdr/cdr_manager.c
+++ b/cdr/cdr_manager.c
@@ -95,17 +95,17 @@ static int manager_log(struct ast_cdr *cdr)
 		return 0;
 
 	t = cdr->start.tv_sec;
-	localtime_r(&t, &timeresult);
+	ast_localtime(&t, &timeresult, NULL);
 	strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
 	
 	if (cdr->answer.tv_sec)	{
     		t = cdr->answer.tv_sec;
-    		localtime_r(&t, &timeresult);
+    		ast_localtime(&t, &timeresult, NULL);
 		strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
 	}
 
 	t = cdr->end.tv_sec;
-	localtime_r(&t, &timeresult);
+	ast_localtime(&t, &timeresult, NULL);
 	strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
 
 	manager_event(EVENT_FLAG_CALL, "Cdr",
diff --git a/cdr/cdr_odbc.c b/cdr/cdr_odbc.c
index 56f0cda353e69668acd3dad5ab17a496c4d22f6e..d9b1cbb9ee10e4dce8faa912ea7ce2046eaac2fa 100644
--- a/cdr/cdr_odbc.c
+++ b/cdr/cdr_odbc.c
@@ -99,7 +99,7 @@ static int odbc_log(struct ast_cdr *cdr)
 	if (usegmtime) 
 		gmtime_r(&cdr->start.tv_sec,&tm);
 	else
-		localtime_r(&cdr->start.tv_sec,&tm);
+		ast_localtime(&cdr->start.tv_sec, &tm, NULL);
 
 	ast_mutex_lock(&odbc_lock);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index 0b62440a88bd2dee8c91e7de9f3b6d9a3d28e73c..09df1bfd740eb06c70600a0a65af41f6bef78eb6 100644
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -78,7 +78,7 @@ static int pgsql_log(struct ast_cdr *cdr)
 
 	ast_mutex_lock(&pgsql_lock);
 
-	localtime_r(&cdr->start.tv_sec,&tm);
+	ast_localtime(&cdr->start.tv_sec, &tm, NULL);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
 	if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
diff --git a/cdr/cdr_radius.c b/cdr/cdr_radius.c
index ff380a13aa4ca441a3721c5d60fff06ea7384a4a..c41d680ddba01408cf22fd4e96079550ad71d91f 100644
--- a/cdr/cdr_radius.c
+++ b/cdr/cdr_radius.c
@@ -146,7 +146,7 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
 	if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
 		gmtime_r(&(cdr->start.tv_sec), &tm);
 	else
-		localtime_r(&(cdr->start.tv_sec), &tm);
+		ast_localtime(&(cdr->start.tv_sec), &tm, NULL);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE))
 		return -1;
@@ -155,7 +155,7 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
 	if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
 		gmtime_r(&(cdr->answer.tv_sec), &tm);
 	else
-		localtime_r(&(cdr->answer.tv_sec), &tm);
+		ast_localtime(&(cdr->answer.tv_sec), &tm, NULL);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE))
 		return -1;
@@ -164,7 +164,7 @@ static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
 	if (ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME))
 		gmtime_r(&(cdr->end.tv_sec), &tm);
 	else
-		localtime_r(&(cdr->end.tv_sec), &tm);
+		ast_localtime(&(cdr->end.tv_sec), &tm, NULL);
 	strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 	if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE))
 		return -1;
diff --git a/cdr/cdr_sqlite.c b/cdr/cdr_sqlite.c
index b47dd350c7ce2c437f573d0a8130506a6e18585c..52010ad93beacf55bd73ea0e6f81ecd88b221443 100644
--- a/cdr/cdr_sqlite.c
+++ b/cdr/cdr_sqlite.c
@@ -104,15 +104,15 @@ static int sqlite_log(struct ast_cdr *cdr)
 	ast_mutex_lock(&sqlite_lock);
 
 	t = cdr->start.tv_sec;
-	localtime_r(&t, &tm);
+	ast_localtime(&t, &tm, NULL);
 	strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
 
 	t = cdr->answer.tv_sec;
-	localtime_r(&t, &tm);
+	ast_localtime(&t, &tm, NULL);
 	strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
 
 	t = cdr->end.tv_sec;
-	localtime_r(&t, &tm);
+	ast_localtime(&t, &tm, NULL);
 	strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
 
 	for(count=0; count<5; count++) {
diff --git a/cdr/cdr_tds.c b/cdr/cdr_tds.c
index 3f79fc63742b474b09e3b7cd1921a0f4525edb4e..451bf1440229d74d84b72f176d729f689691107f 100644
--- a/cdr/cdr_tds.c
+++ b/cdr/cdr_tds.c
@@ -286,7 +286,7 @@ static void get_date(char *dateField, struct timeval tv)
 	if (!ast_tvzero(tv))
 	{
 		t = tv.tv_sec;
-		localtime_r(&t, &tm);
+		ast_localtime(&t, &tm, NULL);
 		strftime(buf, 80, DATE_FORMAT, &tm);
 		sprintf(dateField, "'%s'", buf);
 	}
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index c89ead79fd232159c75d7ed6b4f5bf1f7a5fb6e5..2092dfd64745e005c9ac9318c8bcbb32d4029214 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -2874,9 +2874,10 @@ static unsigned int iax2_datetime(const char *tz)
 	struct tm tm;
 	unsigned int tmp;
 	time(&t);
-	localtime_r(&t, &tm);
 	if (!ast_strlen_zero(tz))
 		ast_localtime(&t, &tm, tz);
+	else
+		ast_localtime(&t, &tm, NULL);
 	tmp  = (tm.tm_sec >> 1) & 0x1f;			/* 5 bits of seconds */
 	tmp |= (tm.tm_min & 0x3f) << 5;			/* 6 bits of minutes */
 	tmp |= (tm.tm_hour & 0x1f) << 11;		/* 5 bits of hours */
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 9c3161b7788b1d69f4604c38c712997a22bff8ef..c55f389766d19470d473f2d3db0cce965bc8d6eb 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -2237,7 +2237,7 @@ static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, ch
 	struct mgcp_endpoint *p = sub->parent;
 	
 	time(&t);
-	localtime_r(&t,&tm);
+	ast_localtime(&t, &tm, NULL);
 	n = callername;
 	l = callernum;
 	if (!n)
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index e33d1a1d2d9b844d42829b223064cb05b9d9d0f1..781431ce27fc33aaef3817005c542c0315732c14 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -295,7 +295,7 @@ static int phone_call(struct ast_channel *ast, char *dest, int timeout)
 	int start;
 
 	time(&UtcTime);
-	localtime_r(&UtcTime,&tm);
+	ast_localtime(&UtcTime, &tm, NULL);
 
 	memset(&cid, 0, sizeof(PHONE_CID));
 	if(&tm != NULL) {
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 4b523da986894b30e210439a1ab4df56509718c0..779db5ea06fa476428fc7b46d9cd661bc80bca99 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -33,11 +33,13 @@
 #include <netdb.h>
 #include <limits.h>
 #include <string.h>
+#include <time.h>	/* we want to override localtime_r */
 
 #include "asterisk/lock.h"
 #include "asterisk/time.h"
 #include "asterisk/logger.h"
 #include "asterisk/compiler.h"
+#include "asterisk/localtime.h"
 
 /*! 
 \note \verbatim
@@ -255,6 +257,11 @@ const char *ast_inet_ntoa(struct in_addr ia);
 #endif
 #define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
 
+#ifdef localtime_r
+#undef localtime_r
+#endif
+#define localtime_r __dont_use_localtime_r_use_ast_localtime_instead__
+
 int ast_utils_init(void);
 int ast_wait_for_input(int fd, int ms);
 
diff --git a/main/asterisk.c b/main/asterisk.c
index 4f5ada9b0de1378638dcc8691f241f6d48fe13f6..2e469729bbc146beefc3e3e9883adc6dea3c7f87 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -365,11 +365,11 @@ static int handle_show_settings(int fd, int argc, char *argv[])
 #if defined(HAVE_SYSINFO)
 	ast_cli(fd, "  Min Free Memory:             %ld MB\n", option_minmemfree);
 #endif
-	if (localtime_r(&ast_startuptime, &tm)) {
+	if (ast_localtime(&ast_startuptime, &tm, NULL)) {
 		strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
 		ast_cli(fd, "  Startup time:                %s\n", buf);
 	}
-	if (localtime_r(&ast_lastreloadtime, &tm)) {
+	if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) {
 		strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
 		ast_cli(fd, "  Last reload time:            %s\n", buf);
 	}
@@ -1864,7 +1864,7 @@ static char *cli_prompt(EditLine *el)
 				case 'd': /* date */
 					memset(&tm, 0, sizeof(tm));
 					time(&ts);
-					if (localtime_r(&ts, &tm)) 
+					if (ast_localtime(&ts, &tm, NULL))
 						strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm);
 					break;
 				case 'h': /* hostname */
@@ -1921,7 +1921,7 @@ static char *cli_prompt(EditLine *el)
 				case 't': /* time */
 					memset(&tm, 0, sizeof(tm));
 					time(&ts);
-					if (localtime_r(&ts, &tm))
+					if (ast_localtime(&ts, &tm, NULL))
 						strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm);
 					break;
 				case '#': /* process console or remote? */
diff --git a/main/callerid.c b/main/callerid.c
index 55e20d3da8e528e05dc9b2dd77c5c522c251ccc9..1401bbbd924b278dfccbaaded42ebde31c08306f 100644
--- a/main/callerid.c
+++ b/main/callerid.c
@@ -691,7 +691,7 @@ static int callerid_genmsg(char *msg, int size, const char *number, const char *
 
 	/* Get the time */
 	time(&t);
-	localtime_r(&t,&tm);
+	ast_localtime(&t, &tm, NULL);
 	
 	ptr = msg;
 	
diff --git a/main/cdr.c b/main/cdr.c
index 6614604ebe165bcb928ec4442424722c48f7a741..deed01e3f22e19f44a078c0a4bfa023ad7be5978 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -212,7 +212,8 @@ static void cdr_get_tv(struct timeval tv, const char *fmt, char *buf, int bufsiz
 		time_t t = tv.tv_sec;
 		if (t) {
 			struct tm tm;
-			localtime_r(&t, &tm);
+
+			ast_localtime(&t, &tm, NULL);
 			strftime(buf, bufsize, fmt, &tm);
 		}
 	}
diff --git a/main/logger.c b/main/logger.c
index e842c77bda35565e5b66d0d014b8e0c7c1d45289..c64b634f4f850ec97825aba957f1a7b791dc7f4f 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -931,7 +931,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
 
 	/* Create our date/time */
 	time(&t);
-	localtime_r(&t, &tm);
+	ast_localtime(&t, &tm, NULL);
 	strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm);
 
 	/* Copy over data */
@@ -1022,7 +1022,7 @@ void ast_verbose(const char *fmt, ...)
 		char *datefmt;
 
 		time(&t);
-		localtime_r(&t, &tm);
+		ast_localtime(&t, &tm, NULL);
 		strftime(date, sizeof(date), dateformat, &tm);
 		datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
 		sprintf(datefmt, "[%s] %s", date, fmt);
diff --git a/main/manager.c b/main/manager.c
index 31df724d5c0a49bd201b3fa2ea8bacf546e456c9..0124005545ffc905327d70e667dcd732330aa461 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2290,9 +2290,9 @@ static int action_corestatus(struct mansession *s, const struct message *m)
 	if (!ast_strlen_zero(actionid))
 		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
 
-	localtime_r(&ast_startuptime, &tm);
+	ast_localtime(&ast_startuptime, &tm, NULL);
 	strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
-	localtime_r(&ast_lastreloadtime, &tm);
+	ast_localtime(&ast_lastreloadtime, &tm, NULL);
 	strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
 
 	astman_append(s, "Response: Success\r\n"
diff --git a/main/pbx.c b/main/pbx.c
index dbd12039a60497ac139fd54be6baee611cc11a23..e01b7c9adb77c0bb906f013af66aa6b815ab4ccb 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -4311,7 +4311,7 @@ int ast_check_timing(const struct ast_timing *i)
 	struct tm tm;
 	time_t t = time(NULL);
 
-	localtime_r(&t,&tm);
+	ast_localtime(&t, &tm, NULL);
 
 	/* If it's not the right month, return */
 	if (!(i->monthmask & (1 << tm.tm_mon)))
diff --git a/main/say.c b/main/say.c
index fcb066e5a980bf3971d14e6a7c956b8ae363193d..c11ac72182bfc8a44da307b907cd30cdd3cea0d3 100644
--- a/main/say.c
+++ b/main/say.c
@@ -3062,8 +3062,8 @@ int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const
 	struct tm tm;
 	char fn[256];
 	int res = 0;
-	ast_localtime(&t,&tm,NULL);
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
 	if (!res)
 		res = wait_file(chan, ints, fn, lang);
@@ -5637,7 +5637,8 @@ int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const
 	struct tm tm;
 	int res = 0;
 	int hour, pm=0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	hour = tm.tm_hour;
 	if (!hour)
 		hour = 12;
@@ -5683,7 +5684,8 @@ int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	if (!res)
 		res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
 	if (!res)
@@ -5701,7 +5703,8 @@ int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	if (!res)
 		res = ast_say_number(chan, tm.tm_hour, ints, lang, "n");
 	if (!res)
@@ -5722,7 +5725,8 @@ int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 
 	res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
 	if (!res)
@@ -5739,7 +5743,8 @@ int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	if (!res)
 		res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL);
 	if (!res)
@@ -5758,7 +5763,8 @@ int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const
 	struct tm tm;
 	int res = 0;
 	int hour;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	hour = tm.tm_hour;
 	if (!res)
 		res = ast_say_number(chan, hour, ints, lang, "f");
@@ -5784,7 +5790,8 @@ int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, con
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 
 	res = ast_say_number(chan, tm.tm_hour, ints, lang, "f");
 	if (!res) {
@@ -5813,7 +5820,8 @@ int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const
 	struct tm tm;
 	int res = 0;
 	int hour, pm=0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	hour = tm.tm_hour;
 	if (!hour)
 		hour = 12;
@@ -5882,7 +5890,8 @@ int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, co
 	char fn[256];
 	int res = 0;
 	int hour, pm=0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	if (!res) {
 		snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
 		res = ast_streamfile(chan, fn, lang);
@@ -5945,7 +5954,8 @@ int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, co
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	res = ast_say_date(chan, t, ints, lang);
 	if (!res) 
 		ast_say_time(chan, t, ints, lang);
@@ -5958,7 +5968,8 @@ int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, co
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	res = ast_say_date(chan, t, ints, lang);
 	if (!res) 
 		ast_say_time(chan, t, ints, lang);
@@ -5971,7 +5982,8 @@ int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, co
 	struct tm tm;
 	char fn[256];
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 
 	if (!res)
 		res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL);
@@ -6009,7 +6021,8 @@ int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, co
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	res = ast_say_date(chan, t, ints, lang);
 	if (!res) {
 		res = ast_streamfile(chan, "digits/nl-om", lang);
@@ -6028,7 +6041,8 @@ int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, co
 	char fn[256];
 	int res = 0;
 	int hour, pm=0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	if (!res) {
 		snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
 		res = ast_streamfile(chan, fn, lang);
@@ -6091,7 +6105,8 @@ int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints,
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	res = ast_say_date(chan, t, ints, lang);
 	if (!res)
 		res = ast_say_time(chan, t, ints, lang);
@@ -6105,7 +6120,8 @@ int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, co
 	char fn[256];
 	int res = 0;
 	int hour, pm=0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	if (!res)
 		res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL);
 	if (!res) {
@@ -6184,8 +6200,8 @@ int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char
 
 	time(&nowt);
 
-	localtime_r(&t,&tm);
-	localtime_r(&nowt,&now);
+	ast_localtime(&t, &tm, NULL);
+	ast_localtime(&nowt,&now, NULL);
 	daydiff = now.tm_yday - tm.tm_yday;
 	if ((daydiff < 0) || (daydiff > 6)) {
 		/* Day of month and month */
@@ -6224,8 +6240,8 @@ int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char
 
 	time(&nowt);
 
-	localtime_r(&t,&tm);
-	localtime_r(&nowt,&now);
+	ast_localtime(&t, &tm, NULL);
+	ast_localtime(&nowt, &now, NULL);
 	daydiff = now.tm_yday - tm.tm_yday;
 	if ((daydiff < 0) || (daydiff > 6)) {
 		/* Day of month and month */
@@ -6264,8 +6280,8 @@ int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char
 
 	time(&nowt);
 
-	localtime_r(&t,&tm);
-	localtime_r(&nowt,&now);
+	ast_localtime(&t, &tm, NULL);
+	ast_localtime(&nowt, &now, NULL);
 	daydiff = now.tm_yday - tm.tm_yday;
 	if ((daydiff < 0) || (daydiff > 6)) {
 		/* Day of month and month */
@@ -6489,7 +6505,7 @@ static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints,
 	int res = 0;
 	int hour, pm=0;
 
-	localtime_r(&t,&tm);
+	ast_localtime(&t, &tm, NULL);
 	hour = tm.tm_hour;
 
 	if (!hour)
@@ -6534,7 +6550,8 @@ static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *i
 	struct tm tm;
 	char fn[256];
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 
 	
 	/* W E E K - D A Y */
@@ -7024,7 +7041,8 @@ static int ast_say_time_ge(struct ast_channel *chan, time_t t, const char *ints,
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 
 	res = ast_say_number(chan, tm.tm_hour, ints, lang, (char*)NULL);
 	if (!res) {
@@ -7054,7 +7072,8 @@ static int ast_say_datetime_ge(struct ast_channel *chan, time_t t, const char *i
 {
 	struct tm tm;
 	int res = 0;
-	localtime_r(&t,&tm);
+
+	ast_localtime(&t, &tm, NULL);
 	res = ast_say_date(chan, t, ints, lang);
 	if (!res)
 		ast_say_time(chan, t, ints, lang);
@@ -7077,8 +7096,8 @@ static int ast_say_datetime_from_now_ge(struct ast_channel *chan, time_t t, cons
 
 	time(&nowt);
 
-	localtime_r(&t,&tm);
-	localtime_r(&nowt,&now);
+	ast_localtime(&t, &tm, NULL);
+	ast_localtime(&nowt, &now, NULL);
 	daydiff = now.tm_yday - tm.tm_yday;
 	if ((daydiff < 0) || (daydiff > 6)) {
 		/* Day of month and month */
diff --git a/main/stdtime/localtime.c b/main/stdtime/localtime.c
index e54f2affd69d84bb626649f1b4b9a83683f1b326..18cd3d7d8a83aa86c8f6576297a80ecdda234275 100644
--- a/main/stdtime/localtime.c
+++ b/main/stdtime/localtime.c
@@ -1217,7 +1217,7 @@ const time_t * const	timep;
 char *buf;
 {
         struct tm tm;
-	return asctime_r(localtime_r(timep, &tm), buf);
+	return asctime_r(ast_localtime(timep, &tm, NULL), buf);
 }
 
 /*