| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
|---|
| 4 |
|
|---|
| 5 | var MakeDay = require('./MakeDay');
|
|---|
| 6 | var MakeTime = require('./MakeTime');
|
|---|
| 7 | var MakeDate = require('./MakeDate');
|
|---|
| 8 |
|
|---|
| 9 | var isInteger = require('math-intrinsics/isInteger');
|
|---|
| 10 |
|
|---|
| 11 | var $BigInt = GetIntrinsic('%BigInt%', true);
|
|---|
| 12 | var $SyntaxError = GetIntrinsic('%SyntaxError%');
|
|---|
| 13 | var $TypeError = GetIntrinsic('%TypeError%');
|
|---|
| 14 |
|
|---|
| 15 | // https://tc39.es/ecma262/#sec-getutcepochnanoseconds
|
|---|
| 16 |
|
|---|
| 17 | // eslint-disable-next-line max-params
|
|---|
| 18 | module.exports = function GetUTCEpochNanoseconds(
|
|---|
| 19 | year,
|
|---|
| 20 | month,
|
|---|
| 21 | day,
|
|---|
| 22 | hour,
|
|---|
| 23 | minute,
|
|---|
| 24 | second,
|
|---|
| 25 | millisecond,
|
|---|
| 26 | microsecond,
|
|---|
| 27 | nanosecond
|
|---|
| 28 | ) {
|
|---|
| 29 | if (!isInteger(year)) {
|
|---|
| 30 | throw new $TypeError('Assertion failed: `year` must be an integral Number');
|
|---|
| 31 | }
|
|---|
| 32 | if (!isInteger(month) || month < 1 || month > 12) {
|
|---|
| 33 | throw new $TypeError('Assertion failed: `month` must be an integral Number between 1 and 12, inclusive');
|
|---|
| 34 | }
|
|---|
| 35 | if (!isInteger(day) || day < 1 || day > 31) {
|
|---|
| 36 | throw new $TypeError('Assertion failed: `day` must be an integral Number between 1 and 31, inclusive');
|
|---|
| 37 | }
|
|---|
| 38 | if (!isInteger(hour) || hour < 0 || hour > 23) {
|
|---|
| 39 | throw new $TypeError('Assertion failed: `hour` must be an integral Number between 0 and 23, inclusive');
|
|---|
| 40 | }
|
|---|
| 41 | if (!isInteger(minute) || minute < 0 || minute > 59) {
|
|---|
| 42 | throw new $TypeError('Assertion failed: `minute` must be an integral Number between 0 and 59, inclusive');
|
|---|
| 43 | }
|
|---|
| 44 | if (!isInteger(second) || second < 0 || second > 59) {
|
|---|
| 45 | throw new $TypeError('Assertion failed: `second` must be an integral Number between 0 and 59, inclusive');
|
|---|
| 46 | }
|
|---|
| 47 | if (!isInteger(millisecond) || millisecond < 0 || millisecond > 999) {
|
|---|
| 48 | throw new $TypeError('Assertion failed: `millisecond` must be an integral Number between 0 and 999, inclusive');
|
|---|
| 49 | }
|
|---|
| 50 | if (!isInteger(microsecond) || microsecond < 0 || microsecond > 999) {
|
|---|
| 51 | throw new $TypeError('Assertion failed: `microsecond` must be an integral Number between 0 and 999, inclusive');
|
|---|
| 52 | }
|
|---|
| 53 | if (!isInteger(nanosecond) || nanosecond < 0 || nanosecond > 999) {
|
|---|
| 54 | throw new $TypeError('Assertion failed: `nanosecond` must be an integral Number between 0 and 999, inclusive');
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | var date = MakeDay(year, month - 1, day); // step 1
|
|---|
| 58 | var time = MakeTime(hour, minute, second, millisecond); // step 2
|
|---|
| 59 | var ms = MakeDate(date, time); // step 3
|
|---|
| 60 | if (!isInteger(ms)) {
|
|---|
| 61 | throw new $TypeError('Assertion failed: `ms` from MakeDate is not an integral Number'); // step 4
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | if (!$BigInt) {
|
|---|
| 65 | throw new $SyntaxError('BigInts are not supported in this environment');
|
|---|
| 66 | }
|
|---|
| 67 | return $BigInt((ms * 1e6) + (microsecond * 1e3) + nanosecond); // step 5
|
|---|
| 68 | };
|
|---|