|
25 | 25 | @change="(periodLength) => setDate(date, periodLength)") |
26 | 26 | div.p-1(v-if="periodLength === 'day'") |
27 | 27 | input.form-control(id="date" type="date" :value="date" :max="today" |
28 | | - @change="setDate($event.target.value)") |
| 28 | + @change="setDate($event.target.value, periodLength)") |
29 | 29 |
|
30 | 30 | div.p-1.ml-auto |
31 | 31 | b-button-group |
@@ -180,19 +180,7 @@ export default { |
180 | 180 | return moment(this.timeperiod.start).format(this.dateformat); |
181 | 181 | }, |
182 | 182 | periodLengthMoment: function() { |
183 | | - if (this.periodLength === 'day') { |
184 | | - return 'day'; |
185 | | - } else if (this.periodLength === 'week') { |
186 | | - /* This is necessary so the week starts on Monday instead of Sunday */ |
187 | | - return 'isoWeek'; |
188 | | - } else if (this.periodLength === 'month') { |
189 | | - return 'month'; |
190 | | - } else if (this.periodLength === 'year') { |
191 | | - return 'year'; |
192 | | - } else { |
193 | | - console.error('Invalid periodLength ${this.periodLength}, defaulting to "day"'); |
194 | | - return 'day'; |
195 | | - } |
| 183 | + return this.periodLengthConvertMoment(this.periodLength); |
196 | 184 | }, |
197 | 185 | }, |
198 | 186 | watch: { |
@@ -220,10 +208,27 @@ export default { |
220 | 208 | .add(1, `${this.periodLength}s`) |
221 | 209 | .format('YYYY-MM-DD'); |
222 | 210 | }, |
| 211 | + periodLengthConvertMoment(periodLength) { |
| 212 | + if (periodLength === 'day') { |
| 213 | + return 'day'; |
| 214 | + } else if (periodLength === 'week') { |
| 215 | + /* This is necessary so the week starts on Monday instead of Sunday */ |
| 216 | + return 'isoWeek'; |
| 217 | + } else if (periodLength === 'month') { |
| 218 | + return 'month'; |
| 219 | + } else if (periodLength === 'year') { |
| 220 | + return 'year'; |
| 221 | + } else { |
| 222 | + console.error('Invalid periodLength ${periodLength}, defaulting to "day"'); |
| 223 | + return 'day'; |
| 224 | + } |
| 225 | + }, |
223 | 226 | setDate: function(date, periodLength) { |
| 227 | + const new_period_length_moment = this.periodLengthConvertMoment(periodLength); |
224 | 228 | const new_date = moment(date) |
225 | | - .startOf(this.periodLengthMoment) |
| 229 | + .startOf(new_period_length_moment) |
226 | 230 | .format('YYYY-MM-DD'); |
| 231 | + console.log(new_date, periodLength); |
227 | 232 | this.$router.push(`/activity/${this.host}/${periodLength}/${new_date}`); |
228 | 233 | }, |
229 | 234 |
|
|
0 commit comments