Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatTime() and time correcting #875 #917

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions core/logic/smn_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +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];
size_t written = strftime(buffer, params[2], format, 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
Expand Down
3 changes: 2 additions & 1 deletion plugins/include/sourcemod.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 Use OS timezone.
* @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.
Expand Down