Example usage for org.joda.time DateTime getHourOfDay

List of usage examples for org.joda.time DateTime getHourOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime getHourOfDay.

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:ph.fingra.statisticsweb.service.DashBoardServiceImpl.java

License:Apache License

@Override
public App getDashBoardAppInfo(DashBoardSearchParam param) {

    App app = getApp(param);//  ww  w .ja v  a  2  s . co m
    DashBoard dashBoard = app.getDashBoard();

    //NOTIFICATIONS
    //dashBoard.setInData(dashBoardDao.getIsData(param)>0?true:false);
    //dashBoard.setLogs(dashBoardDao.getLogs(param));

    //TODAY SNAPSHOT
    dashBoard.setTodayNewUsers(dashBoardDao.getTodayNewUsers(param));
    dashBoard.setTodayActiveUsers(dashBoardDao.getTodayActiveUsers(param));
    dashBoard.setTodaySessions(dashBoardDao.getTodaySessions(param));
    dashBoard.setTodaySessionLength(dashBoardDao.getTodaySessionLength(param));
    dashBoard.setTodayPageViews(dashBoardDao.getTodayPageViews(param));

    //TODAY SNAPSHOT - TIME INFORMATION
    DateTime now = DateTime.now();
    String nowTime = "";
    String prevTime = "";
    // Show statistics after 10 minutes.
    if (now.getMinuteOfHour() < 10) { // Before 10 minutes 
        String nowTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1);
        nowTime = (nowTemp.length() < 2) ? nowTemp = "0" + nowTemp : nowTemp;
        String prevTemp = nowTime.equals("00") ? "23" : String.valueOf(Integer.parseInt(nowTime) - 1);
        prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp;
    } else { // After 10 minutes
        nowTime = (String.valueOf(now.getHourOfDay()).length() < 2) ? "0" + String.valueOf(now.getHourOfDay())
                : String.valueOf(now.getHourOfDay());
        String prevTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1);
        prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp;
    }
    dashBoard.setTodayNowTime(nowTime);
    dashBoard.setTodayPrevTime(prevTime);

    //PERFORMANCE SNAPSHOT
    dashBoard.setCompare(dashBoardDao.getIsCompare(param));
    dashBoard.setNewUsers(dashBoardDao.getNewUsers(param));
    dashBoard.setActiveUsers(dashBoardDao.getActiveUsers(param));
    dashBoard.setSessions(dashBoardDao.getSessions(param));
    dashBoard.setSessionLength(dashBoardDao.getSessionLength(param));
    dashBoard.setPageViews(dashBoardDao.getPageViews(param));
    //PERFORMANCE SNAPSHOT - period
    dashBoard.setThisWeek(param.getFrom() + " ~ " + param.getTo());

    //DISTRIBUTION SNAPSHOT
    dashBoard.setDayOfWeek(dashBoardDao.getDayOfWeek(param));
    dashBoard.setTimeOfDay(dashBoardDao.getTimeOfDay(param));
    dashBoard.setTopCountries(dashBoardDao.getTopCountries(param));
    dashBoard.setTopResolution(dashBoardDao.getTopResolution(param));
    dashBoard.setTopAppVersion(dashBoardDao.getTopAppVersion(param));
    dashBoard.setTopOsVersion(dashBoardDao.getTopOsVersion(param));

    //COMPONENTS Group List
    List<ComponentsGroup> componentGrpList = dashBoardDao.getComponentsGroupList(param);
    dashBoard.setComponentGrpList(componentGrpList);

    app.setDashBoard(dashBoard);
    return app;
}

From source file:ph.fingra.statisticsweb.service.DashBoardServiceImpl.java

License:Apache License

