Every line of 'proptypes date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
6 get type() { 7 return 'date'; 8 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
12 toJsDate() { 13 return new Date(this._value.getTime()); // return a clone. 14 }
5 export default function date(p) { 6 const { format = 'dateTime' } = p.schema; 7 let dateFormat; 8 switch (format) { 9 case 'date': 10 dateFormat = 'YYYY-MM-DD'; 11 break; 12 case 'time': 13 dateFormat = 'HH:mm:ss'; 14 break; 15 default: 16 // dateTime 17 dateFormat = 'YYYY-MM-DD HH:mm:ss'; 18 } 19 let defaultObj = {}; 20 if (p.value) { 21 defaultObj = { 22 value: moment(p.value, dateFormat), 23 }; 24 } 25 26 const placeholderObj = p.description ? { placeholder: p.description } : {}; 27 28 const onChange = value => { 29 p.onChange(p.name, moment(value || '', dateFormat).format(dateFormat)); 30 }; 31 32 if (format === 'time') { 33 return ( 34 <TimePicker 35 style={{ width: '100%' }} 36 {...p.options} 37 disabled={p.disabled} 38 {...defaultObj} 39 onChange={onChange} 40 /> 41 ); 42 } 43 return ( 44 <DatePicker 45 style={{ width: '100%' }} 46 {...placeholderObj} 47 showTime={format === 'dateTime'} 48 {...p.options} 49 {...defaultObj} 50 disabled={p.disabled} 51 onChange={onChange} 52 /> 53 ); 54 }
41 export function checkDateValue(props, propName, componentName) { 42 // 支持传入 moment 对象或字符串,字符串不检测是否为日期字符串 43 if ( 44 props[propName] && 45 !moment.isMoment(props[propName]) && 46 typeof props[propName] !== 'string' 47 ) { 48 return new Error( 49 `Invalid prop ${propName} supplied to ${componentName}. Required a moment object or format date string!` 50 ); 51 } 52 }
34 get date() { 35 return super.date; 36 }
93 function getDateObj(date: RelaxedDateType): Date { 94 if (isString(date) || isNumber(date)) { 95 date = new Date(date); 96 } 97 return date; 98 }
16 export function actualDate(date) { 17 return new Date(flatpickr.parseDate(date, DATE_FORMAT)); 18 }
30 constructor(props, context) { 31 super(props, context); 32 const {_obj, _fld} = props; 33 34 this.state = { 35 showTime: true, 36 showDateInput: true, 37 value: moment(_obj[_fld]), 38 defaultCalendarValue: moment(_obj[_fld]), 39 }; 40 }