mirror of
https://github.com/colanode/colanode.git
synced 2025-12-16 03:37:51 +01:00
Fix date picker date conversion (#243)
This commit is contained in:
@@ -95,13 +95,6 @@ export const isSameDay = (
|
|||||||
return d1.getDate() === d2.getDate() && d1.getMonth() === d2.getMonth();
|
return d1.getDate() === d2.getDate() && d1.getMonth() === d2.getMonth();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const toUTCDate = (dateParam: Date | string): Date => {
|
|
||||||
const date = typeof dateParam === 'string' ? new Date(dateParam) : dateParam;
|
|
||||||
return new Date(
|
|
||||||
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isStringArray = (
|
export const isStringArray = (
|
||||||
value: unknown | null | undefined
|
value: unknown | null | undefined
|
||||||
): value is string[] => {
|
): value is string[] => {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { DayPicker, DayProps, getDefaultClassNames } from 'react-day-picker';
|
|||||||
import {
|
import {
|
||||||
FieldAttributes,
|
FieldAttributes,
|
||||||
isSameDay,
|
isSameDay,
|
||||||
toUTCDate,
|
|
||||||
DatabaseViewFilterAttributes,
|
DatabaseViewFilterAttributes,
|
||||||
} from '@colanode/core';
|
} from '@colanode/core';
|
||||||
import { CalendarViewDay } from '@colanode/ui/components/databases/calendars/calendar-view-day';
|
import { CalendarViewDay } from '@colanode/ui/components/databases/calendars/calendar-view-day';
|
||||||
@@ -184,7 +183,7 @@ export const CalendarViewGrid = ({ field }: CalendarViewGridProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<CalendarViewDay
|
<CalendarViewDay
|
||||||
date={toUTCDate(props.day.date)}
|
date={props.day.date}
|
||||||
records={dayRecords}
|
records={dayRecords}
|
||||||
onCreate={onCreate}
|
onCreate={onCreate}
|
||||||
isOutside={props.day.outside}
|
isOutside={props.day.outside}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { toUTCDate } from '@colanode/core';
|
|
||||||
import { Calendar } from '@colanode/ui/components/ui/calendar';
|
import { Calendar } from '@colanode/ui/components/ui/calendar';
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
@@ -17,6 +16,26 @@ interface DatePickerProps {
|
|||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toUTCDate = (dateParam: Date | string): Date => {
|
||||||
|
const date = typeof dateParam === 'string' ? new Date(dateParam) : dateParam;
|
||||||
|
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = date.getMonth();
|
||||||
|
const day = date.getDate();
|
||||||
|
|
||||||
|
return new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
|
||||||
|
};
|
||||||
|
|
||||||
|
const fromUTCDate = (dateParam: Date | string): Date => {
|
||||||
|
const date = typeof dateParam === 'string' ? new Date(dateParam) : dateParam;
|
||||||
|
|
||||||
|
const year = date.getUTCFullYear();
|
||||||
|
const month = date.getUTCMonth();
|
||||||
|
const day = date.getUTCDate();
|
||||||
|
|
||||||
|
return new Date(year, month, day, 0, 0, 0, 0);
|
||||||
|
};
|
||||||
|
|
||||||
export const DatePicker = ({
|
export const DatePicker = ({
|
||||||
value,
|
value,
|
||||||
className,
|
className,
|
||||||
@@ -25,7 +44,7 @@ export const DatePicker = ({
|
|||||||
readonly,
|
readonly,
|
||||||
}: DatePickerProps) => {
|
}: DatePickerProps) => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const dateObj = value ? new Date(value) : undefined;
|
const dateObj = value ? fromUTCDate(value) : undefined;
|
||||||
const placeHolderText = placeholder ?? '';
|
const placeHolderText = placeholder ?? '';
|
||||||
|
|
||||||
if (readonly) {
|
if (readonly) {
|
||||||
@@ -58,7 +77,7 @@ export const DatePicker = ({
|
|||||||
onChange(toUTCDate(date));
|
onChange(toUTCDate(date));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
initialFocus
|
autoFocus={true}
|
||||||
/>
|
/>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|||||||
Reference in New Issue
Block a user