Skip to content

Commit 041477b

Browse files
author
Irfan Maulana
committed
default preset should have i18n param
1 parent dfb76b2 commit 041477b

File tree

1 file changed

+62
-60
lines changed

1 file changed

+62
-60
lines changed

src/js/rangedate-picker.js

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,69 +46,71 @@ const defaultStyle = {
4646
presetRanges: 'calendar_preset-ranges'
4747
}
4848

49-
const defaultPresets = {
50-
today: function () {
51-
const n = new Date()
52-
const startToday = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1, 0, 0)
53-
const endToday = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1, 23, 59)
54-
return {
55-
label: presetRangeLabel[this.i18n].today,
56-
active: false,
57-
dateRange: {
58-
start: startToday,
59-
end: endToday
49+
const defaultPresets = function (i18n) {
50+
return {
51+
today: function () {
52+
const n = new Date()
53+
const startToday = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1, 0, 0)
54+
const endToday = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1, 23, 59)
55+
return {
56+
label: presetRangeLabel[i18n].today,
57+
active: false,
58+
dateRange: {
59+
start: startToday,
60+
end: endToday
61+
}
6062
}
61-
}
62-
},
63-
thisMonth: function () {
64-
const n = new Date()
65-
const startMonth = new Date(n.getFullYear(), n.getMonth(), 2)
66-
const endMonth = new Date(n.getFullYear(), n.getMonth() + 1, 1)
67-
return {
68-
label: presetRangeLabel[this.i18n].thisMonth,
69-
active: false,
70-
dateRange: {
71-
start: startMonth,
72-
end: endMonth
63+
},
64+
thisMonth: function () {
65+
const n = new Date()
66+
const startMonth = new Date(n.getFullYear(), n.getMonth(), 2)
67+
const endMonth = new Date(n.getFullYear(), n.getMonth() + 1, 1)
68+
return {
69+
label: presetRangeLabel[i18n].thisMonth,
70+
active: false,
71+
dateRange: {
72+
start: startMonth,
73+
end: endMonth
74+
}
7375
}
74-
}
75-
},
76-
lastMonth: function () {
77-
const n = new Date()
78-
const startMonth = new Date(n.getFullYear(), n.getMonth() - 1, 2)
79-
const endMonth = new Date(n.getFullYear(), n.getMonth(), 1)
80-
return {
81-
label: presetRangeLabel[this.i18n].lastMonth,
82-
active: false,
83-
dateRange: {
84-
start: startMonth,
85-
end: endMonth
76+
},
77+
lastMonth: function () {
78+
const n = new Date()
79+
const startMonth = new Date(n.getFullYear(), n.getMonth() - 1, 2)
80+
const endMonth = new Date(n.getFullYear(), n.getMonth(), 1)
81+
return {
82+
label: presetRangeLabel[i18n].lastMonth,
83+
active: false,
84+
dateRange: {
85+
start: startMonth,
86+
end: endMonth
87+
}
8688
}
87-
}
88-
},
89-
last7days: function () {
90-
const n = new Date()
91-
const start = new Date(n.getFullYear(), n.getMonth(), n.getDate() - 5)
92-
const end = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1)
93-
return {
94-
label: presetRangeLabel[this.i18n].lastSevenDays,
95-
active: false,
96-
dateRange: {
97-
start: start,
98-
end: end
89+
},
90+
last7days: function () {
91+
const n = new Date()
92+
const start = new Date(n.getFullYear(), n.getMonth(), n.getDate() - 5)
93+
const end = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1)
94+
return {
95+
label: presetRangeLabel[i18n].lastSevenDays,
96+
active: false,
97+
dateRange: {
98+
start: start,
99+
end: end
100+
}
99101
}
100-
}
101-
},
102-
last30days: function () {
103-
const n = new Date()
104-
const start = new Date(n.getFullYear(), n.getMonth(), n.getDate() - 29)
105-
const end = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1)
106-
return {
107-
label: presetRangeLabel[this.i18n].lastThirtyDays,
108-
active: false,
109-
dateRange: {
110-
start: start,
111-
end: end
102+
},
103+
last30days: function () {
104+
const n = new Date()
105+
const start = new Date(n.getFullYear(), n.getMonth(), n.getDate() - 29)
106+
const end = new Date(n.getFullYear(), n.getMonth(), n.getDate() + 1)
107+
return {
108+
label: presetRangeLabel[i18n].lastThirtyDays,
109+
active: false,
110+
dateRange: {
111+
start: start,
112+
end: end
113+
}
112114
}
113115
}
114116
}
@@ -159,7 +161,7 @@ export default {
159161
},
160162
presetRanges: {
161163
type: Object,
162-
default: () => defaultPresets
164+
default: () => defaultPresets(this.i18n)
163165
},
164166
compact: {
165167
type: String,

0 commit comments

Comments
 (0)