2020-08-25 23:57:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
2021-02-26 03:58:33 +00:00
|
|
|
var GetIntrinsic = require('get-intrinsic');
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
var $DateUTC = GetIntrinsic('%Date.UTC%');
|
|
|
|
|
|
|
|
var $isFinite = require('../helpers/isFinite');
|
|
|
|
|
|
|
|
var DateFromTime = require('./DateFromTime');
|
|
|
|
var Day = require('./Day');
|
2021-02-26 03:58:33 +00:00
|
|
|
var floor = require('./floor');
|
|
|
|
var modulo = require('./modulo');
|
2020-08-25 23:57:08 +00:00
|
|
|
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);
|
2021-02-26 03:58:33 +00:00
|
|
|
var ym = y + floor(m / 12);
|
|
|
|
var mn = modulo(m, 12);
|
2020-08-25 23:57:08 +00:00
|
|
|
var t = $DateUTC(ym, mn, 1);
|
|
|
|
if (YearFromTime(t) !== ym || MonthFromTime(t) !== mn || DateFromTime(t) !== 1) {
|
|
|
|
return NaN;
|
|
|
|
}
|
|
|
|
return Day(t) + dt - 1;
|
|
|
|
};
|