Better timezone support on query and dropdowns/custom-timeframes.

This commit is contained in:
2023-03-14 17:01:43 -05:00
parent 984dce88d4
commit 94767bcbb3
8 changed files with 110 additions and 43 deletions

View File

@ -175,7 +175,10 @@ export default class DataGridUtils
filterOperators: filterOperators,
};
if (columnsToRender[field.name])
/////////////////////////////////////////////////////////////////////////////////////////
// looks like, maybe we can just always render all columns, and remove this parameter? //
/////////////////////////////////////////////////////////////////////////////////////////
if (columnsToRender == null || columnsToRender[field.name])
{
column.renderCell = (cellValues: any) => (
(cellValues.value)

View File

@ -314,11 +314,7 @@ class FilterUtils
{
try
{
let localDate = new Date(param[i]);
let month = (1 + localDate.getUTCMonth());
let zp = FilterUtils.zeroPad;
let toPush = localDate.getUTCFullYear() + "-" + zp(month) + "-" + zp(localDate.getUTCDate()) + "T" + zp(localDate.getUTCHours()) + ":" + zp(localDate.getUTCMinutes()) + ":" + zp(localDate.getUTCSeconds()) + "Z";
console.log(`Input date was ${localDate}. Sending to backend as ${toPush}`);
let toPush = this.frontendLocalZoneDateTimeStringToUTCStringForBackend(param[i]);
rs.push(toPush);
}
catch (e)
@ -336,6 +332,22 @@ class FilterUtils
return (rs);
};
/*******************************************************************************
** Take a string date (w/o a timezone) like that our calendar widgets make,
** and convert it to UTC, e.g., for submitting to the backend.
*******************************************************************************/
public static frontendLocalZoneDateTimeStringToUTCStringForBackend(param: string)
{
let localDate = new Date(param);
let month = (1 + localDate.getUTCMonth());
let zp = FilterUtils.zeroPad;
let toPush = localDate.getUTCFullYear() + "-" + zp(month) + "-" + zp(localDate.getUTCDate()) + "T" + zp(localDate.getUTCHours()) + ":" + zp(localDate.getUTCMinutes()) + ":" + zp(localDate.getUTCSeconds()) + "Z";
console.log(`Input date was ${localDate}. Sending to backend as ${toPush}`);
return toPush;
}
/*******************************************************************************
** Convert a filter field's value from the style that qqq uses, to the style that
** the grid uses.

View File

@ -353,6 +353,21 @@ class ValueUtils
//////////////////////////////////////////////////////////////////
return (value + "T00:00");
}
else if (value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?Z$/))
{
///////////////////////////////////////////////////////////////////////////////////////////////////////
// If the passed in string has a Z on the end (e.g., in UTC) - make a Date object - the browser will //
// shift the value into the user's time zone, so it will display correctly for them //
///////////////////////////////////////////////////////////////////////////////////////////////////////
const date = new Date(value);
// @ts-ignore
const formattedDate = `${date.toString("yyyy-MM-ddTHH:mm")}`
console.log(`Converted UTC date value string [${value}] to local time value for form [${formattedDate}]`)
return (formattedDate);
}
else if (value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}.*/))
{
///////////////////////////////////////////////////////////////////////////////////