| 86 | } |
| 87 | |
| 88 | getFormat() { |
| 89 | const { field } = this.props; |
| 90 | let inputType = 'datetime-local'; |
| 91 | let inputFormat = 'YYYY-MM-DDTHH:mm'; |
| 92 | let format = `YYYY-MM-DDTHH:mm:ss.SSS${this.isUtc ? '[Z]' : 'Z'}`; |
| 93 | let userFormat = field?.get('format'); |
| 94 | let dateFormat = field?.get('date_format'); |
| 95 | let timeFormat = field?.get('time_format'); |
| 96 | if (dateFormat === true) dateFormat = 'YYYY-MM-DD'; |
| 97 | if (timeFormat === true) timeFormat = 'HH:mm'; |
| 98 | |
| 99 | if (this.isUtc) { |
| 100 | userFormat = this.escapeZ(userFormat); |
| 101 | dateFormat = this.escapeZ(dateFormat); |
| 102 | timeFormat = this.escapeZ(timeFormat); |
| 103 | } |
| 104 | |
| 105 | if (typeof dateFormat === 'string' && typeof timeFormat === 'string') { |
| 106 | format = `${dateFormat}T${timeFormat}`; |
| 107 | } else if (typeof timeFormat === 'string') { |
| 108 | inputType = 'time'; |
| 109 | format = timeFormat; |
| 110 | } else if (typeof dateFormat === 'string') { |
| 111 | inputType = 'date'; |
| 112 | format = dateFormat; |
| 113 | } |
| 114 | |
| 115 | if (typeof userFormat === 'string') { |
| 116 | format = userFormat; |
| 117 | inputType = 'datetime-local'; |
| 118 | } |
| 119 | |
| 120 | if (dateFormat === false) inputType = 'time'; |
| 121 | if (timeFormat === false) inputType = 'date'; |
| 122 | if (inputType === 'datetime-local') inputFormat = 'YYYY-MM-DDTHH:mm'; |
| 123 | if (inputType === 'date') inputFormat = 'YYYY-MM-DD'; |
| 124 | if (inputType === 'time') inputFormat = 'HH:mm'; |
| 125 | |
| 126 | return { format, inputType, inputFormat }; |
| 127 | } |
| 128 | |
| 129 | isValidDate = dt => dayjs(dt, this.getFormat().inputFormat).isValid() || dt === ''; |
| 130 | |