Skip to content

Commit

Permalink
fix: Disabled utc='preserve'dates not properly mapped for a specifi…
Browse files Browse the repository at this point in the history
…c timezone (fixes #560)
  • Loading branch information
Jasenkoo committed Sep 8, 2023
1 parent fb6c7f6 commit 076f7d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/VueDatePicker/components/DatePicker/date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export const useDatePicker = (
};
// Get 7 days from the provided start date, month is used to check whether the date is from the specified month or in the offset
const getWeekDays = (startDay: Date, month: number): ICalendarDay[] => {
const startDate = getDate(JSON.parse(JSON.stringify(startDay)));
const startDate = getDate(startDay);
const dates = [];
for (let i = 0; i < 7; i++) {
const next = addDays(startDate, i);
Expand Down
11 changes: 9 additions & 2 deletions src/VueDatePicker/composables/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getDateForCompare,
getDaysInBetween,
getTimeObj,
getUtcDate,
getZonedDate,
isDateAfter,
isDateBefore,
Expand All @@ -20,17 +21,23 @@ import type { PickerBasePropsType, AllPropsType } from '@/props';

export const useValidation = (props: PickerBasePropsType | AllPropsType) => {
const { defaultedFilters } = useDefaults(props);
const getTimezone = () => {
if (props.timezone) return props.timezone;
if (props.utc) return 'UTC';
return undefined;
};
const getMapKey = (date: Date | string | number) => {
const d = resetDateTime(getTzDate(getDate(date))).toISOString();
const [stringVal] = d.split('T');
return stringVal;
};
const getTzDate = (date: Date) => getZonedDate(date, props.timezone);
const getTzDate = (date: Date) =>
props.utc === 'preserve' ? getUtcDate(date, getTimezone()) : getZonedDate(date, getTimezone());
const validateDate = (date: Date) => {
const aboveMax = props.maxDate ? isDateAfter(getTzDate(date), getTzDate(getDate(props.maxDate))) : false;
const bellowMin = props.minDate ? isDateBefore(getTzDate(date), getTzDate(getDate(props.minDate))) : false;
const inDisableArr = matchDate(
date,
getTzDate(date),
(props as PickerBasePropsType).arrMapValues?.disabledDates
? (props as PickerBasePropsType).arrMapValues.disabledDates
: props.disabledDates,
Expand Down

0 comments on commit 076f7d2

Please sign in to comment.