InLeapYear.js 510 B

123456789101112131415161718192021
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $EvalError = GetIntrinsic('%EvalError%');
  4. var DaysInYear = require('./DaysInYear');
  5. var YearFromTime = require('./YearFromTime');
  6. // https://262.ecma-international.org/5.1/#sec-15.9.1.3
  7. module.exports = function InLeapYear(t) {
  8. var days = DaysInYear(YearFromTime(t));
  9. if (days === 365) {
  10. return 0;
  11. }
  12. if (days === 366) {
  13. return 1;
  14. }
  15. throw new $EvalError('Assertion failed: there are not 365 or 366 days in a year, got: ' + days);
  16. };