Skip to content

Commit

Permalink
Removed week start day and added overwrite distance
Browse files Browse the repository at this point in the history
  • Loading branch information
reinzor committed Jan 6, 2021
1 parent 31bf313 commit e59b5a0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/components/DataSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@input="fetchData()"
:value-as-date="true"
v-model="from"
:start-weekday="globalOptions.startWeekDay"
:start-weekday="1"
:hide-header="true"
>
</b-form-datepicker>
Expand Down
6 changes: 0 additions & 6 deletions src/components/GlobalOptionsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
<template #modal-title>
<b-icon icon="gear-fill" variant="primary" aria-hidden="true"></b-icon> Global options
</template>
<label for="start-weekday" class="mt-2">Week starts at:</label>
<b-form-select
id="start-weekday"
v-model="globalOptions.startWeekDay"
:options="globalOptions.startWeekDayOptions"
></b-form-select>
<label for="group-mode" class="mt-2">Group mode:</label>
<b-form-select
id="group-mode"
Expand Down
25 changes: 20 additions & 5 deletions src/components/MileageTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@
</b-form-group>
</b-form>
<b-row>
<b-col><multiselect v-model="fromNames" :multiple="true" :options="nameOptions"></multiselect></b-col>
<b-col><multiselect v-model="toNames" :multiple="true" :options="nameOptions"></multiselect></b-col>
<b-col><b-form-checkbox v-model="wayBack">Way back</b-form-checkbox></b-col>
<b-col sm="4"><multiselect v-model="fromNames" :multiple="true" :options="nameOptions"></multiselect></b-col>
<b-col sm="4"><multiselect v-model="toNames" :multiple="true" :options="nameOptions"></multiselect></b-col>
<b-col sm="2" style="margin-top: -2px">
<b-form-checkbox v-model="wayBack">
<small class="text-muted">Way back</small>
</b-form-checkbox>
<b-form-checkbox v-model="overwriteDistance">
<small class="text-muted">Overwrite distance</small>
</b-form-checkbox>
</b-col>
<b-col sm="2" v-if="overwriteDistance">
<b-input-group append="km">
<b-form-input v-model.number="overwrittenDistance" type="number"></b-form-input>
</b-input-group>
</b-col>
</b-row>
</b-card-body>
<data-table :data="mileageData" />
Expand All @@ -37,7 +49,8 @@ function show(fromNames, toNames, from, to, wayBack) {
const Types = {
DRIVING: 'Driving',
WALKING: 'Walking'
WALKING: 'Walking',
CYCLING: 'Cycling'
}
export default {
Expand All @@ -51,6 +64,8 @@ export default {
fromNames: [],
toNames: [],
wayBack: false,
overwriteDistance: false,
overwrittenDistance: 0,
fields: [
{ key: 'name', sortable: true },
{ key: 'timeBegin', sortable: true },
Expand All @@ -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
})
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/services/global_options.js
Original file line number Diff line number Diff line change
@@ -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']

Expand Down
27 changes: 10 additions & 17 deletions src/util/date.js
Original file line number Diff line number Diff line change
@@ -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))
}
Expand All @@ -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 }

0 comments on commit e59b5a0

Please sign in to comment.