TimeString.js 731 B

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