Example usage for org.joda.time YearMonthDay toDateTimeAtMidnight

List of usage examples for org.joda.time YearMonthDay toDateTimeAtMidnight

Introduction

In this page you can find the example usage for org.joda.time YearMonthDay toDateTimeAtMidnight.

Prototype

public DateTime toDateTimeAtMidnight() 

Source Link

Document

Converts this YearMonthDay to a full datetime at midnight using the default time zone.

Usage

From source file:com.moss.jodapersist.YearMonthDayUserType.java

License:Open Source License

public void nullSafeSet(PreparedStatement statement, Object value, int index)
        throws HibernateException, SQLException {
    YearMonthDay ymd = (YearMonthDay) value;

    if (ymd != null) {
        if (sqltype.equals(this.DB_FORMAT_NUMERIC)) {
            statement.setLong(index, yearMonthDayToLong(ymd));
        } else if (sqltype.equals(this.DB_FORMAT_DATETIME)) {
            Instant instant = ymd.toDateTimeAtMidnight().toInstant();

            if (timeOffset.equals(TIME_OFFSET_NOON)) {
                instant = instant.toDateTime(DateTimeZone.UTC).plusHours(12).toInstant();
            }/*w  ww. j av a2 s . c  o m*/

            statement.setTimestamp(index, new Timestamp(instant.getMillis()), storageCalendar);
        } else if (sqltype.equals(this.DB_FORMAT_STRING)) {
            statement.setString(index, ymd.toString());
        } else
            throw new Error("No valid sqlType specified!");
    } else {
        statement.setNull(index, getNullType());
    }
}

From source file:com.qubit.solution.fenixedu.integration.cgd.services.form43.CgdForm43Sender.java

License:Open Source License

private static Person createPerson(org.fenixedu.academic.domain.Person person) {
    Person personData = new Person();

    executeIfAllowed(person, CgdAuthorizationCodes.BASIC_INFO, () -> personData.setName(person.getName()));
    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_EMAIL, () -> personData
            .setEmail(objectFactory.createPersonEmail(person.getInstitutionalEmailAddressValue())));
    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_GENDER, () -> personData
            .setGenderCode(objectFactory.createPersonGenderCode(getCodeForGender(person.getGender()))));

    YearMonthDay dateOfBirthYearMonthDay = person.getDateOfBirthYearMonthDay();
    if (dateOfBirthYearMonthDay != null) {
        executeIfAllowed(person, CgdAuthorizationCodes.BASIC_INFO, () -> {
            try {
                personData.setBirthDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(
                        dateOfBirthYearMonthDay.toDateTimeAtMidnight().toGregorianCalendar()));
            } catch (DatatypeConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();/* ww w  .j  av a  2 s  .  c  o  m*/
            }
        });
    }
    executeIfAllowed(person, CgdAuthorizationCodes.BASIC_INFO, () -> personData
            .setFiscalNumber(objectFactory.createPersonFiscalNumber(person.getSocialSecurityNumber())));

    PersonalIngressionData personalIngressionDataByExecutionYear = person.getStudent()
            .getPersonalIngressionDataByExecutionYear(ExecutionYear.readCurrentExecutionYear());
    if (personalIngressionDataByExecutionYear != null) {
        org.fenixedu.academic.domain.person.MaritalStatus maritalStatus = personalIngressionDataByExecutionYear
                .getMaritalStatus();
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_MARITAL_STATUS,
                () -> personData.setMaritalStatusCode(
                        objectFactory.createPersonMaritalStatusCode(getCodeForMaritalStatus(maritalStatus))));

    }

    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_FATHER_NAME, () -> personData
            .setFather(objectFactory.createPersonFather(getShortNameFor(person.getNameOfFather()))));

    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_MOTHER_NAME, () -> personData
            .setMother(objectFactory.createPersonMother(getShortNameFor(person.getNameOfMother()))));

    if (person.getCountryOfBirth() != null) {
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_BIRTH_COUNTRY,
                () -> personData.setPlaceOfBirthCountryCode(objectFactory
                        .createPersonPlaceOfBirthCountryCode(person.getCountryOfBirth().getCode())));
    }

    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_BIRTH_DISTRICT,
            () -> personData.setPlaceOfBirthDistrict(
                    objectFactory.createPersonPlaceOfBirthDistrict(person.getDistrictOfBirth())));

    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_BIRTH_COUNTY,
            () -> personData.setPlaceOfBirthCounty(
                    objectFactory.createPersonPlaceOfBirthCounty(person.getDistrictSubdivisionOfBirth())));

    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_BIRTH_PARISH, () -> personData
            .setPlaceOfBirthParish(objectFactory.createPersonPlaceOfBirthParish(person.getParishOfBirth())));

    ArrayOfstring nationality = new ArrayOfstring();
    nationality.getString().add(person.getCountry().getCode());
    Country countryOfResidence = person.getCountryOfResidence();

    executeIfAllowed(person, CgdAuthorizationCodes.BASIC_INFO, () -> {
        personData.setNationalities(nationality);
        if (countryOfResidence != null) {
            personData.setCountryOfResidenceCode(
                    objectFactory.createPersonCountryOfResidenceCode(countryOfResidence.getCode()));
        } else {
            personData.setCountryOfResidenceCode(objectFactory.createPersonCountryOfResidenceCode("PT"));
        }
    });

    PhysicalAddress defaultPhysicalAddress = person.getDefaultPhysicalAddress();
    if (defaultPhysicalAddress != null) {
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_ADDRESS_PLACE, () -> {
            personData.setAddress(objectFactory.createPersonAddress(defaultPhysicalAddress.getAddress()));
            personData.setPlace(objectFactory.createPersonPlace(defaultPhysicalAddress.getArea()));
        });
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_ADDRESS_POSTAL_CODE, () -> personData
                .setPostalCode(objectFactory.createPersonPostalCode(defaultPhysicalAddress.getAreaCode())));
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_ADDRESS_DISTRICT,
                () -> personData.setDistrict(
                        objectFactory.createPersonDistrict(defaultPhysicalAddress.getDistrictOfResidence())));
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_ADDRESS_POSTAL_COUNTY,
                () -> personData.setCounty(objectFactory
                        .createPersonCounty(defaultPhysicalAddress.getDistrictSubdivisionOfResidence())));
        executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_ADDRESS_POSTAL_PARISH, () -> personData
                .setParish(objectFactory.createPersonParish(defaultPhysicalAddress.getParishOfResidence())));
    }

    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_PHONE, () -> personData.setPhone(
            objectFactory.createPersonPhone(getPhoneNumberWithoutCountryCode(person.getDefaultPhoneNumber()))));
    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_MOBILE_PHONE,
            () -> personData.setMobilePhone(objectFactory.createPersonMobilePhone(
                    getPhoneNumberWithoutCountryCode(person.getDefaultMobilePhoneNumber()))));

    IdentificationCard card = new IdentificationCard();

    // skipping issuer
    String codeForDocumentType = getCodeForDocumentType(person.getIdDocumentType());
    if (codeForDocumentType != null) {
        card.setTypeCode(objectFactory.createIdentificationCardTypeCode(codeForDocumentType));
    }
    card.setNumber(person.getDocumentIdNumber());
    // skipping issuer country code
    executeIfAllowed(person, CgdAuthorizationCodes.EXTENDED_INFO_ID_CARD_EXPIRATION_DATE, () -> {
        try {
            YearMonthDay expirationDateOfDocumentIdYearMonthDay = person
                    .getExpirationDateOfDocumentIdYearMonthDay();
            if (expirationDateOfDocumentIdYearMonthDay != null) {
                card.setExpirationDate(objectFactory.createIdentificationCardExpirationDate(DatatypeFactory
                        .newInstance().newXMLGregorianCalendar(expirationDateOfDocumentIdYearMonthDay
                                .toDateTimeAtMidnight().toGregorianCalendar())));
            }
        } catch (DatatypeConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    });
    personData.setIdentificationCard(objectFactory.createIdentificationCard(card));

    return personData;
}

