Skip to content

fix: first time date picker on UTC mode #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions src/datetime-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import localeData from 'dayjs/plugin/localeData';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import relativeTime from 'dayjs/plugin/relativeTime';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import jalaliday from 'jalali-plugin-dayjs';
import React, {
useCallback,
useEffect,
Expand All @@ -6,40 +14,32 @@ import React, {
useRef,
} from 'react';
import { I18nManager } from 'react-native';
import {
dateToUnix,
getEndOfDay,
getStartOfDay,
areDatesOnSameDay,
removeTime,
} from './utils';
import { CalendarContext } from './calendar-context';
import Calendar from './components/calendar';
import {
CalendarViews,
CalendarActionKind,
CalendarViews,
CONTAINER_HEIGHT,
WEEKDAYS_HEIGHT,
} from './enums';
import { usePrevious } from './hooks/use-previous';
import type {
DateType,
CalendarAction,
LocalState,
DatePickerBaseProps,
SingleChange,
RangeChange,
DateType,
LocalState,
MultiChange,
RangeChange,
SingleChange,
} from './types';
import Calendar from './components/calendar';
import { useDeepCompareMemo } from './utils';
import dayjs from 'dayjs';
import localeData from 'dayjs/plugin/localeData';
import relativeTime from 'dayjs/plugin/relativeTime';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import duration from 'dayjs/plugin/duration';
import { usePrevious } from './hooks/use-previous';
import jalaliday from 'jalali-plugin-dayjs';
import {
areDatesOnSameDay,
dateToUnix,
getEndOfDay,
getStartOfDay,
removeTime,
useDeepCompareMemo,
} from './utils';

dayjs.extend(localeData);
dayjs.extend(relativeTime);
Expand Down Expand Up @@ -294,11 +294,13 @@ const DateTimePicker = (

useEffect(() => {
if (mode === 'single') {
let _date =
let _date =
(date &&
(timePicker
? dayjs.tz(date, timeZone)
: getStartOfDay(dayjs.tz(date, timeZone)))) ??
(timeZone === 'UTC'
? dayjs(date)
: timePicker
? dayjs.tz(date, timeZone)
: getStartOfDay(dayjs.tz(date, timeZone)))) ??
date;

if (_date && maxDate && dayjs.tz(_date, timeZone).isAfter(maxDate)) {
Expand Down