main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1007 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $DateUTC = GetIntrinsic('%Date.UTC%');
|
---|
6 |
|
---|
7 | var $isFinite = require('../helpers/isFinite');
|
---|
8 |
|
---|
9 | var DateFromTime = require('./DateFromTime');
|
---|
10 | var Day = require('./Day');
|
---|
11 | var floor = require('./floor');
|
---|
12 | var modulo = require('./modulo');
|
---|
13 | var MonthFromTime = require('./MonthFromTime');
|
---|
14 | var ToIntegerOrInfinity = require('./ToIntegerOrInfinity');
|
---|
15 | var YearFromTime = require('./YearFromTime');
|
---|
16 |
|
---|
17 | // https://262.ecma-international.org/5.1/#sec-15.9.1.12
|
---|
18 |
|
---|
19 | module.exports = function MakeDay(year, month, date) {
|
---|
20 | if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) {
|
---|
21 | return NaN;
|
---|
22 | }
|
---|
23 | var y = ToIntegerOrInfinity(year);
|
---|
24 | var m = ToIntegerOrInfinity(month);
|
---|
25 | var dt = ToIntegerOrInfinity(date);
|
---|
26 | var ym = y + floor(m / 12);
|
---|
27 | if (!$isFinite(ym)) {
|
---|
28 | return NaN;
|
---|
29 | }
|
---|
30 | var mn = modulo(m, 12);
|
---|
31 | var t = $DateUTC(ym, mn, 1);
|
---|
32 | if (YearFromTime(t) !== ym || MonthFromTime(t) !== mn || DateFromTime(t) !== 1) {
|
---|
33 | return NaN;
|
---|
34 | }
|
---|
35 | return Day(t) + dt - 1;
|
---|
36 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.