mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
34 lines
917 B
JavaScript
34 lines
917 B
JavaScript
|
'use strict';
|
||
|
|
||
|
var GetIntrinsic = require('get-intrinsic');
|
||
|
|
||
|
var $DateUTC = GetIntrinsic('%Date.UTC%');
|
||
|
|
||
|
var $isFinite = require('../helpers/isFinite');
|
||
|
|
||
|
var DateFromTime = require('./DateFromTime');
|
||
|
var Day = require('./Day');
|
||
|
var floor = require('./floor');
|
||
|
var modulo = require('./modulo');
|
||
|
var MonthFromTime = require('./MonthFromTime');
|
||
|
var ToInteger = require('./ToInteger');
|
||
|
var YearFromTime = require('./YearFromTime');
|
||
|
|
||
|
// https://262.ecma-international.org/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 = modulo(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;
|
||
|
};
|