@Override
public App getTodaySectionInfo(DashBoardSearchParam param) {

    App app = getApp(param);/*from   w  ww  .  j  av a2  s.  co  m*/

    DashBoard dashBoard = app.getDashBoard();

    //TODAY SNAPSHOT
    dashBoard.setTodayNewUsers(dashBoardDao.getTodayNewUsers(param));
    dashBoard.setTodayActiveUsers(dashBoardDao.getTodayActiveUsers(param));
    dashBoard.setTodaySessions(dashBoardDao.getTodaySessions(param));
    dashBoard.setTodaySessionLength(dashBoardDao.getTodaySessionLength(param));
    dashBoard.setTodayPageViews(dashBoardDao.getTodayPageViews(param));

    //Time of TODAY SNAPSHOT
    DateTime now = DateTime.now();
    String nowTime = "";
    String prevTime = "";
    // Show statistics after 10 minutes
    if (now.getMinuteOfHour() < 10) { // Before 10 minutes 
        String nowTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1);
        nowTime = (nowTemp.length() < 2) ? nowTemp = "0" + nowTemp : nowTemp;
        String prevTemp = nowTime.equals("00") ? "23" : String.valueOf(Integer.parseInt(nowTime) - 1);
        prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp;
    } else { // After 10 minutes
        nowTime = (String.valueOf(now.getHourOfDay()).length() < 2) ? "0" + String.valueOf(now.getHourOfDay())
                : String.valueOf(now.getHourOfDay());
        String prevTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1);
        prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp;
    }
    dashBoard.setTodayNowTime(nowTime);
    dashBoard.setTodayPrevTime(prevTime);
    dashBoard.setToday(now.toString("yyyy-MM-dd"));
    dashBoard.setYesterday(now.minusDays(1).toString("yyyy-MM-dd"));
    app.setDashBoard(dashBoard);

    return app;

}

From source file:proxi.model.ProxiCSVWriter.java

License:Open Source License

private static String[] dateTimeCutter(DateTime dt) {
    String[] dtParts = new String[6];

    String year = "" + dt.getYear();
    String month = fixWith2Chars(dt.getMonthOfYear());
    String day = fixWith2Chars(dt.getDayOfMonth());
    String hour = fixWith2Chars(dt.getHourOfDay());
    String minute = fixWith2Chars(dt.getMinuteOfHour());
    String second = fixWith2Chars(dt.getSecondOfMinute());

    dtParts[0] = year;//  w ww.ja  v a 2s .  c  o  m
    dtParts[1] = month;
    dtParts[2] = day;
    dtParts[3] = hour;
    dtParts[4] = minute;
    dtParts[5] = second;

    return dtParts;

}

From source file:pt.ist.bennu.core.domain.scheduler.TaskConfiguration.java

License:Open Source License

public boolean shouldRunNow(DateTime now) {
    final int min = now.getMinuteOfHour();
    final int hour = now.getHourOfDay();
    final int day = now.getDayOfMonth();
    final int month = now.getMonthOfYear();
    final int dayofweek = now.getDayOfWeek();

    if (matchField(getMinute(), min) && matchField(getHour(), hour) && matchField(getDay(), day)
            && matchField(getMonth(), month) && matchField(getDayofweek(), dayofweek)) {

        final DateTime lastRun = getLastRun();
        return lastRun == null || nowIsAfterLastRun(now, lastRun);
    }//from w  w  w .j av a2s .  c om

    return false;
}

From source file:pt.ist.bennu.core.domain.scheduler.TaskConfiguration.java

License:Open Source License

private boolean nowIsAfterLastRun(final DateTime now, final DateTime lastRun) {
    if (now.getYear() > lastRun.getYear()) {
        return true;
    }//w  w  w  .j  a v a  2  s  . c o m
    if (now.getMonthOfYear() > lastRun.getMonthOfYear()) {
        return true;
    }
    if (now.getDayOfMonth() > lastRun.getDayOfMonth()) {
        return true;
    }
    if (now.getHourOfDay() > lastRun.getHourOfDay()) {
        return true;
    }
    if (now.getMinuteOfHour() > lastRun.getMinuteOfHour()) {
        return true;
    }
    return false;
}

From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.acquisitions.SearchPaymentProcessesAction.java

License:Open Source License

