From e59b5a0605f53c1f7ec7205f61cb47a8715eedc1 Mon Sep 17 00:00:00 2001 From: Rein Appeldoorn Date: Wed, 6 Jan 2021 19:26:56 +0100 Subject: [PATCH] Removed week start day and added overwrite distance --- src/components/DataSelection.vue | 2 +- src/components/GlobalOptionsModal.vue | 6 ------ src/components/MileageTable.vue | 25 ++++++++++++++++++++----- src/services/global_options.js | 5 ----- src/util/date.js | 27 ++++++++++----------------- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/components/DataSelection.vue b/src/components/DataSelection.vue index 20318c2..e43939a 100644 --- a/src/components/DataSelection.vue +++ b/src/components/DataSelection.vue @@ -12,7 +12,7 @@ @input="fetchData()" :value-as-date="true" v-model="from" - :start-weekday="globalOptions.startWeekDay" + :start-weekday="1" :hide-header="true" > diff --git a/src/components/GlobalOptionsModal.vue b/src/components/GlobalOptionsModal.vue index 4092f95..caa73c5 100644 --- a/src/components/GlobalOptionsModal.vue +++ b/src/components/GlobalOptionsModal.vue @@ -3,12 +3,6 @@ - - - - - Way back + + + + + Way back + + + Overwrite distance + + + + + + + @@ -37,7 +49,8 @@ function show(fromNames, toNames, from, to, wayBack) { const Types = { DRIVING: 'Driving', - WALKING: 'Walking' + WALKING: 'Walking', + CYCLING: 'Cycling' } export default { @@ -51,6 +64,8 @@ export default { fromNames: [], toNames: [], wayBack: false, + overwriteDistance: false, + overwrittenDistance: 0, fields: [ { key: 'name', sortable: true }, { key: 'timeBegin', sortable: true }, @@ -77,7 +92,7 @@ export default { duration: item.duration, timeBegin: item.timeBegin, timeEnd: item.timeEnd, - distance: item.distance + distance: this.overwriteDistance ? this.overwrittenDistance * 1e3 : item.distance }) } } diff --git a/src/services/global_options.js b/src/services/global_options.js index e0230ab..964092f 100644 --- a/src/services/global_options.js +++ b/src/services/global_options.js @@ -1,10 +1,5 @@ class Globaloptions { constructor() { - this.startWeekDay = 1 - this.startWeekDayOptions = [ - { value: 0, text: 'Sunday' }, - { value: 1, text: 'Monday' } - ] this.groupMode = 'None' this.groupModeOptions = ['None', 'Week', 'Month'] diff --git a/src/util/date.js b/src/util/date.js index a144b8a..31fa1da 100644 --- a/src/util/date.js +++ b/src/util/date.js @@ -1,22 +1,14 @@ -import globalOptions from '../services/global_options' - function getFirstDayOfWeek(date) { const d = new Date(date) const day = d.getDay() - let first = d.getDate() - day - if (globalOptions.startWeekDay === 1) { - first += day === 0 ? -6 : 1 - } + const first = d.getDate() - day + (day === 0 ? -6 : 1) return new Date(d.setDate(first)) } function getLastDayOfWeek(date) { const d = new Date(date) const day = d.getDay() - let first = d.getDate() - day - if (globalOptions.startWeekDay === 1) { - first += day === 0 ? -6 : 1 - } + const first = d.getDate() - day + (day === 0 ? -6 : 1) const last = first + 6 return new Date(d.setDate(last)) } @@ -30,14 +22,15 @@ function getLastDayOfMonth(date) { } function getWeekNumber(date) { - date = getFirstDayOfWeek(date) - const firstDayOfYear = new Date(date.getFullYear(), 0, 1) - const pastDaysOfYear = (date - firstDayOfYear) / 86400000 - let day = firstDayOfYear.getDay() - if (globalOptions.startWeekDay === 0) { - day += day === 0 ? -6 : 1 + var tdt = new Date(date.valueOf()) + var dayn = (date.getDay() + 6) % 7 + tdt.setDate(tdt.getDate() - dayn + 3) + var firstThursday = tdt.valueOf() + tdt.setMonth(0, 1) + if (tdt.getDay() !== 4) { + tdt.setMonth(0, 1 + ((4 - tdt.getDay() + 7) % 7)) } - return Math.ceil((pastDaysOfYear + day) / 7) + return 1 + Math.ceil((firstThursday - tdt) / 604800000) } export { getFirstDayOfWeek, getLastDayOfWeek, getFirstDayOfMonth, getLastDayOfMonth, getWeekNumber }