1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $Date = GetIntrinsic('%Date%');
|
---|
6 | var $TypeError = require('es-errors/type');
|
---|
7 |
|
---|
8 | var isNaN = require('../helpers/isNaN');
|
---|
9 |
|
---|
10 | var callBound = require('call-bind/callBound');
|
---|
11 |
|
---|
12 | var $indexOf = callBound('String.prototype.indexOf');
|
---|
13 | var $slice = callBound('String.prototype.slice');
|
---|
14 | var $toTimeString = callBound('Date.prototype.toTimeString');
|
---|
15 |
|
---|
16 | // https://262.ecma-international.org/9.0/#sec-timezoneestring
|
---|
17 |
|
---|
18 | module.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, let offsetSign be "+"; otherwise, let offsetSign be "-".
|
---|
25 | // 5. Let offsetMin be the String representation of MinFromTime(abs(offset)), formatted as a two-digit decimal number, padded to the left with a zero if necessary.
|
---|
26 | // 6. Let offsetHour be the String representation of HourFromTime(abs(offset)), formatted as a two-digit decimal number, padded to the left with a zero if necessary.
|
---|
27 | // 7. 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-dependent timezone name, and the code unit 0x0029 (RIGHT PARENTHESIS).
|
---|
28 | // 8. Return the string-concatenation of offsetSign, offsetHour, offsetMin, and tzName.
|
---|
29 |
|
---|
30 | // hack until LocalTZA, and "implementation-defined string" are available
|
---|
31 | var ts = $toTimeString(new $Date(tv));
|
---|
32 | return $slice(ts, $indexOf(ts, '(') + 1, $indexOf(ts, ')'));
|
---|
33 | };
|
---|