Skip to content

Commit

Permalink
feat(component): Correctly convert ISO8601 with TZ to display in brow…
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Nov 13, 2024
1 parent d106e79 commit 966645b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/layout/ModelForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ const ModelForm = ({

field_value = e.target.checked

} else if( e.target.type === 'datetime-local' ) {

if( e.target.value != '' ) { // Convert to UTC

field_value = new Date(e.target.value).toISOString()

}

}

setFormData((prevState) => ({ ...prevState, [e.target.id]: field_value }))
Expand Down Expand Up @@ -223,6 +231,15 @@ const ModelForm = ({

case 'DateTime':

if( value ) { // Convert DateTime (UTC) to local Time

let datetime = new Date(value)
let local_datetime = new Date(datetime - datetime.getTimezoneOffset()*60*1000).toISOString();

value = String(local_datetime).split('.')[0]

}

return (<TextField
id = {field_key}
label = {metadata.fields[field_key].label}
Expand Down

0 comments on commit 966645b

Please sign in to comment.