Skip to content
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

fix(DateInput3): Fix wrong today date for timezone mismatch #7122

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const DateInput3: React.FC<DateInput3Props> = React.memo(function _DateIn
onShortcutChange={handleShortcutChange}
selectedShortcutIndex={selectedShortcutIndex}
timePrecision={timePrecision}
timezone={timezoneValue}
// the rest of this component handles invalid dates gracefully (to show error messages),
// but DatePicker does not, so we must take care to filter those out
value={isErrorState ? null : valueAsDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
DateUtils,
Errors,
TimePicker,
TimezoneUtils,
} from "@blueprintjs/datetime";

import { Classes, dayPickerClassNameOverrides } from "../../classes";
Expand Down Expand Up @@ -355,7 +356,9 @@ export class DatePicker3 extends DateFnsLocalizedComponent<DatePicker3Props, Dat
};

private handleTodayClick = () => {
const value = new Date();
const { timezone } = this.props;
const today = new Date();
const value = timezone != null ? TimezoneUtils.convertLocalDateToTimezoneTime(today, timezone) : today;
const displayMonth = value.getMonth();
const displayYear = value.getFullYear();
const selectedDay = value.getDate();
Expand Down
10 changes: 10 additions & 0 deletions packages/datetime2/src/components/date-picker3/datePicker3Props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ export interface DatePicker3Props extends DatePickerSharedProps, DateFnsLocalePr
* The currently selected day. If this prop is provided, the component acts in a controlled manner.
*/
value?: Date | null;

/**
* The currently selected timezone UTC identifier, e.g. "Pacific/Honolulu".
*
* This prop is only used to determine what date should be selected when clicking the "Today" button in the actions
* bar. If this value is omitted, the current date will be set using the user's local timezone.
*
* See [IANA Time Zones](https://www.iana.org/time-zones).
*/
timezone?: string;
}