当前位置: 首页>>代码示例>>Java>>正文


Java DateTimeValueRange.getMinimum方法代码示例

本文整理汇总了Java中java.time.calendrical.DateTimeValueRange.getMinimum方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeValueRange.getMinimum方法的具体用法?Java DateTimeValueRange.getMinimum怎么用?Java DateTimeValueRange.getMinimum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.calendrical.DateTimeValueRange的用法示例。


在下文中一共展示了DateTimeValueRange.getMinimum方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPlusAdjustment

import java.time.calendrical.DateTimeValueRange; //导入方法依赖的package包/类
/**
 * Adds this period to the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code plus(PlusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will add the years, then months, then days, then nanos. Only non-zero amounts will be
 * added. If the date-time has a calendar system with a fixed number of months in a year, then the years and
 * months will be combined before being added.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to add
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doPlusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.plus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.plus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.plus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.plus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.plus(this.nanos, NANOS);
  }
  return dateTime;
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:41,代码来源:Period.java

示例2: doMinusAdjustment

import java.time.calendrical.DateTimeValueRange; //导入方法依赖的package包/类
/**
 * Subtracts this period from the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code minus(MinusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will subtract the years, then months, then days, then nanos. Only non-zero amounts will
 * be subtracted. If the date-time has a calendar system with a fixed number of months in a year, then the
 * years and months will be combined before being subtracted.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to subtract
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doMinusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.minus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.minus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.minus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.minus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.minus(this.nanos, NANOS);
  }
  return dateTime;
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:41,代码来源:Period.java

示例3: between

import java.time.calendrical.DateTimeValueRange; //导入方法依赖的package包/类
/**
 * Returns a {@code Period} consisting of the number of years, months, days, hours, minutes, seconds, and
 * nanoseconds between two {@code DateTimeAccessor} instances.
 * <p>
 * The start date is included, but the end date is not. Only whole years count. For example, from
 * {@code 2010-01-15} to {@code 2011-03-18} is one year, two months and three days.
 * <p>
 * This method examines the {@link ChronoField fields} {@code YEAR}, {@code MONTH_OF_YEAR},
 * {@code DAY_OF_MONTH} and {@code NANO_OF_DAY} The difference between each of the fields is calculated
 * independently from the others. At least one of the four fields must be present.
 * <p>
 * The four units are typically retained without normalization. However, years and months are normalized if
 * the range of months is fixed, as it is with ISO.
 * <p>
 * The result of this method can be a negative period if the end is before the start. The negative sign can
 * be different in each of the four major units.
 * 
 * @param start the start date, inclusive, not null
 * @param end the end date, exclusive, not null
 * @return the period between the date-times, not null
 * @throws DateTimeException if the two date-times do have similar available fields
 * @throws ArithmeticException if numeric overflow occurs
 */
public static Period between(DateTimeAccessor start, DateTimeAccessor end) {

  if (Chrono.from(start).equals(Chrono.from(end)) == false) {
    throw new DateTimeException("Unable to calculate period as date-times have different chronologies");
  }
  int years = 0;
  int months = 0;
  int days = 0;
  long nanos = 0;
  boolean valid = false;
  if (start.isSupported(YEAR)) {
    years = Jdk8Methods.safeToInt(Jdk8Methods.safeSubtract(end.getLong(YEAR), start.getLong(YEAR)));
    valid = true;
  }
  if (start.isSupported(MONTH_OF_YEAR)) {
    months = Jdk8Methods
        .safeToInt(Jdk8Methods.safeSubtract(end.getLong(MONTH_OF_YEAR), start.getLong(MONTH_OF_YEAR)));
    DateTimeValueRange startRange = Chrono.from(start).range(MONTH_OF_YEAR);
    DateTimeValueRange endRange = Chrono.from(end).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue() && startRange.equals(endRange)) {
      int monthCount = (int) (startRange.getMaximum() - startRange.getMinimum() + 1);
      long totMonths = ((long) months) + years * monthCount;
      months = (int) (totMonths % monthCount);
      years = Jdk8Methods.safeToInt(totMonths / monthCount);
    }
    valid = true;
  }
  if (start.isSupported(DAY_OF_MONTH)) {
    days = Jdk8Methods.safeToInt(Jdk8Methods.safeSubtract(end.getLong(DAY_OF_MONTH), start.getLong(DAY_OF_MONTH)));
    valid = true;
  }
  if (start.isSupported(NANO_OF_DAY)) {
    nanos = Jdk8Methods.safeSubtract(end.getLong(NANO_OF_DAY), start.getLong(NANO_OF_DAY));
    valid = true;
  }
  if (valid == false) {
    throw new DateTimeException("Unable to calculate period as date-times do not have any valid fields");
  }
  return create(years, months, days, nanos);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:64,代码来源:Period.java


注:本文中的java.time.calendrical.DateTimeValueRange.getMinimum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。