File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
src/frontend/components/property-type/datetime Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,14 @@ import { PropertyLabel } from '../utils/property-label/index.js'
7
7
import allowOverride from '../../../hoc/allow-override.js'
8
8
import { useTranslation } from '../../../hooks/index.js'
9
9
import { PropertyType } from '../../../../backend/index.js'
10
+ import { stripTimeFromISO } from './strip-time-from-iso.js'
10
11
11
- const formatDate = ( val :string | null , propertyType : PropertyType ) => {
12
- if ( val ) return ( propertyType === 'date' ? `${ val } T00:00:00` : val )
13
- return ''
12
+ const formatDate = ( date : string | Date | null , propertyType : PropertyType ) => {
13
+ if ( ! date ) return ''
14
+
15
+ if ( propertyType !== 'date' ) return date
16
+
17
+ return `${ stripTimeFromISO ( date ) } T00:00:00`
14
18
}
15
19
16
20
const Edit : React . FC < EditPropertyProps > = ( props ) => {
@@ -26,7 +30,10 @@ const Edit: React.FC<EditPropertyProps> = (props) => {
26
30
value = { value }
27
31
disabled = { property . isDisabled }
28
32
onChange = { ( date ) => {
29
- onChange ( property . path , property . type === 'date' ? date ?. substring ( 0 , 10 ) ?? date : date )
33
+ onChange (
34
+ property . path ,
35
+ property . type === 'date' ? stripTimeFromISO ( date ) ?? date : date ,
36
+ )
30
37
} }
31
38
propertyType = { property . type }
32
39
{ ...property . props }
Original file line number Diff line number Diff line change 1
1
import { formatDateProperty } from '@adminjs/design-system'
2
2
3
3
import { PropertyType } from '../../../../backend/adapters/property/base-property.js'
4
+ import { stripTimeFromISO } from './strip-time-from-iso.js'
4
5
5
6
export default ( value : Date , propertyType : PropertyType ) : string => {
6
7
if ( ! value ) {
7
8
return ''
8
9
}
9
- const date = propertyType === 'date' ? new Date ( `${ value } T00:00:00` ) : new Date ( value )
10
+ const date = propertyType === 'date' ? new Date ( `${ stripTimeFromISO ( value ) } T00:00:00` ) : new Date ( value )
10
11
if ( date ) {
11
12
return formatDateProperty ( date , propertyType )
12
13
}
Original file line number Diff line number Diff line change
1
+ export const stripTimeFromISO = ( date : string | Date | null ) : string | null => {
2
+ if ( date === null ) return null
3
+
4
+ if ( typeof date === 'string' ) {
5
+ return date . replace ( / T \d { 2 } : \d { 2 } : \d { 2 } \. \d { 3 } Z $ / , '' )
6
+ }
7
+
8
+ return date . toISOString ( ) . replace ( / T \d { 2 } : \d { 2 } : \d { 2 } \. \d { 3 } Z $ / , '' )
9
+ }
You can’t perform that action at this time.
0 commit comments