下面列出了怎么用org.joda.time.YearMonthDay的API类实例代码及写法,或者点击链接到github查看源代码。
private void reportRaides(final Spreadsheet sheet, final Registration registration,
StudentCurricularPlan studentCurricularPlan, List<Registration> registrationPath,
ExecutionYear executionYear, final CycleType cycleType, final boolean concluded, final YearMonthDay conclusionDate) {
final Row row =
RaidesCommonReportFieldsWrapper.reportRaidesFields(sheet, registration, studentCurricularPlan, registrationPath,
executionYear, cycleType, concluded, conclusionDate, null, false);
// Total de ECTS concluídos até ao fim do ano lectivo anterior ao que se referem os dados no curso actual
double totalEctsConcludedUntilPreviousYear = studentCurricularPlan.getInternalCycleCurriculumGrops().stream()
.mapToDouble(cycleCurriculumGroup -> cycleCurriculumGroup.getCreditsConcluded(executionYear.getPreviousExecutionYear()))
.sum();
// Total de ECTS necessários para a conclusão
if (concluded) {
row.setCell(0);
} else {
row.setCell(studentCurricularPlan.getRoot().getDefaultEcts(executionYear) - totalEctsConcludedUntilPreviousYear);
}
}
private void logSetterNullYearMonthDay(String keyInfoType, YearMonthDay oldValue, YearMonthDay newValue, String keyLabel) {
Object argNew, argOld;
String strNew, strOld;
argOld = valueToUpdateIfNewNotNull(BundleUtil.getString(Bundle.HTML, "text.dateEmpty"), oldValue);
argNew = valueToUpdateIfNewNotNull(BundleUtil.getString(Bundle.HTML, "text.dateEmpty"), newValue);
if (argOld instanceof YearMonthDay) {
strOld = ((YearMonthDay) argOld).toString("yyyy/MM/dd");
} else {
strOld = (String) argOld;
}
if (argNew instanceof YearMonthDay) {
strNew = ((YearMonthDay) argNew).toString("yyyy/MM/dd");
} else {
strNew = (String) argNew;
}
logSetter(keyInfoType, strOld, strNew, keyLabel);
}
private void testAdd(String start, DurationFieldType type, int amt, String end) {
DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC));
DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC));
assertEquals(dtEnd, dtStart.withFieldAdded(type, amt));
assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt));
DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC));
int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis());
assertEquals(amt, diff);
if (type == DurationFieldType.years() ||
type == DurationFieldType.months() ||
type == DurationFieldType.days()) {
YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC));
YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC));
assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt));
assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt));
}
}
@Override
public YearMonthDay calculateConclusionDate() {
if (getCredits().getOfficialDate() != null) {
return new YearMonthDay(getCredits().getOfficialDate());
}
final SortedSet<IEnrolment> iEnrolments = new TreeSet<IEnrolment>(IEnrolment.COMPARATOR_BY_APPROVEMENT_DATE);
iEnrolments.addAll(getSourceIEnrolments());
final YearMonthDay beginDate = getExecutionPeriod().getBeginDateYearMonthDay();
if (!iEnrolments.isEmpty()) {
final IEnrolment enrolment = iEnrolments.last();
final YearMonthDay approvementDate = enrolment.getApprovementDate();
return approvementDate != null ? approvementDate : beginDate;
} else {
return beginDate;
}
}
public ActionForward prepareCreateAcademicCalendar(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear();
Partial begin;
Partial end;
if (currentExecutionYear != null) {
begin = CalendarEntryBean.getPartialFromYearMonthDay(currentExecutionYear.getBeginDateYearMonthDay());
end = CalendarEntryBean.getPartialFromYearMonthDay(currentExecutionYear.getEndDateYearMonthDay());
} else {
begin = CalendarEntryBean.getPartialFromYearMonthDay(new YearMonthDay());
end = CalendarEntryBean.getPartialFromYearMonthDay(new YearMonthDay().plusMonths(3));
}
CalendarEntryBean bean = CalendarEntryBean.createAcademicCalendarBean(begin, end);
request.setAttribute("parentEntryBean", bean);
return mapping.findForward("prepareCreateCalendarEntry");
}
@Override
public List<Interval> getEventSpaceOccupationIntervals(YearMonthDay startDateToSearch, YearMonthDay endDateToSearch) {
List<Interval> result = new ArrayList<Interval>();
Collection<LessonInstance> lessonInstances = getLessonInstancesSet();
DateTime startDateTime = startDateToSearch != null ? startDateToSearch.toDateTimeAtMidnight() : null;
DateTime endDateTime = endDateToSearch != null ? endDateToSearch.toDateTime(new TimeOfDay(23, 59, 59)) : null;
for (LessonInstance lessonInstance : lessonInstances) {
if (startDateTime == null
|| (!lessonInstance.getEndDateTime().isBefore(startDateTime) && !lessonInstance.getBeginDateTime().isAfter(
endDateTime))) {
result.add(new Interval(lessonInstance.getBeginDateTime(), lessonInstance.getEndDateTime()));
}
}
return result;
}
@Override
protected Collection search(String value, int size) {
Collection<UnitName> units = super.search(value, size);
List<Unit> result = new ArrayList<Unit>();
YearMonthDay now = new YearMonthDay();
for (UnitName unitName : units) {
Unit unit = unitName.getUnit();
if (unit.isActive(now)) {
result.add(unit);
}
}
return result;
}
private void init(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate) {
checkParameters(registration, degreeCurricularPlan, startDate);
setDegreeCurricularPlan(degreeCurricularPlan);
setRegistration(registration);
setStartDateYearMonthDay(startDate);
}
public AdministrativeOfficeFeePR(DateTime startDate, DateTime endDate, ServiceAgreementTemplate serviceAgreementTemplate,
Money fixedAmount, Money fixedAmountPenalty, YearMonthDay whenToApplyFixedAmountPenalty) {
this();
init(EntryType.ADMINISTRATIVE_OFFICE_FEE, EventType.ADMINISTRATIVE_OFFICE_FEE, startDate, endDate,
serviceAgreementTemplate, fixedAmount, fixedAmountPenalty, whenToApplyFixedAmountPenalty);
}
private YearMonthDay getLessonStartDay() {
if (!wasFinished()) {
YearMonthDay periodBegin = getPeriod().getStartYearMonthDay();
return getValidBeginDate(periodBegin);
}
return null;
}
public SortedSet<YearMonthDay> getAllLessonDatesUntil(YearMonthDay day) {
SortedSet<YearMonthDay> result = new TreeSet<YearMonthDay>();
if (day != null) {
result.addAll(getAllLessonInstanceDatesUntil(day));
if (!wasFinished()) {
YearMonthDay startDateToSearch = getLessonStartDay();
YearMonthDay lessonEndDay = getLessonEndDay();
YearMonthDay endDateToSearch = (lessonEndDay.isAfter(day)) ? day : lessonEndDay;
result.addAll(getAllValidLessonDatesWithoutInstancesDates(startDateToSearch, endDateToSearch));
}
}
return result;
}
public void reuse(final YearMonthDay startDate, final YearMonthDay endDate, final Money minAmount, final Money maxAmount,
final Event event) {
reuseCode();
update(startDate, endDate, minAmount, maxAmount);
super.setAccountingEvent(event);
}
private List<Unit> getParentUnitsByState(YearMonthDay currentDate, boolean state) {
List<Unit> allParentUnits = new ArrayList<>();
for (Unit subUnit : this.getParentUnits()) {
if (subUnit.isActive(currentDate) == state) {
allParentUnits.add(subUnit);
}
}
return allParentUnits;
}
public AdministrativeOfficeFeePR edit(DateTime startDate, Money fixedAmount, Money penaltyAmount,
YearMonthDay whenToApplyFixedAmountPenalty) {
if (!startDate.isAfter(getStartDate())) {
throw new DomainException(
"error.AdministrativeOfficeFeePR.startDate.is.before.then.start.date.of.previous.posting.rule");
}
deactivate(startDate);
return new AdministrativeOfficeFeePR(startDate.minus(1000), null, getServiceAgreementTemplate(), fixedAmount,
penaltyAmount, whenToApplyFixedAmountPenalty);
}
public PartialRegimeInstallment(FullGratuityPaymentPlanForPartialRegime paymentPlan, Money amount, YearMonthDay startDate,
YearMonthDay endDate, BigDecimal penaltyPercentage, YearMonthDay whenStartToApplyPenalty,
Integer maxMonthsToApplyPenalty, BigDecimal ectsForAmount, List<ExecutionSemester> executionSemesters) {
this();
init(paymentPlan, amount, startDate, endDate, true, penaltyPercentage, whenStartToApplyPenalty, maxMonthsToApplyPenalty,
ectsForAmount, executionSemesters);
}
private void refreshPeriodAndInstancesInEditOperation(YearMonthDay newBeginDate, YearMonthDay newEndDate,
Boolean createLessonInstances, GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod) {
removeExistentInstancesWithoutSummaryAfterOrEqual(newBeginDate);
SortedSet<YearMonthDay> instanceDates =
getAllLessonInstancesDatesToCreate(getLessonStartDay(), newBeginDate.minusDays(1), createLessonInstances);
refreshPeriod(newBeginDate, newEndDate);
createAllLessonInstances(instanceDates);
}
private boolean contains(Interval interval, SortedSet<YearMonthDay> allLessonDates) {
YearMonthDay intervalStartDate = interval.getStart().toYearMonthDay();
YearMonthDay intervalEndDate = interval.getEnd().toYearMonthDay();
HourMinuteSecond intervalBegin =
new HourMinuteSecond(interval.getStart().getHourOfDay(), interval.getStart().getMinuteOfHour(), interval
.getStart().getSecondOfMinute());
HourMinuteSecond intervalEnd =
new HourMinuteSecond(interval.getEnd().getHourOfDay(), interval.getEnd().getMinuteOfHour(), interval.getEnd()
.getSecondOfMinute());
for (YearMonthDay day : allLessonDates) {
if (intervalStartDate.isEqual(intervalEndDate)) {
if (day.isEqual(intervalStartDate) && !intervalBegin.isAfter(getEndHourMinuteSecond())
&& !intervalEnd.isBefore(getBeginHourMinuteSecond())) {
return true;
}
} else {
if ((day.isAfter(intervalStartDate) && day.isBefore(intervalEndDate)) || day.isEqual(intervalStartDate)
&& !getEndHourMinuteSecond().isBefore(intervalBegin)
|| (day.isEqual(intervalEndDate) && !getBeginHourMinuteSecond().isAfter(intervalEnd))) {
return true;
}
}
}
return false;
}
@Deprecated
public void setEndDate(java.util.Date date) {
if (date == null) {
setEndDateYearMonthDay(null);
} else {
setEndDateYearMonthDay(org.joda.time.YearMonthDay.fromDateFields(date));
}
}
protected void enrolStudentInCurricularCourses(final ExecutionDegree executionDegree, final Registration registration) {
final ExecutionSemester executionSemester = getExecutionPeriod();
final StudentCurricularPlan studentCurricularPlan =
StudentCurricularPlan.createBolonhaStudentCurricularPlan(registration, executionDegree.getDegreeCurricularPlan(),
new YearMonthDay(), executionSemester);
studentCurricularPlan.createFirstTimeStudentEnrolmentsFor(executionSemester, getCurrentUsername());
registration.updateEnrolmentDate(executionSemester.getExecutionYear());
}
protected DateTime getInstant(boolean firstInstant, YearMonthDay begin, final YearMonthDay end,
final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency,
final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday, final Boolean dailyFrequencyMarkSunday) {
DateTime instantResult = null;
begin = getBeginDateInSpecificWeekDay(diaSemana, begin);
if (frequency == null) {
if (!begin.isAfter(end)) {
if (firstInstant) {
return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
} else {
return end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
}
}
} else {
int numberOfDaysToSum = frequency.getNumberOfDays();
while (true) {
if (begin.isAfter(end)) {
break;
}
DateTime intervalEnd = begin.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
if (!frequency.equals(FrequencyType.DAILY)
|| ((dailyFrequencyMarkSaturday || intervalEnd.getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || intervalEnd
.getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {
if (firstInstant) {
return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
} else {
instantResult = intervalEnd;
}
}
begin = begin.plusDays(numberOfDaysToSum);
}
}
return instantResult;
}
final public StudentCurricularPlan getStudentCurricularPlan(final YearMonthDay date) {
StudentCurricularPlan result = null;
for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) {
final YearMonthDay startDate = studentCurricularPlan.getStartDateYearMonthDay();
if (!startDate.isAfter(date) && (result == null || startDate.isAfter(result.getStartDateYearMonthDay()))) {
result = studentCurricularPlan;
}
}
return result;
}
@Atomic
public static void run(Lesson lesson, YearMonthDay day) {
check(RolePredicates.RESOURCE_ALLOCATION_MANAGER_PREDICATE);
if (lesson != null && day != null) {
lesson.deleteLessonInstanceIn(day);
}
}
@Deprecated
public void setEnrollmentBeginDayDate(java.util.Date date) {
if (date == null) {
setEnrollmentBeginDayDateYearMonthDay(null);
} else {
setEnrollmentBeginDayDateYearMonthDay(org.joda.time.YearMonthDay.fromDateFields(date));
}
}
@Override
public YearMonthDay calculateConclusionDate() {
if (!isApproved()) {
throw new DomainException("error.Enrolment.not.approved");
}
return EvaluationConfiguration.getInstance().getEnrolmentEvaluationForConclusionDate(this)
.map(EnrolmentEvaluation::getExamDateYearMonthDay).orElse(null);
}
public InstallmentForFirstTimeStudents(final PaymentPlan paymentPlan, final Money amount, final YearMonthDay startDate,
final YearMonthDay endDate, final BigDecimal penaltyPercentage, final Integer maxMonthsToApplyPenalty,
final Integer numberOfDaysToStartApplyingPenalty) {
this();
init(paymentPlan, amount, startDate, endDate, penaltyPercentage, maxMonthsToApplyPenalty,
numberOfDaysToStartApplyingPenalty);
}
private FiliationForm(YearMonthDay dateOfBirth, String districtOfBirth, String districtSubdivisionOfBirth, String fatherName,
String motherName, Country nationality, String parishOfBirth, Country countryOfBirth) {
this();
this.dateOfBirth = dateOfBirth;
this.districtOfBirth = districtOfBirth;
this.districtSubdivisionOfBirth = districtSubdivisionOfBirth;
this.fatherName = fatherName;
this.motherName = motherName;
setNationality(nationality);
this.parishOfBirth = parishOfBirth;
setCountryOfBirth(countryOfBirth);
}
private YearMonthDay getLessonEndDay() {
if (!wasFinished()) {
YearMonthDay periodEnd = getPeriod().getLastOccupationPeriodOfNestedPeriods().getEndYearMonthDay();
return getValidEndDate(periodEnd);
}
return null;
}
@Override
public void setSummaryDateYearMonthDay(YearMonthDay summaryDateYearMonthDay) {
if (summaryDateYearMonthDay == null) {
throw new DomainException("error.summary.no.date");
}
super.setSummaryDateYearMonthDay(summaryDateYearMonthDay);
}
public static ExecutionYear readBy(final YearMonthDay begin, YearMonthDay end) {
for (final ExecutionYear executionYear : Bennu.getInstance().getExecutionYearsSet()) {
if (executionYear.getBeginDateYearMonthDay().isEqual(begin) && executionYear.getEndDateYearMonthDay().isEqual(end)) {
return executionYear;
}
}
return null;
}
public InfoLessonInstanceAggregation(final Shift shift, final Lesson lesson, final YearMonthDay yearMonthDay) {
this.shift = shift;
this.weekDay = yearMonthDay.toDateMidnight().getDayOfWeek();
this.begin = lesson.getBeginHourMinuteSecond();
this.end = lesson.getEndHourMinuteSecond();
this.allocatableSpace = lesson.getSala();
}