Java Code Examples for org.joda.time.LocalDate#minusDays()

The following examples show how to use org.joda.time.LocalDate#minusDays() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String[] times = {this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2), this.times.get(prefix + 3),
                this.times.get(prefix + 4), this.times.get(prefix + 5)};
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.plusDays(1);
        }
        i++;
        date = date.minusDays(1);
    }
}
 
Example 2
Source File: WebTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public LocalDate getLastSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String[] times = {this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2), this.times.get(prefix + 3),
                this.times.get(prefix + 4), this.times.get(prefix + 5)};
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.minusDays(1);
        }
        i++;
        date = date.plusDays(1);
    }
}
 
Example 3
Source File: Times.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public LocalDateTime getTime(@NonNull LocalDate date, int time) {
    while (time < 0) {
        date = date.minusDays(1);
        time += Vakit.LENGTH;
    }

    while (time >= Vakit.LENGTH) {
        date = date.plusDays(1);
        time -= Vakit.LENGTH;
    }
    LocalDateTime dt = parseTime(date, getStrTime(date, Vakit.getByIndex(time))).plusMinutes(getMinuteAdj()[time]);


    int h = dt.getHourOfDay();
    if ((time >= Vakit.DHUHR.ordinal()) && (h < 5)) {
        dt = dt.plusDays(1);
    }
    return dt;
}
 
Example 4
Source File: Spec11RegistrarThreatMatchesParser.java    From nomulus with Apache License 2.0 6 votes vote down vote up
public Optional<LocalDate> getPreviousDateWithMatches(LocalDate date) {
  LocalDate yesterday = date.minusDays(1);
  GcsFilename gcsFilename = getGcsFilename(yesterday);
  if (gcsUtils.existsAndNotEmpty(gcsFilename)) {
    return Optional.of(yesterday);
  }
  logger.atWarning().log("Could not find previous file from date %s", yesterday);

  for (LocalDate dateToCheck = yesterday.minusDays(1);
      !dateToCheck.isBefore(date.minusMonths(1));
      dateToCheck = dateToCheck.minusDays(1)) {
    gcsFilename = getGcsFilename(dateToCheck);
    if (gcsUtils.existsAndNotEmpty(gcsFilename)) {
      return Optional.of(dateToCheck);
    }
  }
  return Optional.empty();
}
 
Example 5
Source File: WebTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String[] times = {this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2), this.times.get(prefix + 3),
                this.times.get(prefix + 4), this.times.get(prefix + 5)};
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.plusDays(1);
        }
        i++;
        date = date.minusDays(1);
    }
}
 
Example 6
Source File: Times.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public LocalDateTime getTime(@NonNull LocalDate date, int time) {
    while (time < 0) {
        date = date.minusDays(1);
        time += Vakit.LENGTH;
    }

    while (time >= Vakit.LENGTH) {
        date = date.plusDays(1);
        time -= Vakit.LENGTH;
    }
    LocalDateTime dt = parseTime(date, getStrTime(date, Vakit.getByIndex(time))).plusMinutes(getMinuteAdj()[time]);


    int h = dt.getHourOfDay();
    if ((time >= Vakit.DHUHR.ordinal()) && (h < 5)) {
        dt = dt.plusDays(1);
    }
    return dt;
}
 
Example 7
Source File: OrderMenu.java    From estatio with Apache License 2.0 5 votes vote down vote up
OrderMenu.OrderFinder filterOrFindByOrderDate(final LocalDate orderDate) {
    if (orderDate == null)
        return this;
    LocalDate orderDateStart = orderDate.minusDays(5);
    LocalDate orderDateEnd = orderDate.plusDays(5);
    if (!this.result.isEmpty()) {
        filterByOrderDate(orderDateStart, orderDateEnd);
    } else {
        createResultForOrderDate(orderDateStart, orderDateEnd);
    }
    return this;
}
 
Example 8
Source File: LocalDateForwardUnlessNegativeHandler.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
public LocalDate adjustDate(LocalDate startDate, int increment, NonWorkingDayChecker<LocalDate> checker) {
    LocalDate date = startDate;
    while (checker.isNonWorkingDay(date)) {
        if (increment < 0) {
            // act as a Backward calendar
            date = date.minusDays(1);
        } else {
            // move forward by a day!
            date = date.plusDays(1);
        }
    }
    return date;
}
 
