From 0822da0911fff33ca9da20378c45d559bd8f708f Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 2 Nov 2023 16:26:08 -0700 Subject: [PATCH 1/3] fix issue where selected date is 1 before actual date --- src/components/NewDatePicker/CalendarPicker/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/NewDatePicker/CalendarPicker/index.js b/src/components/NewDatePicker/CalendarPicker/index.js index 1a1ea9a726e8..49cc446bbce6 100644 --- a/src/components/NewDatePicker/CalendarPicker/index.js +++ b/src/components/NewDatePicker/CalendarPicker/index.js @@ -205,8 +205,7 @@ class CalendarPicker extends React.PureComponent { const isBeforeMinDate = currentDate < startOfDay(new Date(this.props.minDate)); const isAfterMaxDate = currentDate > startOfDay(new Date(this.props.maxDate)); const isDisabled = !day || isBeforeMinDate || isAfterMaxDate; - const isSelected = isSameDay(new Date(this.props.value), new Date(currentYearView, currentMonthView, day)); - + const isSelected = isSameDay(new Date(this.props.value), new Date(currentYearView, currentMonthView, day - 1)); return ( Date: Thu, 2 Nov 2023 16:31:00 -0700 Subject: [PATCH 2/3] use parseISO to ignore timezone checks --- src/components/NewDatePicker/CalendarPicker/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/NewDatePicker/CalendarPicker/index.js b/src/components/NewDatePicker/CalendarPicker/index.js index 49cc446bbce6..ea45ecab48a3 100644 --- a/src/components/NewDatePicker/CalendarPicker/index.js +++ b/src/components/NewDatePicker/CalendarPicker/index.js @@ -1,4 +1,4 @@ -import {addMonths, endOfMonth, format, getYear, isSameDay, setDate, setYear, startOfDay, subMonths} from 'date-fns'; +import {addMonths, endOfMonth, format, getYear, isSameDay, setDate, setYear, startOfDay, subMonths, parseISO} from 'date-fns'; import Str from 'expensify-common/lib/str'; import PropTypes from 'prop-types'; import React from 'react'; @@ -205,7 +205,7 @@ class CalendarPicker extends React.PureComponent { const isBeforeMinDate = currentDate < startOfDay(new Date(this.props.minDate)); const isAfterMaxDate = currentDate > startOfDay(new Date(this.props.maxDate)); const isDisabled = !day || isBeforeMinDate || isAfterMaxDate; - const isSelected = isSameDay(new Date(this.props.value), new Date(currentYearView, currentMonthView, day - 1)); + const isSelected = isSameDay(parseISO(this.props.value), new Date(currentYearView, currentMonthView, day)); return ( Date: Thu, 2 Nov 2023 16:37:34 -0700 Subject: [PATCH 3/3] style --- src/components/NewDatePicker/CalendarPicker/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/NewDatePicker/CalendarPicker/index.js b/src/components/NewDatePicker/CalendarPicker/index.js index ea45ecab48a3..4b17766feb17 100644 --- a/src/components/NewDatePicker/CalendarPicker/index.js +++ b/src/components/NewDatePicker/CalendarPicker/index.js @@ -1,4 +1,4 @@ -import {addMonths, endOfMonth, format, getYear, isSameDay, setDate, setYear, startOfDay, subMonths, parseISO} from 'date-fns'; +import {addMonths, endOfMonth, format, getYear, isSameDay, parseISO, setDate, setYear, startOfDay, subMonths} from 'date-fns'; import Str from 'expensify-common/lib/str'; import PropTypes from 'prop-types'; import React from 'react';