1 | var staticDayTime = require('./staticDayTime')
|
2 | var staticWeekTime = require('./staticWeekTime')
|
3 | var staticParseInt = require('./staticParseInt')
|
4 |
|
5 | var helperGetDateTime = require('./helperGetDateTime')
|
6 |
|
7 | var toStringDate = require('./toStringDate')
|
8 |
|
9 | var isValidDate = require('./isValidDate')
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function getWhatWeek (date, offset, day) {
|
20 | var time, whatDayTime, currentDay, customDay
|
21 | date = toStringDate(date)
|
22 | if (isValidDate(date)) {
|
23 | customDay = staticParseInt(/^[0-7]$/.test(day) ? day : date.getDay())
|
24 | currentDay = date.getDay()
|
25 | time = helperGetDateTime(date)
|
26 | whatDayTime = time + ((customDay === 0 ? 7 : customDay) - (currentDay === 0 ? 7 : currentDay)) * staticDayTime
|
27 | if (offset && !isNaN(offset)) {
|
28 | whatDayTime += offset * staticWeekTime
|
29 | }
|
30 | return new Date(whatDayTime)
|
31 | }
|
32 | return date
|
33 | }
|
34 |
|
35 | module.exports = getWhatWeek
|