fix(trino): normalize non-iso timestamps (#23339)

This commit is contained in:
Ville Brofeldt
2023-03-13 14:46:39 +02:00
committed by GitHub
parent a8d5cb89a8
commit a591130e0b
4 changed files with 81 additions and 13 deletions

View File

@@ -16,9 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
import { DataRecordValue, TimeFormatFunction } from '@superset-ui/core';
const REGEXP_TIMESTAMP_NO_TIMEZONE = /T(\d{2}:){2}\d{2}$/;
import {
DataRecordValue,
normalizeTimestamp,
TimeFormatFunction,
} from '@superset-ui/core';
/**
* Extended Date object with a custom formatter, and retains the original input
@@ -31,19 +33,12 @@ export default class DateWithFormatter extends Date {
constructor(
input: DataRecordValue,
{
formatter = String,
forceUTC = true,
}: { formatter?: TimeFormatFunction; forceUTC?: boolean } = {},
{ formatter = String }: { formatter?: TimeFormatFunction } = {},
) {
let value = input;
// assuming timestamps without a timezone is in UTC time
if (
forceUTC &&
typeof value === 'string' &&
REGEXP_TIMESTAMP_NO_TIMEZONE.test(value)
) {
value = `${value}Z`;
if (typeof value === 'string') {
value = normalizeTimestamp(value);
}
super(value as string);