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'
77import allowOverride from '../../../hoc/allow-override.js'
88import { useTranslation } from '../../../hooks/index.js'
99import { PropertyType } from '../../../../backend/index.js'
10+ import { stripTimeFromISO } from './strip-time-from-iso.js'
1011
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`
1418}
1519
1620const Edit : React . FC < EditPropertyProps > = ( props ) => {
@@ -26,7 +30,10 @@ const Edit: React.FC<EditPropertyProps> = (props) => {
2630 value = { value }
2731 disabled = { property . isDisabled }
2832 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+ )
3037 } }
3138 propertyType = { property . type }
3239 { ...property . props }
Original file line number Diff line number Diff line change 11import { formatDateProperty } from '@adminjs/design-system'
22
33import { PropertyType } from '../../../../backend/adapters/property/base-property.js'
4+ import { stripTimeFromISO } from './strip-time-from-iso.js'
45
56export default ( value : Date , propertyType : PropertyType ) : string => {
67 if ( ! value ) {
78 return ''
89 }
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 )
1011 if ( date ) {
1112 return formatDateProperty ( date , propertyType )
1213 }
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