GetNamedTimeZoneEpochNanoseconds.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var GetUTCEpochNanoseconds = require('./GetUTCEpochNanoseconds');
  4. var isInteger = require('math-intrinsics/isInteger');
  5. // https://262.ecma-international.org/14.0/#sec-getnamedtimezoneepochnanoseconds
  6. // eslint-disable-next-line max-params
  7. module.exports = function GetNamedTimeZoneEpochNanoseconds(
  8. timeZoneIdentifier,
  9. year,
  10. month,
  11. day,
  12. hour,
  13. minute,
  14. second,
  15. millisecond,
  16. microsecond,
  17. nanosecond
  18. ) {
  19. if (typeof timeZoneIdentifier !== 'string') {
  20. throw new $TypeError('Assertion failed: `timeZoneIdentifier` must be a string');
  21. }
  22. if (!isInteger(year)) {
  23. throw new $TypeError('Assertion failed: `year` must be an integral number');
  24. }
  25. if (!isInteger(month) || month < 1 || month > 12) {
  26. throw new $TypeError('Assertion failed: `month` must be an integral number between 1 and 12, inclusive');
  27. }
  28. if (!isInteger(day) || day < 1 || day > 31) {
  29. throw new $TypeError('Assertion failed: `day` must be an integral number between 1 and 31, inclusive');
  30. }
  31. if (!isInteger(hour) || hour < 0 || hour > 23) {
  32. throw new $TypeError('Assertion failed: `hour` must be an integral number between 0 and 23, inclusive');
  33. }
  34. if (!isInteger(minute) || minute < 0 || minute > 59) {
  35. throw new $TypeError('Assertion failed: `minute` must be an integral number between 0 and 59, inclusive');
  36. }
  37. if (!isInteger(second) || second < 0 || second > 999) {
  38. throw new $TypeError('Assertion failed: `second` must be an integral number between 0 and 999, inclusive');
  39. }
  40. if (!isInteger(millisecond) || millisecond < 0 || millisecond > 999) {
  41. throw new $TypeError('Assertion failed: `millisecond` must be an integral number between 0 and 999, inclusive');
  42. }
  43. if (!isInteger(microsecond) || microsecond < 0 || microsecond > 999) {
  44. throw new $TypeError('Assertion failed: `microsecond` must be an integral number between 0 and 999, inclusive');
  45. }
  46. if (!isInteger(nanosecond) || nanosecond < 0 || nanosecond > 999) {
  47. throw new $TypeError('Assertion failed: `nanosecond` must be an integral number between 0 and 999, inclusive');
  48. }
  49. if (timeZoneIdentifier !== 'UTC') {
  50. throw new $TypeError('Assertion failed: only UTC time zone is supported'); // step 1
  51. }
  52. var epochNanoseconds = GetUTCEpochNanoseconds(
  53. year,
  54. month,
  55. day,
  56. hour,
  57. minute,
  58. second,
  59. millisecond,
  60. microsecond,
  61. nanosecond
  62. ); // step 2
  63. return [epochNanoseconds]; // step 3
  64. };