private void fillXlsInfo(Set<PaymentProcess> processes, StyledExcelSpreadsheet spreadsheet,
        OutputStream outputStream) throws IOException {
    spreadsheet.newRow();//from w ww  .  jav a2  s  . co  m
    spreadsheet.addCell(processes.size() + " " + getAcquisitionResourceMessage("label.processes"));
    spreadsheet.newRow();

    setHeaders(spreadsheet);
    TreeSet<PaymentProcess> sortedProcesses = new TreeSet<PaymentProcess>(
            PaymentProcess.COMPARATOR_BY_YEAR_AND_ACQUISITION_PROCESS_NUMBER);
    sortedProcesses.addAll(processes);

    for (PaymentProcess process : sortedProcesses) {
        spreadsheet.newRow();

        spreadsheet.addCell(process.getAcquisitionProcessId());
        spreadsheet.addCell(process.getTypeShortDescription());
        AcquisitionItemClassification classification = process.getGoodsOrServiceClassification();
        spreadsheet.addCell(classification == null ? " " : classification.getLocalizedName());
        spreadsheet.addCell(process.getSuppliersDescription());
        spreadsheet.addCell(process.getRequest().getRequestItemsSet().size());
        spreadsheet.addCell(process.getProcessStateDescription());
        DateTime time = new DateTime();
        if (process.getPaymentProcessYear().getYear() != time.getYear()) {
            time = new DateTime(process.getPaymentProcessYear().getYear().intValue(), 12, 31, 23, 59, 59, 0);
        }
        spreadsheet.addCell(describeState(process, time));
        DateTime date = process.getDateFromLastActivity();
        spreadsheet.addCell((date == null) ? ""
                : date.getDayOfMonth() + "-" + date.getMonthOfYear() + "-" + date.getYear() + " "
                        + date.getHourOfDay() + ":" + date.getMinuteOfHour());
        spreadsheet.addCell(process.getRequest().getRequester().getFirstAndLastName());
        spreadsheet.addCell(process.getRequest().getRequestingUnit().getName());

        final MissionProcess missionProcess = process.getMissionProcess();
        spreadsheet.addCell(missionProcess == null ? "" : missionProcess.getProcessNumber());
        final Boolean skipSupplierFundAllocation = process.getSkipSupplierFundAllocation();
        spreadsheet.addCell(Boolean
                .toString(skipSupplierFundAllocation != null && skipSupplierFundAllocation.booleanValue()));
        spreadsheet.addCell(toString(process.getCPVReferences()));

        final StringBuilder builderAccountingUnit = new StringBuilder();
        final StringBuilder builderUnits = new StringBuilder();
        for (final Financer financer : process.getFinancersWithFundsAllocated()) {
            final AccountingUnit accountingUnit = financer.getAccountingUnit();
            if (accountingUnit != null) {
                if (builderAccountingUnit.length() > 0) {
                    builderAccountingUnit.append(", ");
                }
                builderAccountingUnit.append(accountingUnit.getName());
            }
            final Unit unit = financer.getUnit();
            if (unit != null) {
                if (builderUnits.length() > 0) {
                    builderUnits.append(", ");
                }
                builderUnits.append(unit.getUnit().getAcronym());
            }
        }
        spreadsheet.addCell(builderAccountingUnit.length() == 0 ? " " : builderAccountingUnit.toString());
        spreadsheet.addCell(builderUnits.length() == 0 ? " " : builderUnits.toString());

        final Money totalValue = process.getTotalValue();
        spreadsheet.addCell((totalValue == null ? Money.ZERO : totalValue).toFormatString());

        final StringBuilder fundAllocationNumbers = new StringBuilder();
        final StringBuilder commitmentNumbers = new StringBuilder();
        final StringBuilder efectiveFundAllocationNumbers = new StringBuilder();
        final StringBuilder requestOrderNumber = new StringBuilder();
        LocalDate invoiceDate = null;
        Money invoiceValue = Money.ZERO;

        if (process instanceof SimplifiedProcedureProcess) {
            SimplifiedProcedureProcess simplifiedProcedureProcess = (SimplifiedProcedureProcess) process;
            final AcquisitionRequest acquisitionRequest = simplifiedProcedureProcess.getAcquisitionRequest();
            for (PayingUnitTotalBean payingUnitTotal : acquisitionRequest.getTotalAmountsForEachPayingUnit()) {
                if ((simplifiedProcedureProcess.getFundAllocationPresent())
                        && (payingUnitTotal.getFinancer().isFundAllocationPresent())) {
                    if (fundAllocationNumbers.length() > 0) {
                        fundAllocationNumbers.append(", ");
                    }
                    fundAllocationNumbers.append(payingUnitTotal.getFinancer().getFundAllocationIds().trim());
                }

                if (commitmentNumbers.length() > 0) {
                    fundAllocationNumbers.append(", ");
                }
                String commitmentNumber = payingUnitTotal.getFinancer().getCommitmentNumber();
                if (commitmentNumber != null) {
                    commitmentNumber = commitmentNumber.trim();
                    if (commitmentNumber.length() > 0) {
                        commitmentNumbers.append(commitmentNumber);
                    }
                }

                if ((simplifiedProcedureProcess.getEffectiveFundAllocationPresent())
                        && (payingUnitTotal.getFinancer().isEffectiveFundAllocationPresent())) {
                    if (efectiveFundAllocationNumbers.length() > 0) {
                        efectiveFundAllocationNumbers.append(", ");
                    }
                    efectiveFundAllocationNumbers
                            .append(payingUnitTotal.getFinancer().getEffectiveFundAllocationIds().trim());
                }
            }

            boolean hasFullInvoice = false;
            for (final Invoice invoice : acquisitionRequest.getInvoices()) {
                //          final AcquisitionInvoice acquisitionInvoice = (AcquisitionInvoice) invoice;
                final LocalDate localDate = invoice.getInvoiceDate();
                if (invoiceDate == null || invoiceDate.isBefore(localDate)) {
                    invoiceDate = localDate;
                }

                hasFullInvoice = true;
                //          if (!hasFullInvoice) {
                //         final String confirmationReport = acquisitionInvoice.getConfirmationReport();
                //         if (confirmationReport == null) {
                //             hasFullInvoice = true;
                //         } else {
                //             for (int i = 0; i < confirmationReport.length(); ) {
                //            final int ulli = confirmationReport.indexOf("<ul><li>", i);
                //            final int q = confirmationReport.indexOf(" - Quantidade:", ulli);
                //            final int ulliClose = confirmationReport.indexOf("</li></ul>", q);
                //            final String itemDescription = confirmationReport.substring(i + "<ul><li>".length(), q);
                //            final int quantity = Integer.parseInt(confirmationReport.substring(q + " - Quantidade:".length(), ulliClose));
                //
                //            invoiceValue = invoiceValue.add(calculate(acquisitionRequest, itemDescription, quantity));
                //             }
                //         }
                //          }
            }

            if (hasFullInvoice) {
                invoiceValue = totalValue;
            }

            final PurchaseOrderDocument purchaseOrderDocument = simplifiedProcedureProcess
                    .getPurchaseOrderDocument();
            if (purchaseOrderDocument != null) {
                requestOrderNumber.append(purchaseOrderDocument.getRequestId());
            }
        }

        spreadsheet.addCell(fundAllocationNumbers.length() == 0 ? " " : fundAllocationNumbers.toString());
        spreadsheet.addCell(commitmentNumbers.length() == 0 ? " " : commitmentNumbers.toString());
        spreadsheet.addCell(requestOrderNumber.length() == 0 ? " " : requestOrderNumber.toString());
        spreadsheet.addCell(
                efectiveFundAllocationNumbers.length() == 0 ? " " : efectiveFundAllocationNumbers.toString());

        spreadsheet.addCell(invoiceDate == null ? " " : invoiceDate.toString("yyyy-MM-dd"));
        spreadsheet.addCell(invoiceValue.toFormatString());

        DateTime creationDate = process.getCreationDate();
        spreadsheet.addCell(creationDate == null ? " " : creationDate.toString("yyyy-MM-dd"));
        SortedSet<WorkflowLog> executionLogsSet = new TreeSet<WorkflowLog>(
                WorkflowLog.COMPARATOR_BY_WHEN_REVERSED);
        executionLogsSet.addAll(process.getExecutionLogsSet());
        DateTime approvalDate = getApprovalDate(process, executionLogsSet);
        spreadsheet.addCell(approvalDate == null ? " " : approvalDate.toString("yyyy-MM-dd"));
        DateTime authorizationDate = getAuthorizationDate(process, executionLogsSet);
        spreadsheet.addCell(authorizationDate == null ? " " : authorizationDate.toString("yyyy-MM-dd"));
    }
}