Example 9
Source File: ExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditDateWithMorePlusDaysThanExpiryDays() {
    LocalDate todayDate = new LocalDate();
    int expiryDays = 5;
    todayDate = todayDate.minusDays(expiryDays + 1);
    ExpiryDayValidator expiryDayValidator = new ExpiryDayValidator(expiryDays,
            todayDate.toString(PATTERN));
    assertFalse(expiryDayValidator.canEdit());
}
 
Example 10
Source File: ExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanEditDateWithLessMinusDaysThanExpiryDays() {
    LocalDate todayDate = new LocalDate();
    int expiryDays = 5;
    todayDate = todayDate.minusDays(expiryDays - 1);
    ExpiryDayValidator expiryDayValidator = new ExpiryDayValidator(expiryDays,
            todayDate.toString(PATTERN));
    assertTrue(expiryDayValidator.canEdit());
}
 
Example 11
Source File: ExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditWithPeriodWithSameMinusDaysAsExpiryDays() {
    LocalDate todayDate = new LocalDate();
    int expiryDays = 5;
    todayDate = todayDate.minusDays(expiryDays);
    ExpiryDayValidator expiryDayValidator = new ExpiryDayValidator(expiryDays,
            todayDate.toString(PATTERN));
    assertFalse(expiryDayValidator.canEdit());
}
 
Example 12
Source File: WeekIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WeekIterator(int openFP, String[] dataInputPeriods) {
    super(dataInputPeriods);
    openFuturePeriods = openFP;
    cPeriod = new LocalDate(currentDate.withWeekOfWeekyear(1).withDayOfWeek(1));
    checkDate = new LocalDate(cPeriod);
    maxDate = new LocalDate(currentDate.getYear(), currentDate.getMonthOfYear(), currentDate.getDayOfMonth());
    maxDate = maxDate.minusDays(currentDate.getDayOfWeek());
    for (int i = 0; i < openFuturePeriods; i++) {
        maxDate = maxDate.plusWeeks(1);
    }
}
 
Example 13
Source File: BiWeekIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BiWeekIterator(int openFP, String[] dataInputPeriods) {
    super(dataInputPeriods);
    openFuturePeriods = openFP;
    cPeriod = new LocalDate(currentDate.withWeekOfWeekyear(1).withDayOfWeek(1));
    checkDate = new LocalDate(cPeriod);
    maxDate = new LocalDate(currentDate.getYear(), currentDate.getMonthOfYear(), currentDate.getDayOfMonth());
    maxDate = maxDate.minusDays(currentDate.getDayOfWeek());
    if(openFuturePeriods>1) {
        for (int i = 0; i < (openFuturePeriods-1) / 2; i++) {
            maxDate = maxDate.plusWeeks(2);
        }
    }
}
 
Example 14
Source File: TurnoverReportingConfigRepository_IntegTest.java    From estatio with Apache License 2.0 5 votes vote down vote up
@Test
public void find_by_property_active_on_date_works() throws Exception {

    // given
    TurnoverReportingConfig config = turnoverReportingConfigRepository.listAll().get(0);
    final LocalDate occupancyStartDate = new LocalDate(2010, 7, 15);
    assertThat(config.getOccupancy().getStartDate()).isEqualTo(occupancyStartDate);
    assertThat(config.getStartDate()).isEqualTo(new LocalDate(2014,1,2));

    // when, then
    final LocalDate firstDayOfOccupancyMonth = new LocalDate(2010, 7, 1);
    assertThat(turnoverReportingConfigRepository.findByPropertyActiveOnDate(Property_enum.OxfGb.findUsing(serviceRegistry2), firstDayOfOccupancyMonth)).hasSize(0);

    // and when
    config.setStartDate(occupancyStartDate);
    // then
    assertThat(turnoverReportingConfigRepository.findByPropertyActiveOnDate(Property_enum.OxfGb.findUsing(serviceRegistry2), firstDayOfOccupancyMonth)).hasSize(1);
    final LocalDate lastDayOfOccupancyMonth = new LocalDate(2010, 7, 31);
    assertThat(turnoverReportingConfigRepository.findByPropertyActiveOnDate(Property_enum.OxfGb.findUsing(serviceRegistry2), lastDayOfOccupancyMonth)).hasSize(1);

    // and when
    final LocalDate lastDayOfPreviousOccupancyMonth = firstDayOfOccupancyMonth.minusDays(1);
    // then
    assertThat(turnoverReportingConfigRepository.findByPropertyActiveOnDate(Property_enum.OxfGb.findUsing(serviceRegistry2), lastDayOfPreviousOccupancyMonth)).hasSize(0);

    // and when occupancy ends before next month
    config.getOccupancy().setEndDate(lastDayOfOccupancyMonth);
    final LocalDate firstDayOfNextOccupancyMonth = new LocalDate(2010, 8, 1);
    assertThat(turnoverReportingConfigRepository.findByPropertyActiveOnDate(Property_enum.OxfGb.findUsing(serviceRegistry2), firstDayOfNextOccupancyMonth)).hasSize(0);

}
 
