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

The following examples show how to use org.joda.time.LocalDate#isEqual() . 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: UnixTimestampRecursiveCopyableDataset.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(Path path) {

  LocalDate endDate = currentTime.toLocalDate();
  LocalDate startDate = endDate.minus(lookbackPeriod);
  Path relativePath = PathUtils.relativizePath(PathUtils.getPathWithoutSchemeAndAuthority(path), datasetRoot());
  Matcher matcher = timestampPattern.matcher(relativePath.toString());
  if (!matcher.matches()) {
    return false;
  }
  Long timestamp = Long.parseLong(matcher.group(1));
  LocalDate dateOfTimestamp = new LocalDateTime(timestamp, dateTimeZone).toLocalDate();
  return !(dateOfTimestamp == null || dateOfTimestamp.isAfter(endDate) || dateOfTimestamp.isEqual(startDate)
      || dateOfTimestamp.isBefore(startDate));
}
 
Example 2
Source File: LegionBoardParser.java    From substitution-schedule-parser with Mozilla Public License 2.0 4 votes vote down vote up
void parseLegionBoard(SubstitutionSchedule substitutionSchedule, JSONArray changes, JSONArray courses,
                         JSONArray teachers) throws IOException, JSONException {
       if (changes == null) {
		return;
	}
	// Link course IDs to their names
	HashMap<String, String> coursesHashMap = null;
	if (courses != null) {
		coursesHashMap = new HashMap<>();
		for (int i = 0; i < courses.length(); i++) {
			JSONObject course = courses.getJSONObject(i);
			coursesHashMap.put(course.getString("id"), course.getString("name"));
		}
	}
	// Link teacher IDs to their names
	HashMap<String, String> teachersHashMap = null;
	if (teachers != null) {
		teachersHashMap = new HashMap<>();
		for (int i = 0; i < teachers.length(); i++) {
			JSONObject teacher = teachers.getJSONObject(i);
			teachersHashMap.put(teacher.getString("id"), teacher.getString("name"));
		}
	}
	// Add changes to SubstitutionSchedule
	LocalDate currentDate = LocalDate.now();
	SubstitutionScheduleDay substitutionScheduleDay = new SubstitutionScheduleDay();
	substitutionScheduleDay.setDate(currentDate);
	for (int i = 0; i < changes.length(); i++) {
		final JSONObject change = changes.getJSONObject(i);
		final Substitution substitution = getSubstitution(change, coursesHashMap, teachersHashMap);
		final LocalDate startingDate = new LocalDate(change.getString("startingDate"));
		final LocalDate endingDate = new LocalDate(change.getString("endingDate"));
		// Handle multi-day changes
		if (!startingDate.isEqual(endingDate)) {
			if (!substitutionScheduleDay.getSubstitutions().isEmpty()) {
				substitutionSchedule.addDay(substitutionScheduleDay);
			}
			for (int k = 0; k < 8; k++) {
				final LocalDate date = LocalDate.now().plusDays(k);
				if ((date.isAfter(startingDate) || date.isEqual(startingDate)) &&
					(date.isBefore(endingDate) || date.isEqual(endingDate))) {
					substitutionScheduleDay = new SubstitutionScheduleDay();
					substitutionScheduleDay.setDate(date);
					substitutionScheduleDay.addSubstitution(substitution);
					substitutionSchedule.addDay(substitutionScheduleDay);
                       currentDate = date;
                   }
			}
			continue;
		}
		// If starting date of change does not equal date of SubstitutionScheduleDay
		if (!startingDate.isEqual(currentDate)) {
			if (!substitutionScheduleDay.getSubstitutions().isEmpty()) {
				substitutionSchedule.addDay(substitutionScheduleDay);
			}
			substitutionScheduleDay = new SubstitutionScheduleDay();
			substitutionScheduleDay.setDate(startingDate);
               currentDate = startingDate;
           }
		substitutionScheduleDay.addSubstitution(substitution);
	}
	substitutionSchedule.addDay(substitutionScheduleDay);
}
 
Example 3
Source File: IphisParser.java    From substitution-schedule-parser with Mozilla Public License 2.0 4 votes vote down vote up
void parseIphis(SubstitutionSchedule substitutionSchedule, JSONArray changes, JSONArray grades,
                JSONArray teachers, JSONArray messages) throws IOException, JSONException {
    if (changes == null) {
        return;
    }
    // Link course IDs to their names
    HashMap<String, String> coursesHashMap = null;
    if (grades != null) {
        coursesHashMap = new HashMap<>();
        for (int i = 0; i < grades.length(); i++) {
            JSONObject grade = grades.getJSONObject(i);
            coursesHashMap.put(grade.getString("id"), grade.getString("name"));
        }
    }
    // Link teacher IDs to their names
    HashMap<String, String> teachersHashMap = null;
    if (teachers != null) {
        teachersHashMap = new HashMap<>();
        for (int i = 0; i < teachers.length(); i++) {
            JSONObject teacher = teachers.getJSONObject(i);
            teachersHashMap.put(teacher.getString("id"), teacher.getString("name"));
        }
    }

    // Add Messages
    List<AdditionalInfo> infos = new ArrayList<>(messages.length());

    for (int i = 0; i < messages.length(); i++) {
        JSONObject message = messages.getJSONObject(i);
        AdditionalInfo info = new AdditionalInfo();
        info.setHasInformation(message.getBoolean("notification"));
        info.setTitle(message.getString("titel").trim());
        info.setText(message.getString("nachricht").trim());
        info.setFromSchedule(true);
        infos.add(info);
    }

    substitutionSchedule.getAdditionalInfos().addAll(infos);
    substitutionSchedule.setLastChange(lastUpdate);

    // Add changes to SubstitutionSchedule
    LocalDate currentDate = LocalDate.now();
    SubstitutionScheduleDay substitutionScheduleDay = new SubstitutionScheduleDay();
    substitutionScheduleDay.setDate(currentDate);
    for (int i = 0; i < changes.length(); i++) {
        final JSONObject change = changes.getJSONObject(i);
        final LocalDate substitutionDate = new LocalDate(change.getString("datum"));

        // If starting date of change does not equal date of SubstitutionScheduleDay
        if (!substitutionDate.isEqual(currentDate)) {
            if (!substitutionScheduleDay.getSubstitutions().isEmpty()
                    || !substitutionScheduleDay.getMessages().isEmpty()) {
                substitutionSchedule.addDay(substitutionScheduleDay);
            }
            substitutionScheduleDay = new SubstitutionScheduleDay();
            substitutionScheduleDay.setDate(substitutionDate);
            currentDate = substitutionDate;
        }

        if (change.getInt("id") > 0) {
            final Substitution substitution = getSubstitution(change, coursesHashMap, teachersHashMap);

            substitutionScheduleDay.addSubstitution(substitution);
        } else if (!change.optString("nachricht").isEmpty()) {
            substitutionScheduleDay.addMessage(change.optString("nachricht"));
        }
    }
    substitutionSchedule.addDay(substitutionScheduleDay);
}
 
Example 4
Source File: ExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean canEdit() {
    LocalDate todayDate = new LocalDate();
    LocalDate maxDate = getMaxDateCanEdit();
    return todayDate.isBefore(maxDate) || todayDate.isEqual(maxDate);
}