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


Java ChronoUnit类代码示例

本文整理汇总了Java中org.threeten.bp.temporal.ChronoUnit的典型用法代码示例。如果您正苦于以下问题:Java ChronoUnit类的具体用法?Java ChronoUnit怎么用?Java ChronoUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getLastWeeksMessages

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
private List<SlackMessagePosted> getLastWeeksMessages() {
    SlackSession slackSession = getSlackSession();

    SlackChannel slackChannel = slackSession.findChannelByName("publicaties");

    ChannelHistoryModule channelHistoryModule = ChannelHistoryModuleFactory.createChannelHistoryModule(slackSession);

    List<SlackMessagePosted> lastWeeksMesages = IntStream.of(7, 6, 5, 4, 3, 2, 1)
            .mapToObj(daysAgo -> LocalDate.now().minus(daysAgo, ChronoUnit.DAYS))
            .flatMap(date -> getMessagesOfDay(slackChannel, channelHistoryModule, date))
            .collect(toList());

    try {
        slackSession.disconnect();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    return lastWeeksMesages;
}
 
开发者ID:bobvandenberge,项目名称:publicaties-generator,代码行数:21,代码来源:SlackAPI.java

示例2: fetchHistoryOfChannel

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
    Map<String, String> params = new HashMap<>();
    params.put("channel", channelId);
    if (day != null) {
        ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
        ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
        params.put("oldest", convertDateToSlackTimestamp(start));
        params.put("latest", convertDateToSlackTimestamp(end));
    }
    if (numberOfMessages > -1) {
        params.put("count", String.valueOf(numberOfMessages));
    } else {
        params.put("count", String.valueOf(DEFAULT_HISTORY_FETCH_SIZE));
    }
    SlackChannel channel =session.findChannelById(channelId);
    switch (channel.getType()) {
        case INSTANT_MESSAGING:
            return fetchHistoryOfChannel(params,FETCH_IM_HISTORY_COMMAND);
        case PRIVATE_GROUP:
            return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND);
        default:
            return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND);
    }
}
 
开发者ID:riversun,项目名称:slacklet,代码行数:26,代码来源:ChannelHistoryModuleImpl.java

示例3: generate_multi

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
static Map<LocalDate, String> generate_multi(LocalDate start_date, LocalDate end_date, String seed) {
    if (start_date.isAfter(end_date)) {
        throw new IllegalArgumentException();
    }

    int days = (int) (1 + ChronoUnit.DAYS.between(start_date, end_date));

    // Now let's generate one password for each day
    Map<LocalDate, String> password_list = new HashMap<>();
    LocalDate date = start_date;
    for (int i = 0; i < days; i++) {
        password_list.put(date, generate(date, seed));
        date = date.plusDays(1);
    }

    return password_list;
}
 
开发者ID:borfast,项目名称:arrispwgen-android,代码行数:18,代码来源:Arrispwgen.java

示例4: fetchHistoryOfChannel

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
    Map<String, String> params = new HashMap<>();
    params.put("channel", channelId);
    if (day != null) {
        ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
        ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
        params.put("oldest", convertDateToSlackTimestamp(start));
        params.put("latest", convertDateToSlackTimestamp(end));
    }
    if (numberOfMessages > -1) {
        params.put("count", String.valueOf(numberOfMessages));
    } else {
        params.put("count", String.valueOf(1000));
    }
    return fetchHistoryOfChannel(params);
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:18,代码来源:ChannelHistoryModuleImpl.java

