Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parseDate(value, format = this.config.format) {
// @see http://momentjs.com/docs/#/parsing/
// return any current moment
if (moment.isMoment(value)) {
if (!value.isValid()) {
this.throwError(`Invalid moment: ${value} provided.`)
}
return this.newMoment(value)
}
else if (typeof value === "string") {
// parse with locale and strictness
let m = moment(value, format, this.config.lang, true)
if (!m.isValid()) {
this.throwError(`Invalid moment: ${value} for format: ${format} and locale: ${this.config.lang}`)
}
return m
}
filterQueryObj(oldObj) {
// 将提交的值中undefined的去掉
const newObj = {};
for (const key in oldObj) {
if (oldObj[key]) {
// 对于js的日期类型, 要转换成字符串再传给后端
if (oldObj[key] instanceof Date) {
newObj[key] = oldObj[key].format('yyyy-MM-dd HH:mm:ss');
} else if (moment.isMoment(oldObj[key])) { // 处理moment对象
newObj[key] = oldObj[key].format('YYYY-MM-DD HH:mm:ss');
} else {
newObj[key] = oldObj[key];
}
}
}
logger.debug('old queryObj: %o, new queryObj %o', oldObj, newObj);
return newObj;
}
getTabItems() {
const datePickerTimes = {
start: moment.isMoment(this.props.startTime) ? this.props.startTime : this.latestTimestamp,
end: moment.isMoment(this.props.endTime) ? this.props.endTime : this.now,
};
const formattedStartTime = this.latestTimestamp.format(TIME_FORMAT);
// Show different labels for the start time depending on whether
// the job has seen any data yet
const showContinueLabels = this.latestTimestamp.valueOf() > 0;
const startLabels =
showContinueLabels === true
? [
,
it('initialized with moment', () => {
const date = moment('2015-05-01');
const wrapper = mount();
assert(moment.isMoment(wrapper.state('date')), 'has moment instance in `date` state field');
assert(wrapper.state('date').isSame(date), 'initialize `date` state field with moment provided in `initializeWith` prop');
});
});
export function syncTime(from, to) {
if (!moment.isMoment(from) || !moment.isMoment(to)) return;
to.hour(from.hour());
to.minute(from.minute());
to.second(from.second());
}
const isMoment = (v) => moment.isMoment(v)
constructor(props) {
super(props);
const value = getValueFromTime(props.value || props.defaultValue);
if( value[0] && !moment.isMoment(value[0]) || !value[1] && moment.isMoment(value[1]) ) {
throw new Error('The value/defaultValue of BizTimePicker must be a moment object array');
}
this.state = {
showDate: getShowDateFromValue(props.value || props.defaultValue || props.quickTimeOption[0], props.format),
open: props.open
};
}
const createOptionForDate = d => {
const date = moment.isMoment(d) ? d : moment(d);
return {
date,
value: date.toDate(),
label: date.calendar(null, {
sameDay: '[Today] (Do MMM YYYY)',
nextDay: '[Tomorrow] (Do MMM YYYY)',
nextWeek: '[Next] dddd (Do MMM YYYY)',
lastDay: '[Yesterday] (Do MMM YYYY)',
lastWeek: '[Last] dddd (Do MMM YYYY)',
sameElse: 'Do MMMM YYYY',
}),
};
};
export default function parse(text, roundUp) {
if (!text) {
return undefined;
}
if (moment.isMoment(text)) {
return text;
}
if (_.isDate(text)) {
return moment(text);
}
let time;
let mathString = '';
let index;
let parseString;
if (text.substring(0, 3) === 'now') {
time = moment();
mathString = text.substring('now'.length);
} else {
index = text.indexOf('||');
function formatTime(time: string | Moment, roundUp = false) {
if (moment.isMoment(time)) {
return time.format('lll');
} else {
if (time === 'now') {
return 'now';
} else {
const tryParse = dateMath.parse(time, { roundUp });
return moment.isMoment(tryParse) ? '~ ' + tryParse.fromNow() : time;
}
}
}