Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!versionId && !cycleId && children.length > 0) {
// 版本 规划中
let stepChildren = [];
children.forEach((child) => {
stepChildren = [...stepChildren, ...child.children];
});
// 进行过滤,防止时间为空
const starts = stepChildren.filter(child => child.fromDate && child.toDate).map(child => moment(child.fromDate));
const ends = stepChildren.filter(child => child.fromDate && child.toDate).map(child => moment(child.toDate));
if (starts.length > 0 && ends.length > 0) {
times.push({
...node,
// children, 不需要编辑,不用限制时间的选择,所有不用传children
type: 'topversion',
start: moment.min(starts),
end: moment.max(ends),
});
}
} else if (versionId && !cycleId && children.length > 0) {
// 版本 0.1.1
// console.log(children);
const starts = children.filter(child => child.fromDate && child.toDate).map(child => moment(child.fromDate));
const ends = children.filter(child => child.fromDate && child.toDate).map(child => moment(child.toDate));
if (starts.length > 0 && ends.length > 0) {
times.push({
...node,
// children,
type: 'version',
start: moment.min(starts),
end: moment.max(ends),
});
return;
}
const workPackageState:InputState = this.states.workPackages.get(wpId);
const workPackage:WorkPackageResource|undefined = workPackageState.value;
if (!workPackage) {
return;
}
// We may still have a reference to a row that, e.g., just got deleted
const startDate = workPackage.startDate ? moment(workPackage.startDate) : currentParams.now;
const dueDate = workPackage.dueDate ? moment(workPackage.dueDate) : currentParams.now;
const date = workPackage.date ? moment(workPackage.date) : currentParams.now;
// start date
newParams.dateDisplayStart = moment.min(
newParams.dateDisplayStart,
currentParams.now,
startDate,
date);
// finish date
newParams.dateDisplayEnd = moment.max(
newParams.dateDisplayEnd,
currentParams.now,
dueDate,
date);
});
export function humanizeTimestamp(timestamp: string | number): string {
const time = moment.utc(timestamp); // parse time as UTC
const now = moment();
// Not in future humanized time
return moment.min(time, now).from(now);
}
renderTimeSlices(vp:TimelineViewParameters,
unit:moment.unitOfTime.DurationConstructor,
marginTop:number,
startView:Moment,
endView:Moment,
cellCallback:(start:Moment, cell:HTMLElement) => void) {
const slices:[Moment, Moment][] = [];
const time = startView.clone().startOf(unit);
const end = endView.clone().endOf(unit);
while (time.isBefore(end)) {
const sliceStart = moment.max(time, startView).clone();
const sliceEnd = moment.min(time.clone().endOf(unit), endView).clone();
time.add(1, unit);
slices.push([sliceStart, sliceEnd]);
}
for (let [start, end] of slices) {
const cell = this.addLabelCell();
cell.style.top = marginTop + "px";
cell.style.left = calculatePositionValueForDayCount(vp, start.diff(startView, "days"));
cell.style.width = calculatePositionValueForDayCount(vp, end.diff(start, "days") + 1);
cellCallback(start, cell);
}
}
function aggregateByMonth(history) {
const dates = history.map((event) => moment(event.starred_at));
const firstDate = moment.min(dates).startOf('month');
const lastDate = moment.max(dates).startOf('month');
const amountOfMonth = lastDate.diff(firstDate, 'months');
const amountsMap = {};
for (let i = -1; i <= amountOfMonth; i++) {
const currentMonth = firstDate.clone().add(i, 'months').format('YYYY-MM');
amountsMap[currentMonth] = 0;
}
dates.forEach((date) => {
const dateMonth = date.format('YYYY-MM');
amountsMap[dateMonth]++;
});
let tmpAmount = 0;
return Object.keys(amountsMap).map((month) => {
.then((quote) => {
debug('got quote response', quote)
if (!quote) {
throw new Error('Got empty quote response from the connector')
}
return {
sourceAmount: String(quote.sourceAmount),
connectorAccount: quote.connectorAccount,
destinationAmount: String(request.amount),
destinationAccount: request.address,
destinationMemo: {
data: request.data,
expires_at: request.expires_at
},
expiresAt: moment.min([
moment(request.expires_at),
moment().add(maxHoldDuration, 'seconds')
]).toISOString(),
executionCondition: request.condition
}
})
}
id: result._itemId,
title: result.title
};
queryFolder(folder, worker);
}
else if (result.type == 'bookmark' && result.location.indexOf('javascript') != 0) {
let file = PageThumbsStorage.getFileForURL(result.location);
let uri = Services.io.newFileURI(file);
let bookmark = {
group: result.folder,
location: result.location,
title: result.title || result.location,
tags: result.tags,
icon: result.icon,
thumb: uri.spec,
added: moment(result.dateAdded).calendar(),
visited: moment(result.time).calendar(),
visits: result.accessCount
};
bookmarks[result.position] = bookmark;
}
},
onComplete: function() {
export function getTimeSlicesForHeader(unit:moment.unitOfTime.DurationConstructor,
startView:Moment,
endView:Moment) {
const slices:[Moment, Moment][] = [];
const time = startView.clone().startOf(unit);
const end = endView.clone().endOf(unit);
while (time.isBefore(end)) {
const sliceStart = moment.max(time, startView).clone();
const sliceEnd = moment.min(time.clone().endOf(unit), endView).clone();
time.add(1, unit);
slices.push([sliceStart, sliceEnd]);
}
return slices;
}
paint: function (spinner, rawValue) {
var max = spinner.max;
var min = spinner.min;
var format = spinner.format;
if (spinner.format === 'number') {
rawValue = parseToNum(rawValue);
rawValue = Math.max(rawValue, min);
rawValue = Math.min(rawValue, max);
}
else {
rawValue = m(rawValue, format);
if (rawValue.isValid()) {
rawValue = m.max(rawValue, min);
rawValue = m.min(rawValue, max);
}
else {
rawValue = min;
}
rawValue = m(rawValue, format).format(format);
}
setInputValue.call(spinner, rawValue);
}
},
function formatPhaseCardListFooterProps(phases) {
const startDates = _.compact(phases.map((phase) =>
phase.startDate ? moment(phase.startDate) : null
))
const endDates = _.compact(phases.map((phase) =>
phase.endDate ? moment(phase.endDate) : null
))
const minStartDate = startDates.length > 0 ? moment.min(startDates) : null
const maxEndDate = endDates.length > 0 ? moment.max(endDates) : null
let startEndDates = minStartDate ? `${minStartDate.format('MMM D')}` : ''
startEndDates += minStartDate && maxEndDate ? `–${maxEndDate.format('MMM D')}` : ''
const totalPrice = _.sum(phases.map((phase) => _.get(phase, 'budget', 0)))
const duration = `${minStartDate && maxEndDate ? maxEndDate.diff(minStartDate, 'days') + 1 : 0} days`
const price = `$${formatNumberWithCommas(totalPrice)}`
return {
duration,
startEndDates,
price,
}
}