From source file:net.sourceforge.fenixedu.applicationTier.Factory.RoomSiteComponentBuilder.java

License:Open Source License

private ISiteComponent getInfoSiteRoomTimeTable(InfoSiteRoomTimeTable component, Calendar day, Space room,
        ExecutionSemester executionSemester) throws Exception {

    List<InfoObject> infoShowOccupations = new ArrayList<InfoObject>();

    Calendar startDay = Calendar.getInstance();
    startDay.setTimeInMillis(day.getTimeInMillis());
    startDay.add(Calendar.DATE, Calendar.MONDAY - day.get(Calendar.DAY_OF_WEEK));

    Calendar endDay = Calendar.getInstance();
    endDay.setTimeInMillis(startDay.getTimeInMillis());
    endDay.add(Calendar.DATE, 6);

    // final boolean isCurrentUserRoomManager =
    // isCurrentUserRoomManager(room);

    final YearMonthDay weekStartYearMonthDay = YearMonthDay.fromCalendarFields(startDay);
    final YearMonthDay weekEndYearMonthDay = YearMonthDay.fromCalendarFields(endDay);

    final Interval search = new Interval(weekStartYearMonthDay.toDateTimeAtMidnight(),
            weekEndYearMonthDay.toDateTimeAtMidnight());

    for (final Occupation roomOccupation : room.getOccupationSet()) {

        if (roomOccupation instanceof WrittenEvaluationSpaceOccupation) {
            Collection<WrittenEvaluation> writtenEvaluations = ((WrittenEvaluationSpaceOccupation) roomOccupation)
                    .getWrittenEvaluationsSet();
            getWrittenEvaluationRoomOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    writtenEvaluations);
        } else if (roomOccupation instanceof LessonSpaceOccupation) {
            final Lesson lesson = ((LessonSpaceOccupation) roomOccupation).getLesson();
            getLessonOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay, lesson);
        } else if (roomOccupation instanceof LessonInstanceSpaceOccupation) {
            Collection<LessonInstance> lessonInstances = ((LessonInstanceSpaceOccupation) roomOccupation)
                    .getLessonInstancesSet();
            getLessonInstanceOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    lessonInstances);/*  w w w .java2  s . com*/
        } else {
            for (Interval interval : roomOccupation.getIntervals()) {
                if (search.overlaps(interval)) {
                    infoShowOccupations.add(new InfoOccupation(roomOccupation, interval));
                }
            }
        }
    }

    component.setInfoShowOccupation(infoShowOccupations);
    component.setInfoRoom(InfoRoom.newInfoFromDomain(room));

    return component;
}

