Skip to content

Commit aa8a3de

Browse files
committed
Merge remote-tracking branch 'remotes/DanielCortez/__timestamp' into dev
2 parents c97aa00 + 263625d commit aa8a3de

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

source/compiler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ if(BUILD_TESTING)
176176
../amx/amxaux.h
177177
../amx/amxcons.c
178178
../amx/amxcore.c
179+
../amx/amxstring.c
179180
)
180181
if(UNIX)
181182
set(PAWNRUNS_SRCS

source/compiler/pawnruns.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static void PrintUsage(char *program)
2727
int main(int argc,char *argv[])
2828
{
2929
extern AMX_NATIVE_INFO console_Natives[];
30+
extern AMX_NATIVE_INFO string_Natives[];
3031
extern AMX_NATIVE_INFO core_Natives[];
3132

3233
AMX amx;
@@ -41,6 +42,7 @@ int main(int argc,char *argv[])
4142
ErrorExit(&amx, err);
4243

4344
amx_Register(&amx, console_Natives, -1);
45+
amx_Register(&amx, string_Natives, -1);
4446
err = amx_Register(&amx, core_Natives, -1);
4547
if (err != AMX_ERR_NONE)
4648
ErrorExit(&amx, err);

source/compiler/sc1.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static int sc_reparse = 0; /* needs 3th parse because of changed prototypes
166166
static int sc_parsenum = 0; /* number of the extra parses */
167167
static int wq[wqTABSZ]; /* "while queue", internal stack for nested loops */
168168
static int *wqptr; /* pointer to next entry */
169+
static time_t now; /* current timestamp, for built-in constants "__time" and "__timestamp" */
169170
#if !defined SC_LIGHT
170171
static char sc_rootpath[_MAX_PATH];
171172
static char *sc_documentation=NULL;/* main documentation */
@@ -1554,6 +1555,8 @@ static void usage(void)
15541555
static void setconstants(void)
15551556
{
15561557
int debug;
1558+
time_t loctime;
1559+
struct tm loctm,utctm;
15571560

15581561
assert(sc_status==statIDLE);
15591562
append_constval(&tagname_tab,"_",0,0);/* "untagged" */
@@ -1601,6 +1604,13 @@ static void setconstants(void)
16011604
line_sym=add_builtin_constant("__line",0,sGLOBAL,0);
16021605
add_builtin_constant("__compat",pc_compat,sGLOBAL,0);
16031606

1607+
now=time(NULL);
1608+
loctm=*localtime(&now);
1609+
utctm=*gmtime(&now);
1610+
loctime=now+(loctm.tm_sec-utctm.tm_sec)+(loctm.tm_min-utctm.tm_min)*60
1611+
+(loctm.tm_hour-utctm.tm_hour)*60*60+(loctm.tm_mday-utctm.tm_mday)*60*60*24;
1612+
add_builtin_constant("__timestamp",(cell)loctime,sGLOBAL,0);
1613+
16041614
debug=0;
16051615
if ((sc_debug & (sCHKBOUNDS | sSYMBOLIC))==(sCHKBOUNDS | sSYMBOLIC))
16061616
debug=2;
@@ -1613,14 +1623,12 @@ static void setconstants(void)
16131623

16141624
static void setstringconstants()
16151625
{
1616-
time_t now;
16171626
char timebuf[arraysize("11:22:33")];
16181627
char datebuf[arraysize("10 Jan 2017")];
16191628

16201629
assert(sc_status!=statIDLE);
16211630
add_builtin_string_constant("__file","",sGLOBAL);
16221631

1623-
now = time(NULL);
16241632
strftime(timebuf,arraysize(timebuf),"%H:%M:%S",localtime(&now));
16251633
add_builtin_string_constant("__time",timebuf,sGLOBAL);
16261634
strftime(datebuf,arraysize(datebuf),"%d %b %Y",localtime(&now));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'test_type': 'runtime',
3+
'output': """
4+
result: 0
5+
__timestamp.amx returns 0
6+
""",
7+
'should_fail': False
8+
}

source/compiler/tests/__timestamp.pwn

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <console>
2+
#include <string>
3+
4+
main()
5+
{
6+
new day_seconds = __timestamp % (60 * 60 * 24);
7+
new hour = day_seconds / (60 * 60);
8+
new minute = (day_seconds % (60 * 60)) / 60;
9+
new second = day_seconds % 60;
10+
new buf[9];
11+
strformat(buf, _, _, "%02d:%02d:%02d", hour, minute, second);
12+
printf("result: %d\n", strcmp(buf, __time));
13+
}

0 commit comments

Comments
 (0)