Skip to content

Commit 07a8af7

Browse files
committed
WIP
1 parent ab6c9c8 commit 07a8af7

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed

packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/DateTimeFieldInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export const DateTimeFieldInput = () => {
6565
value={dateValue}
6666
clearable
6767
onChange={handleChange}
68-
isDateTimeInput
6968
onClear={handleClear}
7069
onSubmit={handleSubmit}
7170
/>

packages/twenty-front/src/modules/ui/field/input/components/DateTimeInput.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export type DateTimeInputProps = {
2222
) => void;
2323
clearable?: boolean;
2424
onChange?: (newDateTime: Nullable<Date>) => void;
25-
isDateTimeInput?: boolean;
2625
onClear?: () => void;
2726
onSubmit?: (newDateTime: Nullable<Date>) => void;
2827
hideHeaderInput?: boolean;
@@ -36,7 +35,6 @@ export const DateTimeInput = ({
3635
onClickOutside,
3736
clearable,
3837
onChange,
39-
isDateTimeInput,
4038
onClear,
4139
onSubmit,
4240
hideHeaderInput,

packages/twenty-front/src/modules/ui/input/components/internal/date/components/DateTimePicker.tsx

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,27 @@ export const DateTimePicker = ({
351351
}: DateTimePickerProps) => {
352352
const internalDate = date ?? new Date();
353353

354+
const dateWithoutTime = new Date(
355+
internalDate.getUTCFullYear(),
356+
internalDate.getUTCMonth(),
357+
internalDate.getUTCDate(),
358+
0,
359+
0,
360+
0,
361+
0,
362+
);
363+
364+
console.log({
365+
date,
366+
});
367+
354368
const theme = useTheme();
355369

356370
const { closeDropdown: closeDropdownMonthSelect } = useCloseDropdown();
357371
const { closeDropdown: closeDropdownYearSelect } = useCloseDropdown();
372+
358373
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
374+
359375
const handleClear = () => {
360376
closeDropdowns();
361377
onClear?.();
@@ -372,78 +388,73 @@ export const DateTimePicker = ({
372388
};
373389

374390
const handleChangeMonth = (month: number) => {
375-
const newDate = new Date(internalDate);
391+
const newDate = new Date(dateWithoutTime);
376392
newDate.setMonth(month);
377393
onChange?.(newDate);
378394
};
379395

380396
const handleAddMonth = () => {
381-
const dateParsed = addMonths(internalDate, 1);
397+
const dateParsed = addMonths(dateWithoutTime, 1);
382398
onChange?.(dateParsed);
383399
};
384400

385401
const handleSubtractMonth = () => {
386-
const dateParsed = subMonths(internalDate, 1);
402+
const dateParsed = subMonths(dateWithoutTime, 1);
387403
onChange?.(dateParsed);
388404
};
389405

390406
const handleChangeYear = (year: number) => {
391-
const dateParsed = setYear(internalDate, year);
407+
const dateParsed = setYear(dateWithoutTime, year);
392408
onChange?.(dateParsed);
393409
};
394410

395411
const handleDateChange = (date: Date) => {
412+
console.log({
413+
date,
414+
});
396415
let dateParsed = setYear(internalDate, date.getFullYear());
397416
dateParsed = setMonth(dateParsed, date.getMonth());
398417
dateParsed = setDate(dateParsed, date.getDate());
399418

419+
console.log({
420+
dateParsed,
421+
});
422+
400423
onChange?.(dateParsed);
401424
};
402425

403426
const handleDateSelect = (date: Date) => {
427+
console.log({
428+
date,
429+
});
404430
let dateParsed = setYear(internalDate, date.getFullYear());
405431
dateParsed = setMonth(dateParsed, date.getMonth());
406432
dateParsed = setDate(dateParsed, date.getDate());
407433

434+
console.log({
435+
dateParsed,
436+
});
437+
408438
handleClose?.(dateParsed);
409439
};
410440

411-
const dateWithoutTime = new Date(
412-
internalDate.getUTCFullYear(),
413-
internalDate.getUTCMonth(),
414-
internalDate.getUTCDate(),
415-
0,
416-
0,
417-
0,
418-
0,
419-
);
420-
421-
// We have to force a end of day on the computer local timezone with the given date
422-
// Because JS Date API cannot hold a timezone other than the local one
423-
// And if we don't do that workaround we will have problems when changing the date
424-
// Because the shown date will have 1 day more or less than the real date
425-
// Leading to bugs where we select 1st of January and it shows 31st of December for example
426-
const endOfDayInLocalTimezone = new Date(
427-
internalDate.getFullYear(),
428-
internalDate.getMonth(),
429-
internalDate.getDate(),
430-
23,
431-
59,
432-
59,
433-
999,
434-
);
441+
const highlightedDates = getHighlightedDates(highlightedDateRange);
435442

436-
const dateToUse = isDateTimeInput ? endOfDayInLocalTimezone : dateWithoutTime;
443+
const selectedDates = isRelative ? highlightedDates : [dateWithoutTime];
437444

438-
const highlightedDates = getHighlightedDates(highlightedDateRange);
445+
const serverOffsetInMillisecondsToCounterActTypeORMAutomaticTimezoneShift =
446+
new Date().getTimezoneOffset() * 60 * 1000;
439447

440-
const hasDate = date != null;
448+
const shiftedDate = new Date(
449+
internalDate.getTime() +
450+
serverOffsetInMillisecondsToCounterActTypeORMAutomaticTimezoneShift,
451+
);
441452

442-
const selectedDates = isRelative
443-
? highlightedDates
444-
: hasDate
445-
? [dateToUse]
446-
: [];
453+
console.log({
454+
internalDate,
455+
shiftedDate,
456+
dateWithoutTime,
457+
});
447458

448459
return (
449460
<StyledContainer calendarDisabled={isRelative}>
@@ -478,11 +489,11 @@ export const DateTimePicker = ({
478489
>
479490
<ReactDatePicker
480491
open={true}
481-
selected={hasDate ? dateToUse : undefined}
492+
selected={dateWithoutTime}
482493
selectedDates={selectedDates}
483-
openToDate={hasDate ? dateToUse : new Date()}
494+
openToDate={dateWithoutTime}
484495
disabledKeyboardNavigation
485-
onChange={handleDateChange as any}
496+
onChange={handleDateChange}
486497
calendarStartDay={
487498
currentWorkspaceMember?.calendarStartDay ===
488499
CalendarStartDay.SYSTEM

0 commit comments

Comments
 (0)