示例5: formatCell

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
@Override
public List<Double[]> formatCell(NodalObjectsCurve value, ValueSpecification valueSpec, Object inlineKey) {
  if (value.size() != 0 && (value.getXData()[0] instanceof Tenor) && (value.getYData()[0] instanceof Double)) {
    final Tenor[] tenors = (Tenor[]) value.getXData();
    final Object[] ys = value.getYData();
    ParallelArrayBinarySort.parallelBinarySort(tenors, ys);
    List<Double[]> data = new ArrayList<>();
    for (int i = 0; i < tenors.length; i++) {
      double x = tenors[i].getPeriod().get(ChronoUnit.YEARS);
      data.add(new Double[] {x, (Double) ys[i]});
    }
    return data;
  } else {
    s_logger.info("Unable to format curve {}", value);
    return null;
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:NodalObjectsCurveFormatter.java

示例6: formatExpanded

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
private List<Double[]> formatExpanded(NodalObjectsCurve value) {
  if (value.size() != 0 && (value.getXData()[0] instanceof Tenor) && (value.getYData()[0] instanceof Double)) {
    final Tenor[] tenors = (Tenor[]) value.getXData();
    final Object[] ys = value.getYData();
    ParallelArrayBinarySort.parallelBinarySort(tenors, ys);
    int dataLength = tenors.length;
    Double[] xs = new Double[dataLength];
    for (int i = 0; i < dataLength; i++) {
      xs[i] = (double) tenors[i].getPeriod().get(ChronoUnit.YEARS);
    }
    List<Double[]> detailedData = new ArrayList<>();
    for (int i = 0; i < ys.length; i++) {
      detailedData.add(new Double[]{xs[i], (Double) ys[i]});
    }
    return detailedData;
  } else {
    s_logger.info("Unable to format curve {}", value);
    return null;
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:NodalObjectsCurveFormatter.java

示例7: convertUnit

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
private static TemporalUnit convertUnit(TimeUnit unit) {
  switch (unit) {
    case NANOSECONDS:
      return ChronoUnit.NANOS;
    case MICROSECONDS:
      return ChronoUnit.MICROS;
    case MILLISECONDS:
      return ChronoUnit.MILLIS;
    case SECONDS:
      return ChronoUnit.SECONDS;
    case MINUTES:
      return ChronoUnit.MINUTES;
    case HOURS:
      return ChronoUnit.HOURS;
    case DAYS:
      return ChronoUnit.DAYS;
    default:
      throw new IllegalArgumentException("Unexpected unit " + unit);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:HistoricalShockMarketDataSnapshot.java

示例8: getExpirationDateAsDate

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * Gets the card expiration date, as a java.util.Date object. Returns
 * null if no date is available.
 *
 * @return Card expiration date.
 */
public Date getExpirationDateAsDate()
{
  if (hasExpirationDate())
  {
    final LocalDateTime endOfMonth = expirationDate.atEndOfMonth()
      .atStartOfDay().plus(1, ChronoUnit.DAYS).minus(1, ChronoUnit.NANOS);
    final Instant instant = endOfMonth.atZone(ZoneId.systemDefault())
      .toInstant();
    final Date date = new Date(instant.toEpochMilli());
    return date;
  }
  else
  {
    return null;
  }
}
 
开发者ID:sualeh,项目名称:credit_card_number,代码行数:23,代码来源:ExpirationDate.java

示例9: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public YearMonth plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case MONTHS: return plusMonths(amountToAdd);
            case YEARS: return plusYears(amountToAdd);
            case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
            case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
            case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
            case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:21,代码来源:YearMonth.java

示例10: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Instant plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
            case MILLIS: return plusMillis(amountToAdd);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
            case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
            case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
            case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:23,代码来源:Instant.java

示例11: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * Returns a copy of this duration with the specified duration added.
 * <p>
 * The duration amount is measured in terms of the specified unit.
 * Only a subset of units are accepted by this method.
 * The unit must either have an {@link TemporalUnit#isDurationEstimated() exact duration} or
 * be {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the period, measured in terms of the unit, positive or negative
 * @param unit  the unit that the period is measured in, must have an exact duration, not null
 * @return a {@code Duration} based on this duration with the specified duration added, not null
 * @throws ArithmeticException if numeric overflow occurs
 */
public Duration plus(long amountToAdd, TemporalUnit unit) {
    Jdk8Methods.requireNonNull(unit, "unit");
    if (unit == DAYS) {
        return plus(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY), 0);
    }
    if (unit.isDurationEstimated()) {
        throw new DateTimeException("Unit must not have an estimated duration");
    }
    if (amountToAdd == 0) {
        return this;
    }
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plusSeconds((amountToAdd / (1000000L * 1000)) * 1000).plusNanos((amountToAdd % (1000000L * 1000)) * 1000);
            case MILLIS: return plusMillis(amountToAdd);
            case SECONDS: return plusSeconds(amountToAdd);
        }
        return plusSeconds(Jdk8Methods.safeMultiply(unit.getDuration().seconds, amountToAdd));
    }
    Duration duration = unit.getDuration().multipliedBy(amountToAdd);
    return plusSeconds(duration.getSeconds()).plusNanos(duration.getNano());
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:39,代码来源:Duration.java

示例12: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * Returns a copy of this time with the specified period added.
 * <p>
 * This method returns a new time based on this time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add hours, minutes or seconds.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return a {@code LocalTime} based on this time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
            case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusMinutes(amountToAdd);
            case HOURS: return plusHours(amountToAdd);
            case HALF_DAYS: return plusHours((amountToAdd % 2) * 12);
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:33,代码来源:LocalTime.java

示例13: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * Returns a copy of this date with the specified period added.
 * <p>
 * This method returns a new date based on this date with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return a {@code LocalDate} based on this date with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDate plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case DAYS: return plusDays(amountToAdd);
            case WEEKS: return plusWeeks(amountToAdd);
            case MONTHS: return plusMonths(amountToAdd);
            case YEARS: return plusYears(amountToAdd);
            case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
            case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
            case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
            case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:34,代码来源:LocalDate.java

示例14: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return a {@code LocalDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDateTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
            case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusMinutes(amountToAdd);
            case HOURS: return plusHours(amountToAdd);
            case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12);  // no overflow (256 is multiple of 2)
        }
        return with(date.plus(amountToAdd, unit), time);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:33,代码来源:LocalDateTime.java

示例15: plus

import org.threeten.bp.temporal.ChronoUnit; //导入依赖的package包/类
@SuppressWarnings("unchecked")
    @Override
    public ChronoDateImpl<D> plus(long amountToAdd, TemporalUnit unit) {
        if (unit instanceof ChronoUnit) {
            ChronoUnit f = (ChronoUnit) unit;
            switch (f) {
                case DAYS: return plusDays(amountToAdd);
                case WEEKS: return plusDays(Jdk8Methods.safeMultiply(amountToAdd, 7));
                case MONTHS: return plusMonths(amountToAdd);
                case YEARS: return plusYears(amountToAdd);
                case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
                case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
                case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
//                case ERAS: throw new DateTimeException("Unable to add era, standard calendar system only has one era");
//                case FOREVER: return (period == 0 ? this : (period > 0 ? LocalDate.MAX_DATE : LocalDate.MIN_DATE));
            }
            throw new DateTimeException(unit + " not valid for chronology " + getChronology().getId());
        }
        return (ChronoDateImpl<D>) getChronology().ensureChronoLocalDate(unit.addTo(this, amountToAdd));
    }
 
开发者ID:ThreeTen,项目名称:threetenbp,代码行数:21,代码来源:ChronoDateImpl.java


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