本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}