Example usage for java.time Period getDays

List of usage examples for java.time Period getDays

Introduction

In this page you can find the example usage for java.time Period getDays.

Prototype

public int getDays() 

Source Link

Document

Gets the amount of days of this period.

Usage

From source file:svc.managers.DemoManager.java

public List<DemoCitation> createCitationsAndViolations() {
    List<DemoCitation> demoCitations = new ArrayList<DemoCitation>();

    DemoUtilities demoUtilities = new DemoUtilities();
    List<Citation> citations = demoUtilities.generateRandomCitations();
    List<Violation> violations = demoUtilities.generateRandomViolations();

    mockCitationDataSource.insertCitations(citations);
    violationManager.insertViolations(violations);

    for (int citationCount = 0; citationCount < citations.size(); citationCount++) {
        Citation citation = citations.get(citationCount);
        int numberOfViolations = 0;
        for (int violationCount = 0; violationCount < violations.size(); violationCount++) {
            if (violations.get(violationCount).citation_number.equals(citation.citation_number)) {
                numberOfViolations++;/*from   w ww. j  a  v  a2  s . c o m*/
            }
        }
        DemoCitation demoCitation = new DemoCitation();
        demoCitation.citationNumber = citation.citation_number;
        demoCitation.dob = citation.date_of_birth;
        demoCitation.driversLicenseNumber = citation.drivers_license_number;
        Period daysTillCourt = DatabaseUtilities.getCurrentDate().until(citation.court_dateTime.toLocalDate());
        demoCitation.daysTillCourt = daysTillCourt.getDays();
        demoCitation.numberOfViolations = numberOfViolations;

        demoCitations.add(demoCitation);
    }

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            mockCitationDataSource.removeCitations(citations);
            violationManager.removeViolations(violations);
        }

    }, 60 * 60 * 1000);

    return demoCitations;
}

From source file:agendapoo.Control.ControlAtividade.java

/**
  * Verifica se o horrio inserido aps uma insero  vlido, ou seja, se entra em conflito
 *  com outras atividades, caso entre em conflito com outras atividades retornar False, caso contrrio,
 * retornar True./*from  www .  ja va  2  s  .c o m*/
 * @param data - LocalDate contendo a data da atividade
 * @param start - LocalTime contendo o horrio inicial da atividade
 * @param end - LocalTime contendo o horrio final da atividade
 * @param u - Usurio que est adicionando a atividade (faz-se necessrio por verificar se o horrio  vlido apenas considerando as atividades
 * daquele usurio)
 * @return - valor booleano indicando se o horrio definido para atividade  vlido ou no.
 * @throws SQLException
 * @throws IOException
 * @throws ClassNotFoundException 
 */
private boolean isValidTimeByUser(LocalDate data, LocalTime start, LocalTime end, Usuario u)
        throws SQLException, IOException, ClassNotFoundException {
    boolean isValid = false;
    List<Atividade> atividades = dao.list(u);
    List<Atividade> sameDay = new ArrayList<>();

    atividades.stream().forEach((a) -> {
        Period p = Period.between(a.getData(), data);
        if (p.getDays() == 0) {
            sameDay.add(a);
        }
    });

    if (!sameDay.isEmpty()) {
        for (Atividade a : sameDay)
            if ((start.isBefore(a.getHoraInicio()) && end.isBefore(a.getHoraInicio()))
                    || (start.isAfter(a.getHoraFim()) && end.isAfter(a.getHoraFim())))
                isValid = true;
            else {
                isValid = false;
                break;
            }
        return isValid;
    }
    return true;
}

From source file:agendapoo.Control.ControlAtividade.java

/**
 * Verifica se o horrio inserido aps uma atualizao  vlido, ou seja, se entra em conflito
 * com outras atividades, caso entre em conflito com outras atividades retornar False, caso contrrio,
 * True, Como  uma atualizao nesse mtodo a verificao ignorar o horrio que tiver no banco dessa mesma atividade.
 * @param current - Atividade que foi atualizada e que ter seu horrio verificado.
 * @return - valor booleano indicando se o horrio  vlido ou no.
 * @throws SQLException//w  ww .  j  a v a2s  .c o m
 * @throws IOException
 * @throws ClassNotFoundException 
 */
