source: frontend/node_modules/es-abstract/2023/GetUTCEpochNanoseconds.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.5 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var MakeDay = require('./MakeDay');
6var MakeTime = require('./MakeTime');
7var MakeDate = require('./MakeDate');
8
9var isInteger = require('math-intrinsics/isInteger');
10
11var $BigInt = GetIntrinsic('%BigInt%', true);
12var $SyntaxError = GetIntrinsic('%SyntaxError%');
13var $TypeError = GetIntrinsic('%TypeError%');
14
15// https://tc39.es/ecma262/#sec-getutcepochnanoseconds
16
17// eslint-disable-next-line max-params
18module.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};
Note: See TracBrowser for help on using the repository browser.