add better support for timezones

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-05-02 21:16:31 +02:00
parent cff7822f12
commit 33e92a0da0
9 changed files with 152 additions and 189 deletions

View File

@@ -2,6 +2,7 @@
import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
import { TimeWindowPicker } from '@/components/time-window-picker';
import { endOfDay, formatISO, startOfDay } from 'date-fns';
export function OverviewReportRange() {
const { range, setRange, setStartDate, setEndDate, endDate, startDate } =
@@ -11,8 +12,14 @@ export function OverviewReportRange() {
<TimeWindowPicker
onChange={setRange}
value={range}
onStartDateChange={(date) => setStartDate(date)}
onEndDateChange={(date) => setEndDate(date)}
onStartDateChange={(date) => {
const d = formatISO(startOfDay(new Date(date)));
setStartDate(d);
}}
onEndDateChange={(date) => {
const d = formatISO(endOfDay(new Date(date)));
setEndDate(d);
}}
endDate={endDate}
startDate={startDate}
/>

View File

@@ -1,3 +0,0 @@
import FullPageLoadingState from '@/components/full-page-loading-state';
export default FullPageLoadingState;

View File

@@ -1,6 +1,12 @@
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
import { isSameDay, isSameMonth } from 'date-fns';
import {
endOfDay,
formatISO,
isSameDay,
isSameMonth,
startOfDay,
} from 'date-fns';
import {
alphabetIds,
@@ -188,8 +194,8 @@ export const reportSlice = createSlice({
}>
) => {
state.dirty = true;
state.startDate = action.payload.startDate;
state.endDate = action.payload.endDate;
state.startDate = formatISO(startOfDay(action.payload.startDate));
state.endDate = formatISO(endOfDay(action.payload.endDate));
if (isSameDay(state.startDate, state.endDate)) {
state.interval = 'hour';
@@ -203,7 +209,7 @@ export const reportSlice = createSlice({
// Date range
changeStartDate: (state, action: PayloadAction<string>) => {
state.dirty = true;
state.startDate = action.payload;
state.startDate = formatISO(startOfDay(action.payload));
const interval = getDefaultIntervalByDates(
state.startDate,
@@ -217,7 +223,7 @@ export const reportSlice = createSlice({
// Date range
changeEndDate: (state, action: PayloadAction<string>) => {
state.dirty = true;
state.endDate = action.payload;
state.endDate = formatISO(endOfDay(action.payload));
const interval = getDefaultIntervalByDates(
state.startDate,