How to use the moment.min function in moment

To help you get started, we’ve selected a few moment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github choerodon / test-manager-service / react / src / app / testManager / store / project / TestPlan / TestPlanStore.js View on Github external
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),
          });
github opf / openproject / frontend / src / app / features / work-packages / components / wp-table / timeline / container / wp-timeline-container.directive.ts View on Github external
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);
    });
github GetStream / react-activity-feed / src / utils.js View on Github external
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);
}
github opf / openproject / frontend / app / components / wp-table / timeline / header / wp-timeline-header.directive.ts View on Github external
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);
    }
  }
github s0ph1e / star-history / src / modules / repoStars.js View on Github external
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) => {
github interledgerjs / ilp / src / lib / sender.js View on Github external
.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
        }
      })
  }
github cleercode / mozaic / src / lib / bookmarks.js View on Github external
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() {
github opf / openproject / frontend / src / app / components / work-packages / exporter / ExportTimelineHeaderRenderer.ts View on Github external
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;
}
github ecomfe / esui-family / dep / ub-ria-ui / 1.0.0-beta.3 / src / Spinner.js View on Github external
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);
                        }
                    },
github appirio-tech / connect-app / src / projects / detail / components / ProjectStages.jsx View on Github external
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,
  }
}