source: imaps-frontend/node_modules/es-abstract/2024/TimeZoneString.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.9 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $Date = GetIntrinsic('%Date%');
6var $TypeError = require('es-errors/type');
7var callBound = require('call-bound');
8var isInteger = require('math-intrinsics/isInteger');
9
10var $indexOf = callBound('String.prototype.indexOf');
11var $slice = callBound('String.prototype.slice');
12var $toTimeString = callBound('Date.prototype.toTimeString');
13
14// https://262.ecma-international.org/14.0/#sec-timezoneestring
15
16module.exports = function TimeZoneString(tv) {
17 if (!isInteger(tv)) {
18 throw new $TypeError('Assertion failed: `tv` must be an integral Number');
19 }
20
21 // 1. Let localTimeZone be DefaultTimeZone().
22 // 2. If IsTimeZoneOffsetString(localTimeZone) is true, then
23 // a. Let offsetNs be ParseTimeZoneOffsetString(localTimeZone).
24 // 3. Else,
25 // a. Let offsetNs be GetNamedTimeZoneOffsetNanoseconds(localTimeZone, ℤ(ℝ(tv) × 106)).
26 // 4. Let offset be 𝔽(truncate(offsetNs / 106)).
27 // 5. If offset is +0𝔽 or offset > +0𝔽, then
28 // a. Let offsetSign be "+".
29 // b. Let absOffset be offset.
30 // 6. Else,
31 // a. Let offsetSign be "-".
32 // b. Let absOffset be -offset.
33 // 7. Let offsetMin be ToZeroPaddedDecimalString(ℝ(MinFromTime(absOffset)), 2).
34 // 8. Let offsetHour be ToZeroPaddedDecimalString(ℝ(HourFromTime(absOffset)), 2).
35 // 9. Let tzName be an implementation-defined string that is either the empty String or the string-concatenation of the code unit 0x0020 (SPACE), the code unit 0x0028 (LEFT PARENTHESIS), an implementation-defined timezone name, and the code unit 0x0029 (RIGHT PARENTHESIS).
36 // 10. Return the string-concatenation of offsetSign, offsetHour, offsetMin, and tzName.
37
38 // hack until DefaultTimeZone, IsTimeZoneOffsetString, ParseTimeZoneOffsetString, GetNamedTimeZoneOffsetNanoseconds, and "implementation-defined string" are available
39 var ts = $toTimeString(new $Date(tv));
40 return $slice(ts, $indexOf(ts, '(') + 1, $indexOf(ts, ')'));
41};
Note: See TracBrowser for help on using the repository browser.