public ZonedDateTime minusMonths(long amount) { return dt.minusMonths(amount); }
public ZonedDateTime minusMonths(long amount) { return dt.minusMonths(amount); }
public ZonedDateTime minusMonths(long amount) { return dt.minusMonths(amount); }
public static ZonedDateTime getFirstOfLastMonth( ZoneId z ) { Instant instant = Instant.now(); return getFirstOfPreviousMonth( instant , z ); } public static ZonedDateTime getFirstOfPreviousMonth( Instant instantArg , ZoneId zoneArg ) { ZonedDateTime zdt = instantArg.atZone( zoneArg); ZonedDateTime firstOfMonthZdt = zdt.with( TemporalAdjusters.firstDayOfMonth() ); ZonedDateTime firstOfMonthPriorZdt = firstOfMonthZdt.minusMonths( 1 ); return firstOfMonthPriorZdt; }
/** * Method to subtract month from given timestamp. * @param timestamp timestamp in minutes * @param n number of months to subtract * @return timestamp with subtracted months */ public static Integer subtractMonth(Integer timestamp, int n) { ZonedDateTime zonedDateTime = TimeUtils.zonedDateTimeFromMinutes(timestamp); zonedDateTime = zonedDateTime.minusMonths(n); return (int) TimeUtils.zonedDateTimestamp(zonedDateTime) / 60; } }
@Override public Payload body(Context context) { String uri = context.uri(); URL url = webJarUrlFinder.url(uri); return new Payload(url) .withHeader(CACHE_CONTROL, "public, max-age=31536000") .withHeader(LAST_MODIFIED, RFC_1123_DATE_TIME.format(now().minusMonths(1L))) .withHeader(EXPIRES, RFC_1123_DATE_TIME.format(now().plusWeeks(1L))); }
public boolean collect(Ledger ledger, Config config) { if(!config.getStatsIntervalSmall().equals(smallInterval) || !config.getStatsIntervalBig().equals(bigInterval)) { //intervals changed. need to reset node init(ledger,config); return false; } ZonedDateTime now = ZonedDateTime.now(); Map<ItemState, Integer> lastIntervalStats = ledger.getLedgerSize(lastStatsBuildTime); ledgerStatsHistory.addLast(lastIntervalStats); ledgerHistoryTimestamps.addLast(lastStatsBuildTime); smallIntervalApproved = lastIntervalStats.getOrDefault(ItemState.APPROVED,0)+lastIntervalStats.getOrDefault(ItemState.REVOKED,0); bigIntervalApproved += smallIntervalApproved; uptimeApproved += smallIntervalApproved; lastIntervalStats.keySet().forEach(is -> ledgerSize.put(is, ledgerSize.getOrDefault(is,0) + lastIntervalStats.get(is))); while (ledgerHistoryTimestamps.getFirst().plus(bigInterval).isBefore(now)) { ledgerHistoryTimestamps.removeFirst(); bigIntervalApproved -= ledgerStatsHistory.removeFirst().get(ItemState.APPROVED) + lastIntervalStats.getOrDefault(ItemState.REVOKED,0); } lastStatsBuildTime = now; Map<Integer, Integer> payments = ledger.getPayments(now.truncatedTo(ChronoUnit.DAYS).minusDays(now.getDayOfMonth()-1).minusMonths(1)); payments.keySet().forEach( day -> { }); return true; }
private ZonedDateTime toEndOfPreviousMonth(final ZonedDateTime datetime) { final ZonedDateTime previousMonth = datetime.minusMonths(1).with(lastDayOfMonth()); final int highestHour = hours.getValues().get(hours.getValues().size() - 1); final int highestMinute = minutes.getValues().get(minutes.getValues().size() - 1); final int highestSecond = seconds.getValues().get(seconds.getValues().size() - 1); return ZonedDateTime .of(previousMonth.getYear(), previousMonth.getMonth().getValue(), previousMonth.getDayOfMonth(), highestHour, highestMinute, highestSecond, 0, previousMonth.getZone()); }
private ExecutionTimeResult getPreviousPotentialYear(final ZonedDateTime date, final TimeNode days, final int highestMonth, int highestDay, final int highestHour, final int highestMinute, final int highestSecond) throws NoSuchValueException { NearestValue nearestValue; ZonedDateTime newDate; final int previousYear = yearsValueGenerator.generatePreviousValue(date.getYear()); if (highestDay > 28) { final int highestDayOfMonth = LocalDate.of(previousYear, highestMonth, 1).lengthOfMonth(); if (highestDay > highestDayOfMonth) { nearestValue = days.getPreviousValue(highestDay, 1); if (nearestValue.getShifts() > 0) { newDate = ZonedDateTime.of( LocalDate.of(previousYear, highestMonth, 1), MAX_SECONDS, date.getZone() ).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth()); return new ExecutionTimeResult(newDate, false); } else { highestDay = nearestValue.getValue(); } } } return new ExecutionTimeResult(ZonedDateTime.of( LocalDate.of(previousYear, highestMonth, highestDay), LocalTime.of(highestHour, highestMinute, highestSecond), date.getZone()), false); }
/** * Decrement a zoned date time by a certain * amount of this granularity. * * @param date zoned date time to decrease * @param amount the number of times to decrease * @return copy of the zoned date time */ public ZonedDateTime decrement(ZonedDateTime date, int amount) { switch (this) { case MINUTE: return date.minusMinutes(amount); case HOUR: return date.minusHours(amount); case DAY: return date.minusDays(amount); case WEEK: return date.minusWeeks(amount); case MONTH: return date.minusMonths(amount); default: return date.minusHours(amount); } }
/** * Subtract granularity intervals of this type * from a given date time. * * @param now the time to subtract intervals from * @param intervals the number of intervals to subtract * @param granularityRange range of granularity to aggregate on * @return a copied ZonedDateTime with the intervals subtracted */ public ZonedDateTime subtractIntervals(ZonedDateTime now, int intervals, int granularityRange) { int n = intervals - (intervals % granularityRange); switch (this) { case MINUTE: return now.minusMinutes(n); case HOUR: return now.minusHours(n); case DAY: return now.minusDays(n); case WEEK: return now.minusWeeks(n); case MONTH: return now.minusMonths(n); default: return now.minusHours(n); } }
private ExecutionTimeResult getPreviousPotentialDayOfMonth(final ZonedDateTime date, final TimeNode days, final int highestHour, final int highestMinute, final int highestSecond) { NearestValue nearestValue = days.getPreviousValue(date.getDayOfMonth(), 0); if (nearestValue.getShifts() > 0) { ZonedDateTime newDate = ZonedDateTime.of( LocalDate.of(date.getYear(), date.getMonthValue(), 1), MAX_SECONDS, date.getZone() ).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth()); return new ExecutionTimeResult(newDate, false); } return new ExecutionTimeResult(date.withDayOfMonth(nearestValue.getValue()) .with(LocalTime.of(highestHour, highestMinute, highestSecond)).truncatedTo(SECONDS), false); }
); ZonedDateTime past = reference.minusMonths( 1 ).minusHours( 1 ); dummy = new PastRelativePartialDummyEntity( past );
@Override public ZonedDateTime dateAddDuration(ZonedDateTime date, Duration duration) { if (date == null || duration == null) { return null; } try { int years = duration.getYears(); int months = duration.getMonths(); int days = duration.getDays(); if (duration.getSign() == -1) { return date .minusYears(years) .minusMonths(months) .minusDays(days); } else { return date .plusYears(years) .plusMonths(months) .plusDays(days); } } catch (Throwable e) { String message = String.format("dateAdd(%s, %s)", date, duration); logError(message, e); return null; } }
@Override public ZonedDateTime dateSubtractDuration(ZonedDateTime date, Duration duration) { if (date == null || duration == null) { return null; } try { int years = duration.getYears(); int months = duration.getMonths(); int days = duration.getDays(); if (duration.getSign() == -1) { return date .plusYears(years) .plusMonths(months) .plusDays(days); } else { return date .minusYears(years) .minusMonths(months) .minusDays(days); } } catch (Throwable e) { String message = String.format("dateSubtract(%s, %s)", date, duration); logError(message, e); return null; } }
@Test public void test123() throws Exception { ZonedDateTime now = ZonedDateTime.now(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.appendValue(ChronoField.DAY_OF_MONTH,2); builder.appendLiteral("/"); builder.appendValue(ChronoField.MONTH_OF_YEAR,2); builder.appendLiteral("/"); builder.appendValue(ChronoField.YEAR,4); System.out.println(now.format(builder.toFormatter())); System.out.println(now.truncatedTo(ChronoUnit.DAYS).format(builder.toFormatter())); System.out.println(now.truncatedTo(ChronoUnit.DAYS).minusDays(now.getDayOfMonth()-1).format(builder.toFormatter())); System.out.println(now.truncatedTo(ChronoUnit.DAYS).minusDays(now.getDayOfMonth()-1).minusMonths(1).format(builder.toFormatter())); }
@Override public ZonedDateTime dateAddDuration(ZonedDateTime date, Duration duration) { if (date == null || duration == null) { return null; } try { int years = duration.getYears(); int months = duration.getMonths(); int days = duration.getDays(); if (duration.getSign() == -1) { return date .minusYears(years) .minusMonths(months) .minusDays(days); } else { return date .plusYears(years) .plusMonths(months) .plusDays(days); } } catch (Throwable e) { String message = String.format("dateAdd(%s, %s)", date, duration); logError(message, e); return null; } }
@Override public ZonedDateTime dateSubtractDuration(ZonedDateTime date, Duration duration) { if (date == null || duration == null) { return null; } try { int years = duration.getYears(); int months = duration.getMonths(); int days = duration.getDays(); if (duration.getSign() == -1) { return date .plusYears(years) .plusMonths(months) .plusDays(days); } else { return date .minusYears(years) .minusMonths(months) .minusDays(days); } } catch (Throwable e) { String message = String.format("dateSubtract(%s, %s)", date, duration); logError(message, e); return null; } }
@Test public void paymentSaveTest() throws Exception { try (PooledDb db = (PooledDb) ledger.getDb()) { try (PreparedStatement statement = db.statement("delete from payments_summary;") ) { statement.executeUpdate(); } } NodeStats stats = new NodeStats(); Config config = new Config(); stats.init(ledger,config); ZonedDateTime now = ZonedDateTime.now(); ZonedDateTime dateTime = now.minusDays(now.getDayOfMonth()-1).minusMonths(1); while (dateTime.isBefore(ZonedDateTime.now().plusSeconds(1))) { ledger.savePayment(100,dateTime); ledger.savePayment(100,dateTime); dateTime = dateTime.plusDays(1); } stats.collect(ledger,config); //assertEquals(stats.todayPaidAmount,200); //assertEquals(stats.yesterdayPaidAmount,200); //assertEquals(stats.thisMonthPaidAmount,200*now.getDayOfMonth()); //assertEquals(stats.lastMonthPaidAmount,200*now.minusMonths(1).getMonth().length(now.getYear() % 4 == 0)); }
return dateTime .minusYears(years) .minusMonths(months) .minusDays(days) .minusHours(hours)