Skip to content

Commit 1704d71

Browse files
bugfix: Inconsistency when changing period length
1 parent 353634b commit 1704d71

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/views/activity/Activity.vue

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ div
2525
@change="(periodLength) => setDate(date, periodLength)")
2626
div.p-1(v-if="periodLength === 'day'")
2727
input.form-control(id="date" type="date" :value="date" :max="today"
28-
@change="setDate($event.target.value)")
28+
@change="setDate($event.target.value, periodLength)")
2929

3030
div.p-1.ml-auto
3131
b-button-group
@@ -180,19 +180,7 @@ export default {
180180
return moment(this.timeperiod.start).format(this.dateformat);
181181
},
182182
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);
196184
},
197185
},
198186
watch: {
@@ -220,10 +208,27 @@ export default {
220208
.add(1, `${this.periodLength}s`)
221209
.format('YYYY-MM-DD');
222210
},
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+
},
223226
setDate: function(date, periodLength) {
227+
const new_period_length_moment = this.periodLengthConvertMoment(periodLength);
224228
const new_date = moment(date)
225-
.startOf(this.periodLengthMoment)
229+
.startOf(new_period_length_moment)
226230
.format('YYYY-MM-DD');
231+
console.log(new_date, periodLength);
227232
this.$router.push(`/activity/${this.host}/${periodLength}/${new_date}`);
228233
},
229234

0 commit comments

Comments
 (0)