From source file:pt.ist.fenixedu.integration.api.FenixAPIv1.java

License:Open Source License

private SummariesManagementBean fillSummaryManagementBean(ExecutionCourse executionCourse, Shift shift,
        Space space, String date, JsonObject title, JsonObject content, Boolean taught, int attendance) {

    MultiLanguageString titleMLS, contentMLS;
    try {//from ww  w . ja  v  a 2  s . co m
        titleMLS = MultiLanguageString.fromLocalizedString(LocalizedString.fromJson(title));
        contentMLS = MultiLanguageString.fromLocalizedString(LocalizedString.fromJson(content));
    } catch (Exception e) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "'title' or 'content' is not a valid multi-language string");
    }

    DateTime lessonDateTime = DateTimeFormat.forPattern(dayHourSecondPattern).parseDateTime(date);
    YearMonthDay lessonDate = lessonDateTime.toYearMonthDay();
    Partial lessonTime = new Partial().with(DateTimeFieldType.hourOfDay(), lessonDateTime.getHourOfDay())
            .with(DateTimeFieldType.minuteOfHour(), lessonDateTime.getMinuteOfHour())
            .with(DateTimeFieldType.secondOfDay(), lessonDateTime.getSecondOfMinute());

    Optional<Lesson> lesson = shift.getAssociatedLessonsSet().stream()
            .filter(l -> l.getAllLessonDates().stream().anyMatch(lessonDate::equals))
            .filter(l -> l.getSala().equals(space)).findFirst();

    if (!lesson.isPresent()) {
        throw newApplicationError(Status.PRECONDITION_FAILED, "invalid parameters",
                "invalid lesson date or room");
    }

    Person person = getPerson();
    Professorship professorship = executionCourse.getProfessorship(person);
    String teacherName = person.getName();
    LessonInstance lessonInstance = lesson.get().getLessonInstanceFor(lessonDate);
    Summary summary = lessonInstance != null ? lessonInstance.getSummary() : null;
    ShiftType shiftType = shift.getSortedTypes().first();

    return new SummariesManagementBean(titleMLS, contentMLS, attendance, NORMAL_SUMMARY, professorship,
            teacherName, null, shift, lesson.get(), lessonDate, space, lessonTime, summary, professorship,
            shiftType, taught);
}

