1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 22:33:17 +00:00
musix-oss/node_modules/es-abstract/2017/MakeDay.js

34 lines
936 B
JavaScript
Raw Normal View History

2020-03-03 20:30:50 +00:00
'use strict';
var GetIntrinsic = require('../GetIntrinsic');
var $floor = GetIntrinsic('%Math.floor%');
var $DateUTC = GetIntrinsic('%Date.UTC%');
var mod = require('../helpers/mod');
var $isFinite = require('../helpers/isFinite');
var DateFromTime = require('./DateFromTime');
var Day = require('./Day');
var MonthFromTime = require('./MonthFromTime');
var ToInteger = require('./ToInteger');
var YearFromTime = require('./YearFromTime');
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.12
module.exports = function MakeDay(year, month, date) {
if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) {
return NaN;
}
var y = ToInteger(year);
var m = ToInteger(month);
var dt = ToInteger(date);
var ym = y + $floor(m / 12);
var mn = mod(m, 12);
var t = $DateUTC(ym, mn, 1);
if (YearFromTime(t) !== ym || MonthFromTime(t) !== mn || DateFromTime(t) !== 1) {
return NaN;
}
return Day(t) + dt - 1;
};