1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = sub;
|
7 |
|
8 | var _index = _interopRequireDefault(require("../subDays/index.js"));
|
9 |
|
10 | var _index2 = _interopRequireDefault(require("../subMonths/index.js"));
|
11 |
|
12 | var _index3 = _interopRequireDefault(require("../toDate/index.js"));
|
13 |
|
14 | var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
|
15 |
|
16 | var _index5 = _interopRequireDefault(require("../_lib/toInteger/index.js"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | function sub(dirtyDate, duration) {
|
60 | (0, _index4.default)(2, arguments);
|
61 | if (!duration || typeof duration !== 'object') return new Date(NaN);
|
62 | var years = 'years' in duration ? (0, _index5.default)(duration.years) : 0;
|
63 | var months = 'months' in duration ? (0, _index5.default)(duration.months) : 0;
|
64 | var weeks = 'weeks' in duration ? (0, _index5.default)(duration.weeks) : 0;
|
65 | var days = 'days' in duration ? (0, _index5.default)(duration.days) : 0;
|
66 | var hours = 'hours' in duration ? (0, _index5.default)(duration.hours) : 0;
|
67 | var minutes = 'minutes' in duration ? (0, _index5.default)(duration.minutes) : 0;
|
68 | var seconds = 'seconds' in duration ? (0, _index5.default)(duration.seconds) : 0;
|
69 |
|
70 | var dateWithoutMonths = (0, _index2.default)((0, _index3.default)(dirtyDate), months + years * 12);
|
71 |
|
72 | var dateWithoutDays = (0, _index.default)(dateWithoutMonths, days + weeks * 7);
|
73 |
|
74 | var minutestoSub = minutes + hours * 60;
|
75 | var secondstoSub = seconds + minutestoSub * 60;
|
76 | var mstoSub = secondstoSub * 1000;
|
77 | var finalDate = new Date(dateWithoutDays.getTime() - mstoSub);
|
78 | return finalDate;
|
79 | }
|
80 |
|
81 | module.exports = exports.default; |
\ | No newline at end of file |