diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 9d5df1faca..d89bb0a889 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3019,10 +3019,10 @@ It will only return numbers. If another type is supplied -1 will be returned. --------------------------------------- -*gettimestr(,) +*gettimestr(<"time format">,{,}) 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 : + + mes gettimestr("%Y-%m/%d %H:%M:%S",21,vip_status(VIP_STATUS_EXPIRE)); --------------------------------------- diff --git a/src/map/script.c b/src/map/script.c index 31013b6797..2d2146c123 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -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">,{,}); + */ 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?"),