MakeTime.js 758 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var $isFinite = require('../helpers/isFinite');
  3. var timeConstants = require('../helpers/timeConstants');
  4. var msPerSecond = timeConstants.msPerSecond;
  5. var msPerMinute = timeConstants.msPerMinute;
  6. var msPerHour = timeConstants.msPerHour;
  7. var ToIntegerOrInfinity = require('./ToIntegerOrInfinity');
  8. // https://262.ecma-international.org/12.0/#sec-maketime
  9. module.exports = function MakeTime(hour, min, sec, ms) {
  10. if (!$isFinite(hour) || !$isFinite(min) || !$isFinite(sec) || !$isFinite(ms)) {
  11. return NaN;
  12. }
  13. var h = ToIntegerOrInfinity(hour);
  14. var m = ToIntegerOrInfinity(min);
  15. var s = ToIntegerOrInfinity(sec);
  16. var milli = ToIntegerOrInfinity(ms);
  17. var t = (h * msPerHour) + (m * msPerMinute) + (s * msPerSecond) + milli;
  18. return t;
  19. };