From 6dee32900784b1e65258f37ec1cee988a8d24d48 Mon Sep 17 00:00:00 2001 From: komashchenko Date: Mon, 29 Oct 2018 23:53:59 +0200 Subject: [PATCH 1/3] Feature Request: FormatTime() and time correcting #875 --- core/logic/smn_core.cpp | 3 ++- plugins/include/sourcemod.inc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index 611d026b24..bdb7f4b570 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -202,7 +202,8 @@ static cell_t FormatTime(IPluginContext *pContext, const cell_t *params) #endif time_t t = (params[4] == -1) ? g_pSM->GetAdjustedTime() : (time_t)params[4]; - size_t written = strftime(buffer, params[2], format, localtime(&t)); + struct tm *tm_t = (params[0] > 4 && params[5] == 0) ? gmtime(&t) : localtime(&t); + size_t written = strftime(buffer, params[2], format, tm_t); #if defined SUBPLATFORM_SECURECRT _set_invalid_parameter_handler(handler); diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index ca5b993f4c..97ccd5e6e2 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -375,9 +375,10 @@ native int GetTime(int bigStamp[2]={0,0}); * @param maxlength Maximum length of output string buffer. * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format). * @param stamp Optional time stamp. + * @param localtime Requires use OS timezone settings. * @error Buffer too small or invalid time format. */ -native void FormatTime(char[] buffer, int maxlength, const char[] format, int stamp=-1); +native void FormatTime(char[] buffer, int maxlength, const char[] format, int stamp=-1, bool localtime = true); /** * Loads a game config file. From 18fc25501f2f3a1a061f05367d180ce0b9d63e4b Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 13 Nov 2018 19:00:39 +0200 Subject: [PATCH 2/3] Update description Co-Authored-By: komashchenko --- plugins/include/sourcemod.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 97ccd5e6e2..6d4a277743 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -375,7 +375,7 @@ native int GetTime(int bigStamp[2]={0,0}); * @param maxlength Maximum length of output string buffer. * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format). * @param stamp Optional time stamp. - * @param localtime Requires use OS timezone settings. + * @param localtime Use OS timezone. * @error Buffer too small or invalid time format. */ native void FormatTime(char[] buffer, int maxlength, const char[] format, int stamp=-1, bool localtime = true); From 9bb01c41f7230b8bfa75f63a40e4d3f3b8455a9f Mon Sep 17 00:00:00 2001 From: komashchenko Date: Tue, 13 Nov 2018 19:15:18 +0200 Subject: [PATCH 3/3] Fix sm_time_adjustment --- core/logic/smn_core.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index bdb7f4b570..0229b81a30 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -200,11 +200,31 @@ static cell_t FormatTime(IPluginContext *pContext, const cell_t *params) #if defined SUBPLATFORM_SECURECRT _invalid_parameter_handler handler = _set_invalid_parameter_handler(_ignore_invalid_parameter); #endif - - time_t t = (params[4] == -1) ? g_pSM->GetAdjustedTime() : (time_t)params[4]; - struct tm *tm_t = (params[0] > 4 && params[5] == 0) ? gmtime(&t) : localtime(&t); + + struct tm *tm_t; + time_t t = (time_t)params[4]; + + if(params[0] > 4 && params[5] == 0) + { + if(params[4] == -1) + { + t = time(NULL); + } + + tm_t = gmtime(&t); + } + else + { + if(params[4] == -1) + { + t = g_pSM->GetAdjustedTime(); + } + + tm_t = localtime(&t); + } + size_t written = strftime(buffer, params[2], format, tm_t); - + #if defined SUBPLATFORM_SECURECRT _set_invalid_parameter_handler(handler); #endif