1 | var staticStrFirst = require('./staticStrFirst')
|
2 | var staticStrLast = require('./staticStrLast')
|
3 |
|
4 | var helperGetDateFullYear = require('./helperGetDateFullYear')
|
5 |
|
6 | var getWhatMonth = require('./getWhatMonth')
|
7 | var toStringDate = require('./toStringDate')
|
8 | var isValidDate = require('./isValidDate')
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function getWhatYear (date, offset, month) {
|
19 | var number
|
20 | date = toStringDate(date)
|
21 | if (isValidDate(date)) {
|
22 | if (offset) {
|
23 | number = offset && !isNaN(offset) ? offset : 0
|
24 | date.setFullYear(helperGetDateFullYear(date) + number)
|
25 | }
|
26 | if (month || !isNaN(month)) {
|
27 | if (month === staticStrFirst) {
|
28 | return new Date(helperGetDateFullYear(date), 0, 1)
|
29 | } else if (month === staticStrLast) {
|
30 | date.setMonth(11)
|
31 | return getWhatMonth(date, 0, staticStrLast)
|
32 | } else {
|
33 | date.setMonth(month)
|
34 | }
|
35 | }
|
36 | }
|
37 | return date
|
38 | }
|
39 |
|
40 | module.exports = getWhatYear
|