Skip to content

Commit

Permalink
[js] Implement nqp::decodelocaltime
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jan 12, 2019
1 parent a803c8a commit 9393f57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vm/js/Operations.nqp
Expand Up @@ -1932,6 +1932,8 @@ class QAST::OperationsJS {
add_simple_op('writenum', $T_VOID, [$T_OBJ, $T_INT, $T_NUM, $T_INT], :side_effects);
add_simple_op('readnum', $T_NUM, [$T_OBJ, $T_INT, $T_INT]);

add_simple_op('decodelocaltime', $T_OBJ, [$T_INT], :side_effects);

method add_hll_unbox($hll, $type, $method_name) {
unless nqp::existskey(%hll_unbox, $hll) {
%hll_unbox{$hll} := nqp::hash();
Expand Down
13 changes: 13 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -2213,3 +2213,16 @@ op.setjsattr = function(ctx, obj, attr, value) {
op.getjsattr = function(ctx, obj, attr) {
return fromJSToObject(ctx, obj.$$jsObject[attr]);
};

op.decodelocaltime = function(sinceEpoch) {
let date = new Date(sinceEpoch * 1000);

return BOOT.createIntArray([
date.getSeconds(),
date.getMinutes(),
date.getHours(),
date.getDate(),
date.getMonth()+1,
date.getFullYear()
]);
};

0 comments on commit 9393f57

Please sign in to comment.