TimeString.js 818 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var $isNaN = require('../helpers/isNaN');
  4. var HourFromTime = require('./HourFromTime');
  5. var MinFromTime = require('./MinFromTime');
  6. var SecFromTime = require('./SecFromTime');
  7. var ToZeroPaddedDecimalString = require('./ToZeroPaddedDecimalString');
  8. // https://262.ecma-international.org/13.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 = ToZeroPaddedDecimalString(HourFromTime(tv), 2); // step 1
  14. var minute = ToZeroPaddedDecimalString(MinFromTime(tv), 2); // step 2
  15. var second = ToZeroPaddedDecimalString(SecFromTime(tv), 2); // step 3
  16. return hour + ':' + minute + ':' + second + ' GMT'; // step 4
  17. };