-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.js
69 lines (67 loc) · 1.72 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
60
61
62
63
64
65
66
67
68
69
export function createYearObj(userDate, allPoints) {
const userStartYear = userDate.getFullYear()
const userStartMonth = userDate.getMonth()
//console.log('userstartmonth', userStartMonth)
// console.log('user start yer', userStartYear)
const currentYear = new Date().getFullYear()
const currentMonth = new Date().getMonth()
const yearObj = {}
for (let year = userStartYear; year <= currentYear; year++) {
let loopStartMonth
let loopEndMonth
yearObj[year] = []
if (year === userStartYear) {
loopStartMonth = userStartMonth
} else {
loopStartMonth = 0
}
if (year === currentYear) {
loopEndMonth = currentMonth
} else {
loopEndMonth = 11
}
// for (let month = loopStartMonth; month <= loopEndMonth; month++) {
// // const monthName = monthNumToName(month)
// yearObj[year][month] = {month: true}
// }
for (let month = 0; month <= loopEndMonth; month++) {
// const monthName = monthNumToName(month)
if (month >= loopStartMonth) {
yearObj[year][month] = {month: true}
}
if (month < loopStartMonth) {
yearObj[year][month] = {
month: month,
year: year,
goal: 0,
totalEarned: 0
}
}
}
}
// console.log('year obj', yearObj)
// console.log('all points', allPoints)
allPoints.forEach(point => {
// const monthName = monthNumToName(point.month)
yearObj[point.year][point.month] = point
})
console.log(yearObj)
return yearObj
}
export function monthNumToName(monthNum) {
var months = [
'Jan',
'Feb',
'Mar',
'April',
'May',
'June',
'July',
'Aug',
'Sept',
'Oct',
'Nov',
'Dec'
]
return months[monthNum]
}