-
Notifications
You must be signed in to change notification settings - Fork 680
Question: How to handle Date object in native C? #4058
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hello @weixiongmei ! Unfortunately, currently we do not have any API functions to handle date objects. Moreover I can suggest you two better solutions:
B:
typedef enum
{
JERRY_DATE_OPERATION_GET_YEAR,
JERRY_DATE_OPERATION_GET_MONTH,
// ... and so on
} jerry_date_operation_t;
jerry_value_t
jerry_date_get (jerry_date_operation_t operation, jerry_value_t value)
{
// step 1: validate date object
// step 2: get the internal date
ecma_number_t date_num = get_the_stored_internal_date_value() // see ecma_builtin_date_prototype_dispatch_routine
ecma_number_t result;
// step 3: choose the operation
switch (operation) {
case JERRY_DATE_OPERATION_GET_YEAR: {
result = ecma_date_year_from_time (date_num);
break;
}
case JERRY_DATE_OPERATION_GET_MONTH: {
result = ecma_date_month_from_time (date_num);
break;
}
// ... and so on
}
return ecma_make_number_value (result);
} Both options are suitable for resolve your problem, but IMHO the option B would be more future-proof also much efficient as well. |
@rerobika Thank you so much~~ |
Hi, I'm having hard time to figure out how to get the Date.year, month, date in the native C code. Also having hard time to figure out how to return a Date object from native to javascript. Thanks
Javascript
Native C
The text was updated successfully, but these errors were encountered: