8 examples of 'proptypes date' in JavaScript

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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
6get type() {
7 return 'date';
8}
12toJsDate() {
13 return new Date(this._value.getTime()); // return a clone.
14}
5export 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
35 );
36 }
37 return (
38
39 );
40}
41export 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}
34get date() {
35 return super.date;
36}
93function getDateObj(date: RelaxedDateType): Date {
94 if (isString(date) || isNumber(date)) {
95 date = new Date(date);
96 }
97 return date;
98}
16export function actualDate(date) {
17 return new Date(flatpickr.parseDate(date, DATE_FORMAT));
18}
30constructor(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}

Related snippets