TimeClip.js 468 B

123456789101112131415161718192021
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $Date = GetIntrinsic('%Date%');
  4. var $Number = GetIntrinsic('%Number%');
  5. var $isFinite = require('../helpers/isFinite');
  6. var abs = require('./abs');
  7. var ToNumber = require('./ToNumber');
  8. // https://262.ecma-international.org/5.1/#sec-15.9.1.14
  9. module.exports = function TimeClip(time) {
  10. if (!$isFinite(time) || abs(time) > 8.64e15) {
  11. return NaN;
  12. }
  13. return $Number(new $Date(ToNumber(time)));
  14. };