Adjusted script command gettimestr (#2329)

* Fixes #2328.
* Added an optional parameter to pass in a Unix tick value to convert to a readable format.
Thanks to @hendra814 and @Lemongrass3110!
This commit is contained in:
Aleos 2017-08-14 13:51:18 -04:00 committed by GitHub
parent 74d809d139
commit 7554b53d68
2 changed files with 26 additions and 12 deletions

View File

@ -3019,10 +3019,10 @@ It will only return numbers. If another type is supplied -1 will be returned.
---------------------------------------
*gettimestr(<format string>,<max length>)
*gettimestr(<"time format">,<max length>{,<time_tick>})
This function will return a string containing time data as specified by the
format string.
time format.
This uses the C function 'strfmtime', which obeys special format characters. For
a full description see, for example, the description of 'strfmtime' at
@ -3034,7 +3034,11 @@ The example given in rAthena sample scripts works like this:
mes gettimestr("%Y-%m/%d %H:%M:%S",21);
This will print a full date and time like 'YYYY-MM/DD HH:MM:SS'.
The example above will print the current date and time like 'YYYY-MM/DD HH:MM:SS'.
The following example will print the date and time when the player's VIP status
expires by the given <time_tick>:
mes gettimestr("%Y-%m/%d %H:%M:%S",21,vip_status(VIP_STATUS_EXPIRE));
---------------------------------------

View File

@ -9945,22 +9945,32 @@ BUILDIN_FUNC(gettime)
return SCRIPT_CMD_SUCCESS;
}
/*==========================================
* GetTimeStr("TimeFMT", Length);
*------------------------------------------*/
/**
* Returns the current server time or the provided time in a readable format.
* gettimestr(<"time_format">,<max_length>{,<time_tick>});
*/
BUILDIN_FUNC(gettimestr)
{
char *tmpstr;
const char *fmtstr;
int maxlen;
time_t now = time(NULL);
time_t now;
fmtstr=script_getstr(st,2);
maxlen=script_getnum(st,3);
fmtstr = script_getstr(st,2);
maxlen = script_getnum(st,3);
tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char));
if (script_hasdata(st, 4)) {
if (script_getnum(st, 4) < 0) {
ShowWarning("buildin_gettimestr: a positive value must be supplied to be valid.\n");
return SCRIPT_CMD_FAILURE;
} else
now = (time_t)script_getnum(st, 4);
} else
now = time(NULL);
tmpstr = (char *)aMalloc((maxlen+1)*sizeof(char));
strftime(tmpstr,maxlen,fmtstr,localtime(&now));
tmpstr[maxlen]='\0';
tmpstr[maxlen] = '\0';
script_pushstr(st,tmpstr);
return SCRIPT_CMD_SUCCESS;
@ -23692,7 +23702,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(savepoint,"sii???"),
BUILDIN_DEF(gettimetick,"i"),
BUILDIN_DEF(gettime,"i"),
BUILDIN_DEF(gettimestr,"si"),
BUILDIN_DEF(gettimestr,"si?"),
BUILDIN_DEF(openstorage,""),
BUILDIN_DEF(guildopenstorage,""),
BUILDIN_DEF(itemskill,"vi?"),