From source file:pt.ist.fenixedu.vigilancies.ui.struts.action.vigilancy.ConvokeManagement.java

License:Open Source License

public ActionForward confirmConvokes(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ConvokeBean beanWithTeachers = null;

    if (RenderUtils.getViewState("selectVigilantsThatAreTeachers") != null) {
        beanWithTeachers = (ConvokeBean) RenderUtils.getViewState("selectVigilantsThatAreTeachers")
                .getMetaObject().getObject();
    }/*from ww  w .  j a va2  s  .co  m*/

    ConvokeBean beanWithVigilants = (ConvokeBean) RenderUtils.getViewState("selectVigilants").getMetaObject()
            .getObject();

    ConvokeBean beanWithUnavailables = (ConvokeBean) RenderUtils
            .getViewState("selectVigilantsThatAreUnavailable").getMetaObject().getObject();

    List<VigilantWrapper> teachers = null;
    List<VigilantWrapper> vigilants, unavailables;

    if (RenderUtils.getViewState("selectVigilantsThatAreTeachers") != null) {
        teachers = beanWithTeachers.getSelectedTeachers();
    }

    vigilants = beanWithVigilants.getVigilants();
    unavailables = beanWithUnavailables.getSelectedUnavailableVigilants();

    String convokedVigilants = beanWithVigilants.getTeachersAsString();
    String teachersVigilancies = null;

    if (RenderUtils.getViewState("selectVigilantsThatAreTeachers") != null) {
        teachersVigilancies = beanWithTeachers.getVigilantsAsString();
        vigilants.addAll(teachers);
    } else {
        teachersVigilancies = RenderUtils.getResourceString("VIGILANCY_RESOURCES", "label.vigilancy.noone");
    }

    vigilants.addAll(unavailables);
    beanWithVigilants.setVigilants(vigilants);

    String email = RenderUtils.getResourceString("VIGILANCY_RESOURCES", "label.vigilancy.emailConvoke");
    MessageFormat format = new MessageFormat(email);
    WrittenEvaluation evaluation = beanWithVigilants.getWrittenEvaluation();
    DateTime beginDate = evaluation.getBeginningDateTime();
    String date = beginDate.getDayOfMonth() + "/" + beginDate.getMonthOfYear() + "/" + beginDate.getYear();

    String minutes = String.format("%02d", new Object[] { beginDate.getMinuteOfHour() });

    Object[] args = { evaluation.getFullName(), date, beginDate.getHourOfDay(), minutes,
            beanWithVigilants.getRoomsAsString(), teachersVigilancies, convokedVigilants,
            beanWithVigilants.getSelectedVigilantGroup().getRulesLink() };
    beanWithVigilants.setEmailMessage(format.format(args));
    request.setAttribute("bean", beanWithVigilants);
    return mapping.findForward("confirmConvokes");
}

