MCPcopy Create free account
hub / github.com/json-editor/json-editor / _validateDateTimeSubSchema

Method _validateDateTimeSubSchema

src/validator.js:869–951  ·  view source on GitHub ↗
(schema, value, path)

Source from the content-addressed store, hash-verified

867 }
868
869 _validateDateTimeSubSchema (schema, value, path) {
870 const _validateInteger = (schema, value, path) => {
871 /* The value is a timestamp */
872 if (value * 1 < 1) {
873 /* If value is less than 1, then it's an invalid epoch date before 00:00:00 UTC Thursday, 1 January 1970 */
874 return [{
875 path,
876 property: 'format',
877 message: this.translate('error_invalid_epoch', null, schema)
878 }]
879 } else if (value !== Math.abs(parseInt(value))) {
880 /* not much to check for, so we assume value is ok if it's a positive number */
881 return [{
882 path,
883 property: 'format',
884 message: this.translate(`error_${schema.format.replace(/-/g, '_')}`, [dateFormat], schema)
885 }]
886 }
887 return []
888 }
889 const _validateFlatPicker = (schema, value, path, editor) => {
890 if (value !== '') {
891 let compareValue
892 if (editor.flatpickr.config.mode !== 'single') {
893 const seperator = editor.flatpickr.config.mode === 'range' ? editor.flatpickr.l10n.rangeSeparator : ', '
894 const selectedDates = editor.flatpickr.selectedDates.map(val =>
895 editor.flatpickr.formatDate(val, editor.flatpickr.config.dateFormat)
896 )
897 compareValue = selectedDates.join(seperator)
898 }
899
900 try {
901 if (compareValue) {
902 /* Not the best validation method, but range and multiple mode are special */
903 /* Optimal solution would be if it is possible to change the return format from string/integer to array */
904 if (compareValue !== value) throw new Error(`${editor.flatpickr.config.mode} mismatch`)
905 } else if (editor.flatpickr.formatDate(editor.flatpickr.parseDate(value, editor.flatpickr.config.dateFormat), editor.flatpickr.config.dateFormat) !== value) {
906 throw new Error('mismatch')
907 }
908 } catch (err) {
909 const errorDateFormat = editor.flatpickr.config.errorDateFormat !== undefined ? editor.flatpickr.config.errorDateFormat : editor.flatpickr.config.dateFormat
910 return [{
911 path,
912 property: 'format',
913 message: this.translate(`error_${editor.format.replace(/-/g, '_')}`, [errorDateFormat], schema)
914 }]
915 }
916 }
917 return []
918 }
919
920 const validatorRx = {
921 date: /^(\d{4}\D\d{2}\D\d{2})$/,
922 time: /^(\d{2}:\d{2}(?::\d{2})?)$/,
923 'datetime-local': /^(\d{4}\D\d{2}\D\d{2}[ T]\d{2}:\d{2}(?::\d{2})?)$/
924 }
925 const format = {
926 date: '"YYYY-MM-DD"',

Callers 1

_validateSchemaMethod · 0.95

Calls 1

getEditorMethod · 0.80

Tested by

no test coverage detected