java.time.Period.negated()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中java.time.Period.negated()方法的一些代码示例,展示了Period.negated()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Period.negated()方法的具体详情如下:
包路径:java.time.Period
类名称:Period
方法名:negated

Period.negated介绍

[英]Returns a new instance with each amount in this period negated.
[中]返回一个新实例,该期间的每个金额都为负数。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Supports the unary minus operator; equivalent to calling the {@link java.time.Period#negated()} method.
 *
 * @param self a Period
 * @return a negated Period
 * @since 2.5.0
 */
public static Period negative(final Period self) {
  return self.negated();
}

代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions

public static Period negative(Period p) {
  return p.negated();
}

代码示例来源:origin: com.jtransc/jtransc-rt

public static Period parse(CharSequence text) {
  final Pattern pattern = Pattern.compile("^(-?)P((-?[0-9]+)Y)?((-?[0-9]+)M)?((-?[0-9]+)D)?$");
  final Matcher matcher = pattern.matcher(text);
  if (!matcher.matches()) throw new DateTimeParseException("Text cannot be parsed to a Period", text, 0);
  final boolean globalNegate = Objects.equals(matcher.group(1), "-");
  final String yearsStr = matcher.group(3);
  final String monthsStr = matcher.group(5);
  final String daysStr = matcher.group(7);
  final int years = (yearsStr != null) ? Integer.parseInt(yearsStr) : 0;
  final int months = (monthsStr != null) ? Integer.parseInt(monthsStr) : 0;
  final int days = (daysStr != null) ? Integer.parseInt(daysStr) : 0;
  final Period period = _of(years, months, days);
  return globalNegate ? period.negated() : period;
}

代码示例来源:origin: goldmansachs/jdmn

protected TemporalAmount toTemporalPeriod(Duration duration) {
  Period period = Period.of(duration.getYears(), duration.getMonths(), duration.getDays());
  return duration.getSign() == -1 ? period.negated() : period;
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

protected TemporalAmount toTemporalPeriod(Duration duration) {
  Period period = Period.of(duration.getYears(), duration.getMonths(), duration.getDays());
  return duration.getSign() == -1 ? period.negated() : period;
}

代码示例来源:origin: ical4j/ical4j

public static TemporalAmountAdapter from(Dur dur) {
  TemporalAmount duration;
  if (dur.getWeeks() > 0) {
    Period p = Period.ofWeeks(dur.getWeeks());
    if (dur.isNegative()) {
      p = p.negated();
    }
    duration = p;
  } else {
    Duration d = Duration.ofDays(dur.getDays())
        .plusHours(dur.getHours())
        .plusMinutes(dur.getMinutes())
        .plusSeconds(dur.getSeconds());
    if (dur.isNegative()) {
      d = d.negated();
    }
    duration = d;
  }
  return new TemporalAmountAdapter(duration);
}

代码示例来源:origin: org.mnode.ical4j/ical4j

public static TemporalAmountAdapter from(Dur dur) {
  TemporalAmount duration;
  if (dur.getWeeks() > 0) {
    Period p = Period.ofWeeks(dur.getWeeks());
    if (dur.isNegative()) {
      p = p.negated();
    }
    duration = p;
  } else {
    Duration d = Duration.ofDays(dur.getDays())
        .plusHours(dur.getHours())
        .plusMinutes(dur.getMinutes())
        .plusSeconds(dur.getSeconds());
    if (dur.isNegative()) {
      d = d.negated();
    }
    duration = d;
  }
  return new TemporalAmountAdapter(duration);
}

相关文章