public ZonedDateTime minusWeeks(long amount) { return dt.minusWeeks(amount); }
public ZonedDateTime minusWeeks(long amount) { return dt.minusWeeks(amount); }
public ZonedDateTime minusWeeks(long amount) { return dt.minusWeeks(amount); }
final ZonedDateTime input = ZonedDateTime.now(); System.out.println(input); final ZonedDateTime startOfLastWeek = input.minusWeeks(1).with(DayOfWeek.MONDAY); System.out.println(startOfLastWeek); final ZonedDateTime endOfLastWeek = startOfLastWeek.plusDays(6); System.out.println(endOfLastWeek);
final ZonedDateTime input = ZonedDateTime.now(); for(int i = 1; i < 10; i++) { final ZonedDateTime startOfLastWeek = input.minusWeeks(i).with(DayOfWeek.MONDAY); System.out.print(startOfLastWeek.format(DateTimeFormatter.ISO_LOCAL_DATE)); final ZonedDateTime endOfLastWeek = startOfLastWeek.plusDays(6); System.out.println(" - " + endOfLastWeek.format(DateTimeFormatter.ISO_LOCAL_DATE)); }
ZoneId z = ZoneId.of( "America/Montreal" ); ZonedDateTime now = ZonedDateTime.now( z ); ZonedDateTime start = now.minusWeeks( 1 ); // Simulating input. ZonedDateTime stop = now.plusWeeks( 2 ); // Simulating input.
/** * 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); } }
@Test public void testWeeks() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusWeeks(1); String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime2 = zTime.minusWeeks(7); String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT); Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time)); Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1)); Literal nowMinusSeven = VF.createLiteral(dtf.newXMLGregorianCalendar(time2)); DateTimeWithinPeriod func = new DateTimeWithinPeriod(); assertEquals(TRUE, func.evaluate(VF, now, now, VF.createLiteral(1), OWLTime.WEEKS_URI)); assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne, VF.createLiteral(1), OWLTime.WEEKS_URI)); assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne, VF.createLiteral(2), OWLTime.WEEKS_URI)); assertEquals(FALSE, func.evaluate(VF, now, nowMinusSeven, VF.createLiteral(7), OWLTime.WEEKS_URI)); }