Example 15
Source File: BiWeeklyPeriodFilter.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static DateTime getStartDayOfPreviousMonthBiWeek(DateTime date){
    LocalDate localDate = new LocalDate(getStartDayOfFirstBiWeek(date));
    localDate = localDate.minusDays(14);
    return localDate.toDateTimeAtStartOfDay();
}
 
Example 16
Source File: BiWeeklyPeriodFilter.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static DateTime getEndDayOfPreviousMonthBiWeek(DateTime date){
    DateTime startDay = getStartDayOfFirstBiWeek(date);
    LocalDate localDate = new LocalDate(startDay);
    localDate = localDate.minusDays( 14 );
    return localDate.toDateTimeAtStartOfDay();
}
 
Example 17
Source File: DateRange.java    From adwords-alerting with Apache License 2.0 4 votes vote down vote up
/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 */
private static DateRange parseEnumFormat(String dateRange) {
  ReportDefinitionDateRangeType dateRangeType;
  try {
    dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("Unknown DateRange type: " + dateRange);
  }

  LocalDate today = LocalDate.now();
  LocalDate startDate;
  LocalDate endDate;
  switch (dateRangeType) {
    case TODAY:
      startDate = endDate = today;
      break;
    case YESTERDAY:
      startDate = endDate = today.minusDays(1);
      break;
    case LAST_7_DAYS:
      startDate = today.minusDays(7);
      endDate = today.minusDays(1);
      break;
    case LAST_WEEK:
      LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
      startDate = lastWeekProp.withMinimumValue();
      endDate = lastWeekProp.withMaximumValue();
      break;
    case THIS_MONTH:
      LocalDate.Property thisMonthProp = today.dayOfMonth();
      startDate = thisMonthProp.withMinimumValue();
      endDate = thisMonthProp.withMaximumValue();
      break;
    case LAST_MONTH:
      LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
      startDate = lastMonthProp.withMinimumValue();
      endDate = lastMonthProp.withMaximumValue();
      break;
    case LAST_14_DAYS:
      startDate = today.minusDays(14);
      endDate = today.minusDays(1);
      break;
    case LAST_30_DAYS:
      startDate = today.minusDays(30);
      endDate = today.minusDays(1);
      break;
    case THIS_WEEK_SUN_TODAY:
      // Joda-Time uses the ISO standard Monday to Sunday week.
      startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
      endDate = today;
      break;
    case THIS_WEEK_MON_TODAY:
      startDate = today.dayOfWeek().withMinimumValue();
      endDate = today;
      break;
    case LAST_WEEK_SUN_SAT:
      startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
      endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
      break;
      // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
      throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange);
  }

  return new DateRange(startDate, endDate);
}
 