private boolean isValidTimeUpdate(Atividade current) throws SQLException, IOException, ClassNotFoundException {
    boolean isValid = false;
    List<Atividade> atividades = dao.list(current.getUsuario());
    List<Atividade> sameDay = new ArrayList<>();
    LocalTime start = current.getHoraInicio();
    LocalTime end = current.getHoraFim();

    atividades.stream().forEach((a) -> {
        Period p = Period.between(a.getData(), current.getData());
        if ((p.getDays() == 0) && (!a.getId().equals(current.getId()))) {
            sameDay.add(a);
        }
    });

    if (!sameDay.isEmpty()) {
        for (Atividade a : sameDay)
            if ((start.isBefore(a.getHoraInicio()) && end.isBefore(a.getHoraInicio()))
                    || (start.isAfter(a.getHoraFim()) && end.isAfter(a.getHoraFim())))
                isValid = true;
            else {
                isValid = false;
                break;
            }
        return isValid;
    }
    return true;
}

From source file:agendapoo.View.FrmCadastroAtividade.java

private boolean isOldTime(LocalDate data, LocalTime end) {
    Period p = Period.between(data, LocalDate.now());
    if (p.getDays() > 0)
        return true;
    else if (p.getDays() == 0) {
        return end.isBefore(LocalTime.now());
    }// www. j  av  a2s . co  m
    return false;
}

From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java

/**
 * copy participant info// w  ww. j  av a 2 s  . c  om
 */
private ParticipantType copyParticipant(ObjectFactory factory, Participant part) {
    final ParticipantType retVal = factory.createParticipantType();

    if (part.getId() != null)
        retVal.setId(part.getId());

    retVal.setName(part.getName());

    final LocalDate bday = part.getBirthDate();
    if (bday != null) {
        try {
            final DatatypeFactory df = DatatypeFactory.newInstance();
            final XMLGregorianCalendar cal = df
                    .newXMLGregorianCalendar(GregorianCalendar.from(bday.atStartOfDay(ZoneId.systemDefault())));
            cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
            retVal.setBirthday(cal);
        } catch (DatatypeConfigurationException e) {
            LOGGER.log(Level.WARNING, e.toString(), e);
        }
    }

    final Period age = part.getAge(null);
    if (age != null) {
        try {
            final DatatypeFactory df = DatatypeFactory.newInstance();
            final Duration ageDuration = df.newDuration(true, age.getYears(), age.getMonths(), age.getDays(), 0,
                    0, 0);
            retVal.setAge(ageDuration);
        } catch (DatatypeConfigurationException e) {
            LOGGER.log(Level.WARNING, e.toString(), e);
        }
    }

    retVal.setEducation(part.getEducation());
    retVal.setGroup(part.getGroup());

    final String lang = part.getLanguage();
    final String langs[] = (lang != null ? lang.split(",") : new String[0]);
    for (String l : langs) {
        retVal.getLanguage().add(StringUtils.strip(l));
    }

    if (part.getSex() == Sex.MALE)
        retVal.setSex(SexType.MALE);
    else if (part.getSex() == Sex.FEMALE)
        retVal.setSex(SexType.FEMALE);

    ParticipantRole prole = part.getRole();
    if (prole == null)
        prole = ParticipantRole.TARGET_CHILD;
    retVal.setRole(prole.toString());

    // create ID based on role if possible
    if (retVal.getId() == null && prole != null) {
        if (prole == ParticipantRole.TARGET_CHILD) {
            retVal.setId("CHI");
        } else if (prole == ParticipantRole.MOTHER) {
            retVal.setId("MOT");
        } else if (prole == ParticipantRole.FATHER) {
            retVal.setId("FAT");
        } else if (prole == ParticipantRole.INTERVIEWER) {
            retVal.setId("INT");
        } else {
            retVal.setId("p" + (++pIdx));
        }
    }

    retVal.setSES(part.getSES());

    return retVal;
}