Projekt

Obecné

Profil

Stáhnout (1.02 KB) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
var GetIntrinsic = require('../GetIntrinsic');
4

    
5
var $EvalError = GetIntrinsic('%EvalError%');
6

    
7
var DayWithinYear = require('./DayWithinYear');
8
var InLeapYear = require('./InLeapYear');
9
var MonthFromTime = require('./MonthFromTime');
10

    
11
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.5
12

    
13
module.exports = function DateFromTime(t) {
14
	var m = MonthFromTime(t);
15
	var d = DayWithinYear(t);
16
	if (m === 0) {
17
		return d + 1;
18
	}
19
	if (m === 1) {
20
		return d - 30;
21
	}
22
	var leap = InLeapYear(t);
23
	if (m === 2) {
24
		return d - 58 - leap;
25
	}
26
	if (m === 3) {
27
		return d - 89 - leap;
28
	}
29
	if (m === 4) {
30
		return d - 119 - leap;
31
	}
32
	if (m === 5) {
33
		return d - 150 - leap;
34
	}
35
	if (m === 6) {
36
		return d - 180 - leap;
37
	}
38
	if (m === 7) {
39
		return d - 211 - leap;
40
	}
41
	if (m === 8) {
42
		return d - 242 - leap;
43
	}
44
	if (m === 9) {
45
		return d - 272 - leap;
46
	}
47
	if (m === 10) {
48
		return d - 303 - leap;
49
	}
50
	if (m === 11) {
51
		return d - 333 - leap;
52
	}
53
	throw new $EvalError('Assertion failed: MonthFromTime returned an impossible value: ' + m);
54
};
(13-13/109)