Fixes issue with dates and daylight savings (#1752)
* dates should use themselves for timezone offset * remove log lines Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
parent
f566a7d7c0
commit
381085f655
|
@ -38,7 +38,6 @@ const loadedLocales: Record<string, moment.Locale> = {}
|
|||
function DateRange(props: Props): JSX.Element {
|
||||
const {className, value, showEmptyPlaceholder, onChange} = props
|
||||
const intl = useIntl()
|
||||
const timeZoneOffset = new Date().getTimezoneOffset() * 60 * 1000
|
||||
|
||||
const getDisplayDate = (date: Date | null | undefined) => {
|
||||
let displayDate = ''
|
||||
|
@ -48,6 +47,10 @@ function DateRange(props: Props): JSX.Element {
|
|||
return displayDate
|
||||
}
|
||||
|
||||
const timeZoneOffset = (date: number): number => {
|
||||
return new Date(date).getTimezoneOffset() * 60 * 1000
|
||||
}
|
||||
|
||||
const createDatePropertyFromString = (initialValue: string) => {
|
||||
let dateProperty: DateProperty = {}
|
||||
if (initialValue) {
|
||||
|
@ -71,8 +74,8 @@ function DateRange(props: Props): JSX.Element {
|
|||
// Keep dateProperty as UTC,
|
||||
// dateFrom / dateTo will need converted to local time, to ensure date stays consistent
|
||||
// dateFrom / dateTo will be used for input and calendar dates
|
||||
const dateFrom = dateProperty.from ? new Date(dateProperty.from + (dateProperty.includeTime ? 0 : timeZoneOffset)) : undefined
|
||||
const dateTo = dateProperty.to ? new Date(dateProperty.to + (dateProperty.includeTime ? 0 : timeZoneOffset)) : undefined
|
||||
const dateFrom = dateProperty.from ? new Date(dateProperty.from + (dateProperty.includeTime ? 0 : timeZoneOffset(dateProperty.from))) : undefined
|
||||
const dateTo = dateProperty.to ? new Date(dateProperty.to + (dateProperty.includeTime ? 0 : timeZoneOffset(dateProperty.to))) : undefined
|
||||
const [fromInput, setFromInput] = useState<string>(getDisplayDate(dateFrom))
|
||||
const [toInput, setToInput] = useState<string>(getDisplayDate(dateTo))
|
||||
|
||||
|
@ -118,10 +121,10 @@ function DateRange(props: Props): JSX.Element {
|
|||
const saveRangeValue = (range: DateProperty) => {
|
||||
const rangeUTC = {...range}
|
||||
if (rangeUTC.from) {
|
||||
rangeUTC.from -= dateProperty.includeTime ? 0 : timeZoneOffset
|
||||
rangeUTC.from -= dateProperty.includeTime ? 0 : timeZoneOffset(rangeUTC.from)
|
||||
}
|
||||
if (rangeUTC.to) {
|
||||
rangeUTC.to -= dateProperty.includeTime ? 0 : timeZoneOffset
|
||||
rangeUTC.to -= dateProperty.includeTime ? 0 : timeZoneOffset(rangeUTC.to)
|
||||
}
|
||||
|
||||
setDateProperty(rangeUTC)
|
||||
|
|
Loading…
Reference in New Issue
Block a user