Skip to content

Commit 268cde8

Browse files
committed
Add API to build Date objects
1 parent 0bbb78c commit 268cde8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

quickjs.c

+9
Original file line numberDiff line numberDiff line change
@@ -46868,6 +46868,15 @@ static const JSCFunctionListEntry js_date_proto_funcs[] = {
4686846868
JS_CFUNC_DEF("toJSON", 1, js_date_toJSON ),
4686946869
};
4687046870

46871+
JSValue JS_NewDate(JSContext *ctx, double epoch_ms)
46872+
{
46873+
JSValue obj = js_create_from_ctor(ctx, JS_UNDEFINED, JS_CLASS_DATE);
46874+
if (JS_IsException(obj))
46875+
return JS_EXCEPTION;
46876+
JS_SetObjectData(ctx, obj, JS_NewFloat64(ctx, time_clip(epoch_ms)));
46877+
return obj;
46878+
}
46879+
4687146880
void JS_AddIntrinsicDate(JSContext *ctx)
4687246881
{
4687346882
JSValueConst obj;

quickjs.h

+2
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,8 @@ JS_BOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, JS_BOOL val)
676676
JSValue JS_NewArray(JSContext *ctx);
677677
int JS_IsArray(JSContext *ctx, JSValueConst val);
678678

679+
JSValue JS_NewDate(JSContext *ctx, double epoch_ms);
680+
679681
JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
680682
JSAtom prop, JSValueConst receiver,
681683
JS_BOOL throw_ref_error);

0 commit comments

Comments
 (0)