dockerized_openAger/nodered/rootfs/data/node_modules/es-abstract/2017/DateFromTime.js

55 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2020-10-17 16:42:50 +00:00
'use strict';
var GetIntrinsic = require('../GetIntrinsic');
var $EvalError = GetIntrinsic('%EvalError%');
var DayWithinYear = require('./DayWithinYear');
var InLeapYear = require('./InLeapYear');
var MonthFromTime = require('./MonthFromTime');
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.5
module.exports = function DateFromTime(t) {
var m = MonthFromTime(t);
var d = DayWithinYear(t);
if (m === 0) {
return d + 1;
}
if (m === 1) {
return d - 30;
}
var leap = InLeapYear(t);
if (m === 2) {
return d - 58 - leap;
}
if (m === 3) {
return d - 89 - leap;
}
if (m === 4) {
return d - 119 - leap;
}
if (m === 5) {
return d - 150 - leap;
}
if (m === 6) {
return d - 180 - leap;
}
if (m === 7) {
return d - 211 - leap;
}
if (m === 8) {
return d - 242 - leap;
}
if (m === 9) {
return d - 272 - leap;
}
if (m === 10) {
return d - 303 - leap;
}
if (m === 11) {
return d - 333 - leap;
}
throw new $EvalError('Assertion failed: MonthFromTime returned an impossible value: ' + m);
};