summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-04-07 20:27:22 +0200
committerGitHub <noreply@github.com>2019-04-07 20:27:22 +0200
commit73dacb74a8d2ed52590a6d6b8b937d9e14f77d8e (patch)
tree9aee364596b3d53f88dda7d465ec1fc7f84aeb9f /src
parented5a86ed44b19d1e4c203f78c7bf2551442d2319 (diff)
parentb478fb0a7373af0d80912641fbe08e9cbb49464e (diff)
downloadhercules-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')
-rw-r--r--src/map/script.c32
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?"),