/** * Returns a copy of this {@code LocalDateTime} with the specified period in days subtracted. * <p> * This method subtracts the specified amount from the days field incrementing the * month and year fields as necessary to ensure the result remains valid. * The result is only invalid if the maximum/minimum year is exceeded. * <p> * For example, 2009-01-01 minus one day would result in 2008-12-31. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to subtract, may be negative * @return a {@code LocalDateTime} based on this date-time with the days subtracted, not null * @throws DateTimeException if the result exceeds the supported date range */ public LocalDateTime minusDays(long days) { return (days == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-days)); }
/** * Returns a copy of this {@code LocalDateTime} with the specified period in days subtracted. * <p> * This method subtracts the specified amount from the days field incrementing the * month and year fields as necessary to ensure the result remains valid. * The result is only invalid if the maximum/minimum year is exceeded. * <p> * For example, 2009-01-01 minus one day would result in 2008-12-31. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to subtract, may be negative * @return a {@code LocalDateTime} based on this date-time with the days subtracted, not null * @throws DateTimeException if the result exceeds the supported date range */ public LocalDateTime minusDays(long days) { return (days == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-days)); }
/** * Returns a copy of this OffsetDateTime with the specified period in days added. * <p> * This method adds the specified amount to the days field incrementing the * month and year fields as necessary to ensure the result remains valid. * The result is only invalid if the maximum/minimum year is exceeded. * <p> * For example, 2008-12-31 plus one day would result in the 2009-01-01. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, may be negative * @return an {@code OffsetDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public OffsetDateTime plusDays(long days) { return with(dateTime.plusDays(days), offset); }
/** * Returns a copy of this OffsetDateTime with the specified period in days added. * <p> * This method adds the specified amount to the days field incrementing the * month and year fields as necessary to ensure the result remains valid. * The result is only invalid if the maximum/minimum year is exceeded. * <p> * For example, 2008-12-31 plus one day would result in the 2009-01-01. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, may be negative * @return an {@code OffsetDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public OffsetDateTime plusDays(long days) { return with(dateTime.plusDays(days), offset); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in days added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusDays(long) adding days} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, may be negative * @return a {@code ZonedDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime plusDays(long days) { return resolveLocal(dateTime.plusDays(days)); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in days added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusDays(long) adding days} to the local date-time. * This is then converted back to a {@code ZonedDateTime}, using the zone ID * to obtain the offset. * <p> * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap, * then the offset will be retained if possible, otherwise the earlier offset will be used. * If in a gap, the local date-time will be adjusted forward by the length of the gap. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to add, may be negative * @return a {@code ZonedDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime plusDays(long days) { return resolveLocal(dateTime.plusDays(days)); }
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)
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)
@Override public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages, Set<String> allowedSubtypes) { 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, allowedSubtypes); case PRIVATE_GROUP: return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND, allowedSubtypes); default: return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND, allowedSubtypes); } }
LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days); instantSecs = ldt.toEpochSecond(ZoneOffset.UTC); instantSecs += Jdk8Methods.safeMultiply(yearParsed / 10000L, SECONDS_PER_10000_YEARS);
LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days); instantSecs = ldt.toEpochSecond(ZoneOffset.UTC); instantSecs += Jdk8Methods.safeMultiply(yearParsed / 10000L, SECONDS_PER_10000_YEARS);