TimeString.js 808 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var $isNaN = require('../helpers/isNaN');
  5. var padTimeComponent = require('../helpers/padTimeComponent');
  6. var HourFromTime = require('./HourFromTime');
  7. var MinFromTime = require('./MinFromTime');
  8. var SecFromTime = require('./SecFromTime');
  9. var Type = require('./Type');
  10. // https://262.ecma-international.org/9.0/#sec-timestring
  11. module.exports = function TimeString(tv) {
  12. if (Type(tv) !== 'Number' || $isNaN(tv)) {
  13. throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number');
  14. }
  15. var hour = HourFromTime(tv);
  16. var minute = MinFromTime(tv);
  17. var second = SecFromTime(tv);
  18. return padTimeComponent(hour) + ':' + padTimeComponent(minute) + ':' + padTimeComponent(second) + '\x20GMT';
  19. };