From source file:pt.ist.fenixWebFramework.rendererExtensions.DateTimeDataDependentRenderer.java

License:Open Source License

@Override
protected Layout getLayout(Object object, Class type) {
    if (object == null) {
        return super.getLayout(object, type);
    }//from   w  w w .j a  v a  2 s.  com

    DateTime dateTime = (DateTime) object;
    if (dateTime.getHourOfDay() == 0 && dateTime.getMinuteOfHour() == 0) {
        setFormat(getFormatWithoutTime());
    } else {
        setFormat(getFormatWithTime());
    }

    return super.getLayout(object, type);
}

From source file:pt.utl.ist.codeGenerator.database.WrittenTestsRoomManager.java

License:Open Source License

public DateTime getNextDateTime(final ExecutionSemester executionPeriod) {
    EvaluationRoomManager evaluationRoomManager = evaluationRoomManagerMap.get(executionPeriod);
    if (evaluationRoomManager == null) {
        evaluationRoomManager = new EvaluationRoomManager(
                executionPeriod.getBeginDateYearMonthDay().plusMonths(1).toDateTimeAtMidnight(),
                executionPeriod.getEndDateYearMonthDay().minusDays(31).toDateTimeAtMidnight(), 120, this);
        evaluationRoomManagerMap.put(executionPeriod, evaluationRoomManager);
    }/*from   w ww  .j av a2s .  c  o  m*/

    DateTime dateTime;
    Space oldRoom;

    do {
        dateTime = evaluationRoomManager.getNextDateTime();
        oldRoom = evaluationRoomManager.getNextOldRoom();

    } while (SpaceUtils.isFree(oldRoom, dateTime.toYearMonthDay(), dateTime.plusMinutes(120).toYearMonthDay(),
            new HourMinuteSecond(dateTime.getHourOfDay(), dateTime.getMinuteOfHour(),
                    dateTime.getSecondOfMinute()),
            dateTime.plusMinutes(120).getHourOfDay() == 0
                    ? new HourMinuteSecond(dateTime.plusMinutes(119).getHourOfDay(),
                            dateTime.plusMinutes(119).getMinuteOfHour(),
                            dateTime.plusMinutes(119).getSecondOfMinute())
                    : new HourMinuteSecond(dateTime.plusMinutes(120).getHourOfDay(),
                            dateTime.plusMinutes(120).getMinuteOfHour(),
                            dateTime.plusMinutes(120).getSecondOfMinute()),
            new DiaSemana(dateTime.getDayOfWeek() + 1), FrequencyType.DAILY, Boolean.TRUE, Boolean.TRUE));
    return dateTime;
}