Browse Source

fix bug with editing goal with custom dates.

main
Gisle Aune 3 years ago
parent
commit
b89535e055
  1. 6
      svelte-ui/src/components/DateRangeSelect.svelte
  2. 20
      svelte-ui/src/utils/date-range.ts

6
svelte-ui/src/components/DateRangeSelect.svelte

@ -1,5 +1,5 @@
<script lang="ts">
import { allOffsets, pastOffsets, customDateRange } from "../utils/date-range";
import { allOffsets, pastOffsets, CustomDateRange } from "../utils/date-range";
import type { DateRange } from "../utils/date-range";
import { formatFormTime } from "../utils/time";
@ -11,12 +11,12 @@
let rangeOptions: DateRange[];
let selected = value.name;
let [customMin, customMax] = pastOffsets[0].calculate(new Date()).map(d => formatFormTime(d));
let [customMin, customMax] = (value || pastOffsets[0]).calculate(new Date()).map(d => formatFormTime(d));
$: rangeOptions = noFuture ? pastOffsets : allOffsets;
$: {
if (selected === "Specific Dates") {
value = customDateRange(new Date(customMin), new Date(customMax))
value = new CustomDateRange(new Date(customMin), new Date(customMax))
} else {
value = rangeOptions.find(v => v.name === selected);
if (value != null) {

20
svelte-ui/src/utils/date-range.ts

@ -52,8 +52,22 @@ export class RelativeDateRange {
}
}
export function customDateRange(from: Date, to: Date): DateRange {
return {name: "Specific Dates", calculate: () => [from, to]}
export class CustomDateRange {
private from: Date;
private to: Date;
constructor(from: Date, to: Date) {
this.from = from;
this.to = to;
}
get name() {
return "Specific Dates"
}
calculate(_: Date): [Date, Date] {
return [this.from, this.to];
}
}
const thisWeek = dateRangeCallback("This week", date => [startOfWeek(date), endOfWeek(date)]);
@ -96,7 +110,7 @@ export function rangeFromDates(from: Date, to: Date, options: DateRange[]): Date
}
}
return customDateRange(from, to);
return new CustomDateRange(from, to);
}
export const pastOffsets: DateRange[] = allOffsets.filter(r => !r.name.startsWith("Next"));
Loading…
Cancel
Save