summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnnieRuru <jeankofannie2@gmail.com>2019-03-23 23:27:05 +0800
committerAnnieRuru <jeankofannie2@gmail.com>2019-03-23 23:27:05 +0800
commitae5a425420e3cafd1a9887f02ba60f972cb85ede (patch)
tree7a6346a81d1096c07a7547016444c51721fb7b64
parente1e951c805916853e55ff5b9ce0531e0cf483ebf (diff)
downloadhercules-ae5a425420e3cafd1a9887f02ba60f972cb85ede.tar.gz
hercules-ae5a425420e3cafd1a9887f02ba60f972cb85ede.tar.bz2
hercules-ae5a425420e3cafd1a9887f02ba60f972cb85ede.tar.xz
hercules-ae5a425420e3cafd1a9887f02ba60f972cb85ede.zip
Add optional parameter for *gettimestr
-rw-r--r--doc/script_commands.txt3
-rw-r--r--src/map/script.c16
2 files changed, 16 insertions, 3 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 19f189f81..c99f27206 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3531,7 +3531,7 @@ Examples :
---------------------------------------
-*gettimestr(<format string>, <max length>)
+*gettimestr(<format string>, <max length>{, <timestamp>})
This function will return a string containing time data as specified by
the format string.
@@ -3545,6 +3545,7 @@ Max length is the maximum length of a time string to generate.
The example given in Hercules sample scripts works like this:
mes(gettimestr("%Y-%m/%d %H:%M:%S", 21));
+ mes(gettimestr("%Y-%m/%d %H:%M:%S", 21, getcalendartime(0, 0)));
This will print a full date and time like 'YYYY-MM/DD HH:MM:SS'.
diff --git a/src/map/script.c b/src/map/script.c
index bba559df8..aeaf851b1 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10612,11 +10612,23 @@ 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);
+ 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';
@@ -25378,7 +25390,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?"),