Example 18
Source File: SummariesControlAction.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
private List<DetailSummaryElement> getExecutionCourseResume(final ExecutionSemester executionSemester,
        Collection<Professorship> professorships) {
    List<DetailSummaryElement> allListElements = new ArrayList<DetailSummaryElement>();
    LocalDate today = new LocalDate();
    LocalDate oneWeekBeforeToday = today.minusDays(8);
    for (Professorship professorship : professorships) {
        BigDecimal lessonsGiven = EMPTY;
        BigDecimal summariesGiven = EMPTY;
        BigDecimal summariesGivenPercentage = EMPTY;
        BigDecimal notTaughtSummaries = EMPTY;
        BigDecimal notTaughtSummariesPercentage = EMPTY;
        BigDecimal onlineLessons = EMPTY;
        BigDecimal onlineLessonsPercentage = EMPTY;
        if (professorship.belongsToExecutionPeriod(executionSemester)) {
            for (Shift shift : professorship.getExecutionCourse().getAssociatedShifts()) {
                lessonsGiven = lessonsGiven.add(BigDecimal.valueOf(shift.getNumberOfLessonInstances()));

                // Get the number of summaries given
                summariesGiven = getSummariesGiven(professorship, shift, summariesGiven, oneWeekBeforeToday);
                // Get the number of not taught summaries
                notTaughtSummaries = getNotTaughtSummaries(professorship, shift, notTaughtSummaries, oneWeekBeforeToday);
                // Get the number of online lessons
                onlineLessons = getOnlineLessons(professorship, shift, onlineLessons, oneWeekBeforeToday);
            }
            summariesGiven = summariesGiven.setScale(1, RoundingMode.HALF_UP);
            notTaughtSummaries = notTaughtSummaries.setScale(1, RoundingMode.HALF_UP);
            onlineLessons = onlineLessons.setScale(1, RoundingMode.HALF_UP);

            if (lessonsGiven.signum() == 1) {
                summariesGivenPercentage = summariesGiven.divide(lessonsGiven, 3, BigDecimal.ROUND_CEILING)
                        .multiply(BigDecimal.valueOf(100));
                notTaughtSummariesPercentage = notTaughtSummaries.divide(lessonsGiven, 3, BigDecimal.ROUND_CEILING)
                        .multiply(BigDecimal.valueOf(100));
                onlineLessonsPercentage = onlineLessons.divide(lessonsGiven, 3, BigDecimal.ROUND_CEILING)
                        .multiply(BigDecimal.valueOf(100));
            }

            Teacher teacher = professorship.getTeacher();
            String categoryName = null;
            if (teacher != null) {
                final Optional<TeacherAuthorization> authorization =
                        teacher.getTeacherAuthorization(executionSemester.getAcademicInterval());

                categoryName =
                        authorization.isPresent() ? authorization.get().getTeacherCategory().getName().getContent() : null;

            }

            String siglas = getSiglas(professorship);

            String teacherEmail =
                    professorship.getPerson().getDefaultEmailAddress() != null ? professorship.getPerson()
                            .getDefaultEmailAddress().getPresentationValue() : null;

            DetailSummaryElement listElementDTO =
                    new DetailSummaryElement(professorship.getPerson().getName(), professorship.getExecutionCourse()
                            .getNome(), teacher != null ? teacher.getTeacherId() : null, teacherEmail, categoryName,
                            summariesGiven, notTaughtSummaries, onlineLessons, siglas, lessonsGiven, summariesGivenPercentage,
                            notTaughtSummariesPercentage, onlineLessonsPercentage);

            allListElements.add(listElementDTO);
        }
    }
    return allListElements;
}
 
Example 19
Source File: DateUtil.java    From flowable-engine with Apache License 2.0 3 votes vote down vote up
public static Date subtractDate(Object startDate, Object years, Object months, Object days) {

        LocalDate currentDate = new LocalDate(startDate);

        currentDate = currentDate.minusYears(intValue(years));
        currentDate = currentDate.minusMonths(intValue(months));
        currentDate = currentDate.minusDays(intValue(days));

        return currentDate.toDate();
    }
 
Example 20
Source File: DateUtil.java    From activiti6-boot2 with Apache License 2.0 3 votes vote down vote up
public static Date subtractDate(Date startDate, Integer years, Integer months, Integer days) {

        LocalDate currentDate = new LocalDate(startDate);

        currentDate = currentDate.minusYears(years);
        currentDate = currentDate.minusMonths(months);
        currentDate = currentDate.minusDays(days);

        return currentDate.toDate();
    }