下面列出了org.joda.time.LocalDate#isBefore ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static List<Interval> intervalsInRange(
final LocalDate startDate,
final LocalDate endDate,
final String rrule) {
if (startDate.compareTo(endDate) > 0) {
throw new IllegalArgumentException(
String.format("Start date %s is after end date %s", startDate.toString(), endDate.toString()));
}
List<Interval> intervals = Lists.newArrayList();
LocalDate start = startDate;
Interval interval = null;
do {
interval = intervalContaining(start, rrule);
if (interval != null) {
intervals.add(interval);
start = interval.getEnd().toLocalDate();
}
} while (interval != null && start.isBefore(endDate));
return intervals;
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
int counter = 0;
int quantity = checkDate.weekOfWeekyear().getMaximumValue()/2;
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(2))) && counter < quantity) {
String year = checkDate.year().getAsString();
String cDate = checkDate.toString();
String nDate = checkDate.plusWeeks(2).minusDays(1).toString();
String date = String.format(DATE_FORMAT, year, periodApi, counter+1);
String label = String.format(DATE_LABEL_FORMAT, periodHumanReedable, counter+1, cDate, nDate);
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
counter++;
checkDate = checkDate.plusWeeks(2);
}
Collections.reverse(dates);
return dates;
}
public String validateTerminate(
final LocalDate terminationDate) {
if (terminationDate.isBefore(getStartDate())) {
return "Termination date can't be before start date";
}
return null;
}
private LocalDate getAvailableDate(LocalDate localDate) {
if (localDate.isBefore(mStartDate)) {
return mStartDate;
} else if (localDate.isAfter(mEndDate)) {
return mEndDate;
} else {
return localDate;
}
}
private int getExpiryDays(int expiryDay){
LocalDate periodDate = new LocalDate();
LocalDate periodInitRange = new LocalDate();
periodInitRange = periodInitRange.withWeekOfWeekyear(1);
do{
periodInitRange = periodInitRange.plusWeeks(2).withDayOfWeek(DateTimeConstants.MONDAY);
} while (periodInitRange.isBefore(periodDate));
periodInitRange = periodInitRange.minusWeeks(2);
return Days.daysBetween(periodInitRange.minusDays(1), new LocalDate()).getDays() + expiryDay;
}
public String validateChangeEffectiveDates(
final LocalDate effectiveStartDate,
final LocalDate effectiveEndDate){
if (effectiveStartDate!=null && effectiveEndDate!=null && effectiveEndDate.isBefore(effectiveStartDate)){
return "The end date is before the start date";
}
return null;
}
public void aggregateTurnoversForLease(final Lease lease, final LocalDate startDate, final LocalDate endDate, final boolean maintainOnly){
//since we analyze all previous and next leases with all associated configs, any config with type prelimninary and frequency monthly will do
TurnoverReportingConfig firstConfigCandidate = null;
for (Occupancy o : lease.getOccupancies()){
final TurnoverReportingConfig c = turnoverReportingConfigRepository
.findByOccupancyAndTypeAndFrequency(o, Type.PRELIMINARY, Frequency.MONTHLY).stream().findFirst()
.orElse(null);
if (c!=null && firstConfigCandidate==null ){
firstConfigCandidate = c;
}
}
if (firstConfigCandidate==null) return;
LocalDate startDateToUse = startDate==null || startDate.isBefore(MIN_AGGREGATION_DATE) ? MIN_AGGREGATION_DATE.minusMonths(23).withDayOfMonth(1) : startDate.withDayOfMonth(1);
LocalDate endDateToUse = endDate==null ? clockService.now().withDayOfMonth(1).plusMonths(23) : endDate.withDayOfMonth(1);
if (endDateToUse.isBefore(startDateToUse)) return;
// since we look 24 months ahead the aggregations to be made are
List<LocalDate> turnoverDates = new ArrayList<>();
turnoverDates.add(startDateToUse.withDayOfMonth(1));
LocalDate d = startDateToUse.plusMonths(24);
while (!d.isAfter(endDateToUse)){
turnoverDates.add(d.withDayOfMonth(1));
d = d.plusMonths(24);
}
if (turnoverDates.isEmpty()) return;
if (maintainOnly){
aggregate(turnoverDates.get(0), firstConfigCandidate, null, true);
} else {
for (LocalDate toDate : turnoverDates) {
aggregate(toDate, firstConfigCandidate, null, maintainOnly);
}
}
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
int counter = 0;
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(6))) && counter < 2) {
String year = checkDate.year().getAsString();
String label;
String date;
if (checkDate.getMonthOfYear() > JUN) {
label = String.format(DATE_LABEL_FORMAT, JUL_STR_LONG, DEC_STR_LONG, year);
date = year + S2;
} else {
label = String.format(DATE_LABEL_FORMAT, JAN_STR_LONG, JUN_STR_LONG, year);
date = year + S1;
}
checkDate = checkDate.plusMonths(6);
counter++;
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
}
Collections.reverse(dates);
return dates;
}
@Action()
public Occupancy $$(final LocalDate startDate, final LocalDate endDate) {
if (!endDate.isBefore(startDate)){
final List<TurnoverReportingConfig> configs = turnoverReportingConfigRepository.findByOccupancy(occupancy);
LocalDate date = startDate;
while (!date.isAfter(endDate)){
for (TurnoverReportingConfig config : configs){
config.produceEmptyTurnover(date);
}
date = date.plusDays(1);
}
}
return occupancy;
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
int counter = 0;
int quantity = checkDate.dayOfYear().getMaximumValue();
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate)) && counter < quantity) {
String date = checkDate.toString(DATE_FORMAT);
String dName = checkDate.dayOfMonth().getAsString();
String mName = checkDate.monthOfYear().getAsText();
String yName = checkDate.year().getAsString();
String label = String.format(DATE_LABEL_FORMAT, dName, mName, yName);
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
counter++;
checkDate = checkDate.plusDays(1);
}
Collections.reverse(dates);
return dates;
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
int counter = 0;
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(3))) && counter < 4) {
String label;
String date;
int cMonth = checkDate.getMonthOfYear();
String cYearStr = checkDate.year().getAsString();
if (cMonth < MAR) {
date = cYearStr + Q1;
label = String.format(DATE_LABEL_FORMAT, JAN_STR, MAR_STR, cYearStr);
} else if ((cMonth >= MAR) && (cMonth < JUN)) {
date = cYearStr + Q2;
label = String.format(DATE_LABEL_FORMAT, APR_STR, JUN_STR, cYearStr);
} else if ((cMonth >= JUN) && (cMonth < SEP)) {
date = cYearStr + Q3;
label = String.format(DATE_LABEL_FORMAT, JUL_STR, SEP_STR, cYearStr);
} else {
date = cYearStr + Q4;
label = String.format(DATE_LABEL_FORMAT, OCT_STR, DEC_STR, cYearStr);
}
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
checkDate = checkDate.plusMonths(3);
counter++;
}
Collections.reverse(dates);
return dates;
}
static public LocalDate parseDate(String value) {
if (StringUtils.isEmpty(value)) {
return null;
}
if (value.length() < 2) {
return null;
}
LocalDate result = null;
String normalizedValue = value;
if (value.length() == "dMMyyyy".length()) {
normalizedValue = "0".concat(value);
}
for (String pattern : CORRECT_DATE_PATTERNS) {
try {
result = DateTimeFormat.forPattern(pattern).parseDateTime(normalizedValue).toLocalDate();
} catch (IllegalArgumentException e) {
continue;
}
if (result.isAfter(DateTimeFormat.forPattern("yyyy").parseDateTime("1920").toLocalDate())
&& result.isBefore(DateTimeFormat.forPattern("yyy").parseDateTime("2020").toLocalDate())) {
return result;
}
}
throw new IncorrectDateFormatException(value);
}
public String validateRenew(
final String reference,
final String name,
final LocalDate startDate,
final LocalDate endDate
) {
if (endDate.isBefore(startDate)) {
return "End date can not be before start date.";
}
return leaseRepository.findLeaseByReferenceElseNull(reference) == null ? null : "Lease reference already exists.";
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
int counter = 0;
int quantity = checkDate.weekOfWeekyear().getMaximumValue();
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(1).minusDays(1))) && counter < quantity) {
String year = checkDate.year().getAsString();
String cWeekNumber = "" + (Integer.parseInt(checkDate.weekOfWeekyear().getAsString())+ 1 );
String cDate = checkDate.toString();
String nDate = checkDate.plusWeeks(1).minusDays(1).toString();
String date = String.format(DATE_FORMAT, year, W, cWeekNumber);
String label = String.format(DATE_LABEL_FORMAT, W, cWeekNumber, cDate, nDate);
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
counter++;
checkDate = checkDate.plusWeeks(1);
}
Collections.reverse(dates);
return dates;
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
int counter = 0;
int quantity = checkDate.weekOfWeekyear().getMaximumValue();
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(1).minusDays(1))) && counter < quantity) {
String year = checkDate.year().getAsString();
String cWeekNumber = "" + (Integer.parseInt(checkDate.weekOfWeekyear().getAsString())+ 1 );
String cDate = checkDate.toString();
String nDate = checkDate.plusWeeks(1).minusDays(1).toString();
String date = String.format(DATE_FORMAT, year, W, cWeekNumber);
String label = String.format(DATE_LABEL_FORMAT, W, cWeekNumber, cDate, nDate);
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
counter++;
checkDate = checkDate.plusWeeks(1);
}
Collections.reverse(dates);
return dates;
}
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);
}
private String validateNewProject(final String reference, final LocalDate startDate, final LocalDate endDate) {
if (projectRepository.findByReference(reference) != null)
return "There is already a project with this reference";
return startDate != null && endDate != null && !startDate.isBefore(endDate) ? "End date must be after start date" : null;
}
public String validate$$(final LocalDate startDate, final LocalDate endDate, final boolean maintainOnly){
if (startDate!=null && endDate!=null){
if (endDate.isBefore(startDate)) return "The end date cannot be before the start date";
}
return null;
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
int counter = 0;
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
checkDate = new LocalDate(cPeriod);
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(2))) && counter < 6) {
int cMonth = checkDate.getMonthOfYear();
String year = checkDate.year().getAsString();
String date;
String label;
if (cMonth < FEB) {
date = year + B1;
label = String.format(DATE_LABEL_FORMAT, JAN_STR, FEB_STR, year);
} else if ((cMonth >= FEB) && (cMonth < APR)) {
date = year + B2;
label = String.format(DATE_LABEL_FORMAT, MAR_STR, APR_STR, year);
} else if ((cMonth >= APR) && (cMonth < JUN)) {
date = year + B3;
label = String.format(DATE_LABEL_FORMAT, MAY_STR, JUN_STR, year);
} else if ((cMonth >= JUN) && (cMonth < AUG)) {
date = year + B4;
label = String.format(DATE_LABEL_FORMAT, JUL_STR, AUG_STR, year);
} else if ((cMonth >= AUG) && (cMonth < OCT)) {
date = year + B5;
label = String.format(DATE_LABEL_FORMAT, SEP_STR, OCT_STR, year);
} else {
date = year + B6;
label = String.format(DATE_LABEL_FORMAT, NOV_STR, DEC_STR, year);
}
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
dates.add(dateHolder);
}
counter++;
checkDate = checkDate.plusMonths(2);
}
Collections.reverse(dates);
return dates;
}
public String validateDownloadToExcelForAllProperties(final LocalDate startDate, final LocalDate endDate, final Country country, final String fileName) {
if (endDate.isBefore(startDate))
return "End date cannot be before start date";
return null;
}