improve fscript_date_time

This commit is contained in:
lixianjing 2021-01-08 17:35:25 +08:00
parent 8235764919
commit b8bcd8d725
2 changed files with 22 additions and 1 deletions

View File

@ -15,6 +15,7 @@
*/
#include "tkc/fscript.h"
#include "tkc/time_now.h"
#include "tkc/object_date_time.h"
static ret_t func_date_time_create(fscript_t* fscript, fscript_args_t* args, value_t* result) {
@ -67,11 +68,29 @@ static ret_t func_date_time_set(fscript_t* fscript, fscript_args_t* args, value_
return RET_OK;
}
static ret_t func_time_now_us(fscript_t* fscript, fscript_args_t* args, value_t* result) {
value_set_uint64(result, time_now_us());
return RET_OK;
}
static ret_t func_time_now_ms(fscript_t* fscript, fscript_args_t* args, value_t* result) {
value_set_uint64(result, time_now_ms());
return RET_OK;
}
static ret_t func_time_now_s(fscript_t* fscript, fscript_args_t* args, value_t* result) {
value_set_uint64(result, time_now_s());
return RET_OK;
}
ret_t fscript_date_time_register(void) {
ENSURE(fscript_register_func("date_time_create", func_date_time_create) == RET_OK);
ENSURE(fscript_register_func("date_time_to_time", func_date_time_to_time) == RET_OK);
ENSURE(fscript_register_func("date_time_from_time", func_date_time_from_time) == RET_OK);
ENSURE(fscript_register_func("date_time_set", func_date_time_set) == RET_OK);
ENSURE(fscript_register_func("time_now_us", func_time_now_us) == RET_OK);
ENSURE(fscript_register_func("time_now_ms", func_time_now_ms) == RET_OK);
ENSURE(fscript_register_func("time_now_s", func_time_now_s) == RET_OK);
return RET_OK;
}

View File

@ -25,6 +25,8 @@ assert(dt.hour == 2)
assert(dt.minute == 3)
assert(dt.second == 5)
print(time_now_us())
print(time_now_ms())
print(time_now_s())