source: imaps-frontend/node_modules/es-abstract/2021/TimeZoneString.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $Date = GetIntrinsic('%Date%');
6var $TypeError = require('es-errors/type');
7
8var isNaN = require('../helpers/isNaN');
9
10var callBound = require('call-bind/callBound');
11
12var $indexOf = callBound('String.prototype.indexOf');
13var $slice = callBound('String.prototype.slice');
14var $toTimeString = callBound('Date.prototype.toTimeString');
15
16// https://262.ecma-international.org/12.0/#sec-timezoneestring
17
18module.exports = function TimeZoneString(tv) {
19 if (typeof tv !== 'number' || isNaN(tv)) {
20 throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number'); // steps 1 - 2
21 }
22
23 // 3. Let offset be LocalTZA(tv, true).
24 // 4. If offset ≥ +0𝔽, then
25 // a. Let offsetSign be "+".
26 // b. Let absOffset be offset.
27 // 5. Else,
28 // a. Let offsetSign be "-".
29 // b. Let absOffset be -offset.
30 // 6. Let offsetMin be the String representation of MinFromTime(absOffset), formatted as a two-digit decimal number, padded to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.
31 // 7. Let offsetHour be the String representation of HourFromTime(absOffset), formatted as a two-digit decimal number, padded to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.
32 // 8. 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).
33 // 9. Return the string-concatenation of offsetSign, offsetHour, offsetMin, and tzName.
34
35 // hack until LocalTZA, and "implementation-defined string" are available
36 var ts = $toTimeString(new $Date(tv));
37 return $slice(ts, $indexOf(ts, '(') + 1, $indexOf(ts, ')'));
38};
Note: See TracBrowser for help on using the repository browser.