securityos/node_modules/es-abstract/2022/TimeString.js

27 lines
818 B
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
'use strict';
var $TypeError = require('es-errors/type');
var $isNaN = require('../helpers/isNaN');
var HourFromTime = require('./HourFromTime');
var MinFromTime = require('./MinFromTime');
var SecFromTime = require('./SecFromTime');
var ToZeroPaddedDecimalString = require('./ToZeroPaddedDecimalString');
// https://262.ecma-international.org/13.0/#sec-timestring
module.exports = function TimeString(tv) {
if (typeof tv !== 'number' || $isNaN(tv)) {
throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number');
}
var hour = ToZeroPaddedDecimalString(HourFromTime(tv), 2); // step 1
var minute = ToZeroPaddedDecimalString(MinFromTime(tv), 2); // step 2
var second = ToZeroPaddedDecimalString(SecFromTime(tv), 2); // step 3
return hour + ':' + minute + ':' + second + ' GMT'; // step 4
};