From source file:net.sourceforge.fenixedu.applicationTier.Factory.RoomSiteComponentBuilder.java

License:Open Source License

private void getLessonOccupations(List<InfoObject> infoShowOccupations, YearMonthDay weekStartYearMonthDay,
        YearMonthDay weekEndYearMonthDay, Lesson lesson) {

    if (lesson != null && lesson.getShift() != null && lesson.containsWithoutCheckInstanceDates(new Interval(
            weekStartYearMonthDay.toDateTimeAtMidnight(), weekEndYearMonthDay.toDateTimeAtMidnight()))) {
        infoShowOccupations.add(InfoLesson.newInfoFromDomain(lesson));
    }//from  w w w.j  a va2 s .  co  m
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.residenceManagement.PayResidenceEvent.java

License:Open Source License

@Atomic
public static void run(User user, ResidenceEvent event, YearMonthDay date) {
    event.process(user, event.calculateEntries(),
            new AccountingTransactionDetailDTO(date.toDateTimeAtMidnight(), PaymentMode.CASH));
}

From source file:net.sourceforge.fenixedu.dataTransferObject.InfoLessonInstanceAggregation.java

License:Open Source License

public SortedSet<Integer> getWeeks() {
    final ExecutionCourse executionCourse = shift.getExecutionCourse();
    final YearMonthDay firstPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getLeft();
    final YearMonthDay lastPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getRight();
    return getWeeks(new Interval(firstPossibleLessonDay.toDateTimeAtMidnight(),
            lastPossibleLessonDay.toDateTimeAtMidnight().plusDays(1)));
}

From source file:net.sourceforge.fenixedu.dataTransferObject.spaceManager.ViewEventSpaceOccupationsBean.java

License:Open Source License

public ViewEventSpaceOccupationsBean(YearMonthDay day, Space allocatableSpace) {

    setAllocatableSpace(allocatableSpace);

    if (day != null) {
        setYear(new Partial(DateTimeFieldType.year(), day.getYear()));
        setMonth(new Partial(DateTimeFieldType.monthOfYear(), day.getMonthOfYear()));

        YearMonthDay monday = day.toDateTimeAtMidnight().withDayOfWeek(MONDAY_IN_JODA_TIME).toYearMonthDay();
        if ((monday.getMonthOfYear() < day.getMonthOfYear()) || (monday.getYear() < day.getYear())) {
            monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
        }//from  ww w .j  av  a2s . com

        setDay(monday);
    }
}

From source file:net.sourceforge.fenixedu.domain.EnrolmentEvaluation.java

License:Open Source License

@Override
public void setExamDateYearMonthDay(YearMonthDay evaluationDateYearMonthDay) {
    if (evaluationDateYearMonthDay != null) {
        final Enrolment enrolment = getEnrolment();
        final Thesis thesis = enrolment.getThesis();
        if (thesis != null) {
            DateTime newDateTime = evaluationDateYearMonthDay.toDateTimeAtMidnight();
            final DateTime dateTime = thesis.getDiscussed();
            if (dateTime != null) {
                newDateTime = newDateTime.withHourOfDay(dateTime.getHourOfDay());
                newDateTime = newDateTime.withMinuteOfHour(dateTime.getMinuteOfHour());
            }//from ww w .  ja v a  2 s  .  c  om
            thesis.setDiscussed(newDateTime);
        }
    }
    super.setExamDateYearMonthDay(evaluationDateYearMonthDay);
}

From source file:net.sourceforge.fenixedu.domain.ExecutionDegree.java

License:Open Source License

@Deprecated
public boolean isDateInFirstSemesterNormalSeasonOfGradeSubmission(YearMonthDay date) {
    return isDateInPeriodOfType(date.toDateTimeAtMidnight(), OccupationPeriodType.GRADE_SUBMISSION, 1);
}

From source file:net.sourceforge.fenixedu.domain.ExecutionDegree.java

License:Open Source License

@Deprecated
public boolean isDateInSecondSemesterNormalSeasonOfGradeSubmission(YearMonthDay date) {
    return isDateInPeriodOfType(date.toDateTimeAtMidnight(), OccupationPeriodType.GRADE_SUBMISSION, 2);
}