diff --git a/ui/packages/shared/components/src/DateTimePicker/index.tsx b/ui/packages/shared/components/src/DateTimePicker/index.tsx index 2f1826841ab..433e1a3dd74 100644 --- a/ui/packages/shared/components/src/DateTimePicker/index.tsx +++ b/ui/packages/shared/components/src/DateTimePicker/index.tsx @@ -11,15 +11,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {useEffect, useRef, useState} from 'react'; +import {useEffect, useMemo, useRef, useState} from 'react'; import {Popover} from '@headlessui/react'; import {Icon} from '@iconify/react'; import cx from 'classnames'; +import moment from 'moment-timezone'; import ReactDatePicker from 'react-datepicker'; import {usePopper} from 'react-popper'; -import {convertLocalToUTCDate, convertUTCToLocalDate} from '@parca/utilities'; +import {convertLocalToUTCDate, shiftTimeAcrossTimezones} from '@parca/utilities'; import {AbsoluteDate} from '../DateTimeRangePicker/utils'; import Input from '../Input'; @@ -67,7 +68,8 @@ export const DateTimePicker = ({selected, onChange}: Props): JSX.Element => { onChange(new AbsoluteDate(textInput)); return; } - const date = new Date(textInput); + const date = + timezone !== undefined ? moment.tz(textInput, timezone).toDate() : new Date(textInput); if (isNaN(date.getTime())) { setTextInput(selected.getUIString(timezone)); return; @@ -83,6 +85,10 @@ export const DateTimePicker = ({selected, onChange}: Props): JSX.Element => { }; }, []); + const browserTimezone = useMemo(() => { + return Intl.DateTimeFormat().resolvedOptions().timeZone; + }, []); + return ( {({open}) => ( @@ -118,18 +124,20 @@ export const DateTimePicker = ({selected, onChange}: Props): JSX.Element => { className="z-10" > { if (date == null) { return; } - onChange( - new AbsoluteDate(timezone !== undefined ? date : convertLocalToUTCDate(date)) - ); + const utcDate = shiftTimeAcrossTimezones(date, browserTimezone, timezone ?? 'UTC'); + + onChange(new AbsoluteDate(utcDate)); + + onChange(new AbsoluteDate(utcDate)); setIsTextInputDirty(false); }} showTimeInput diff --git a/ui/packages/shared/profile/src/ProfileSelector/MetricsGraphSection.tsx b/ui/packages/shared/profile/src/ProfileSelector/MetricsGraphSection.tsx index 564df7607e5..7956086a6eb 100644 --- a/ui/packages/shared/profile/src/ProfileSelector/MetricsGraphSection.tsx +++ b/ui/packages/shared/profile/src/ProfileSelector/MetricsGraphSection.tsx @@ -224,7 +224,7 @@ export function MetricsGraphSection({