Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix invalid date issue if seconds are set to 0 in html input datetime

Joshen Lime41246ef0bc9
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
index 6b6b5eb41f8..683b0821872 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
@@ -122,6 +122,7 @@ const RowEditor: FC<Props> = ({
if (isEmpty(errors)) {
updateEditorDirty()
+
const payload = isNewRecord
? generateRowObjectFromFields(rowFields)
: generateUpdateRowPayload(row, rowFields)
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
index 4be4a5eae1d..57e15a31b59 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
@@ -275,7 +275,11 @@ export const generateRowObjectFromFields = (
} else if (field.format === 'bool' && value) {
rowObject[field.name] = value === 'true'
} else if (DATETIME_TYPES.includes(field.format)) {
- rowObject[field.name] = convertInputDatetimeToPostgresDatetime(field.format, value)
+ // Seconds are missing if they are set to 0 in the HTML input
+ // Need to format that first, before passing to dayjs
+ const timeSegments = (value || '').split(':')
+ const formattedValue = timeSegments.length === 2 ? `${value}:00` : value
+ rowObject[field.name] = convertInputDatetimeToPostgresDatetime(field.format, formattedValue)
} else {
rowObject[field.name] = value
}