diff options
author | Haru <haru@dotalux.com> | 2019-04-07 20:27:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-07 20:27:22 +0200 |
commit | 73dacb74a8d2ed52590a6d6b8b937d9e14f77d8e (patch) | |
tree | 9aee364596b3d53f88dda7d465ec1fc7f84aeb9f /src/map/script.c | |
parent | ed5a86ed44b19d1e4c203f78c7bf2551442d2319 (diff) | |
parent | b478fb0a7373af0d80912641fbe08e9cbb49464e (diff) | |
download | hercules-73dacb74a8d2ed52590a6d6b8b937d9e14f77d8e.tar.gz hercules-73dacb74a8d2ed52590a6d6b8b937d9e14f77d8e.tar.bz2 hercules-73dacb74a8d2ed52590a6d6b8b937d9e14f77d8e.tar.xz hercules-73dacb74a8d2ed52590a6d6b8b937d9e14f77d8e.zip |
Merge pull request #2388 from AnnieRuru/61-gettimestr
Add optional parameter for *gettimestr
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/map/script.c b/src/map/script.c index 348efae6f..3b99c16f0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10604,24 +10604,36 @@ static BUILDIN(gettime) return true; } -/*========================================== +/* * GetTimeStr("TimeFMT", Length); - *------------------------------------------*/ + */ static BUILDIN(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); + if (script_hasdata(st, 4)) { + int timestamp = script_getnum(st, 4); + if (timestamp < 0) { + ShowWarning("buildin_gettimestr: UNIX timestamp must be in positive value.\n"); + return false; + } + + now = (time_t)timestamp; + } else { + now = time(NULL); + } - tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char)); - strftime(tmpstr,maxlen,fmtstr,localtime(&now)); - tmpstr[maxlen]='\0'; + tmpstr = (char *)aMalloc((maxlen +1)*sizeof(char)); + strftime(tmpstr, maxlen, fmtstr, localtime(&now)); + tmpstr[maxlen] = '\0'; - script_pushstr(st,tmpstr); + script_pushstr(st, tmpstr); return true; } @@ -25379,7 +25391,7 @@ static void script_parse_builtin(void) 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?"), |