forked from ground/ground
first version of datetime lib
This commit is contained in:
12
libs/datetime/time_functions.c
Normal file
12
libs/datetime/time_functions.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "time_functions.h"
|
||||
|
||||
GroundValue datetime_NowEpoch(GroundScope* scope, List args) {
|
||||
// grab time from system clock
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
|
||||
// convert it to secs and return it
|
||||
double secsSinceEpoch = (double)ts.tv_sec + (double)ts.tv_nsec / 1e9;
|
||||
|
||||
return groundCreateValue(DOUBLE, secsSinceEpoch);
|
||||
}
|
||||
Reference in New Issue
Block a user