Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

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

Prototype

public LocalDateTime() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

From source file:de.avanux.smartapplianceenabler.semp.webservice.SempController.java

License:Open Source License

@RequestMapping(value = BASE_URL + "/PlanningRequest", method = RequestMethod.GET, produces = "application/xml")
@ResponseBody//  w  w  w .  j  a  v a2  s.c o m
public String planningRequest(@RequestParam(value = "DeviceId", required = false) String deviceId) {
    LocalDateTime now = new LocalDateTime();
    List<PlanningRequest> planningRequests = new ArrayList<PlanningRequest>();
    if (deviceId != null) {
        ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, deviceId);
        applianceLogger.debug("Planning request requested");
        Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceId);
        PlanningRequest planningRequest = createPlanningRequest(applianceLogger, now, appliance);
        addPlanningRequest(planningRequests, planningRequest);
    } else {
        logger.debug("Planning request requested of all devices");
        List<Appliance> appliances = ApplianceManager.getInstance().getAppliances();
        for (Appliance appliance : appliances) {
            ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, appliance.getId());
            PlanningRequest planningRequest = createPlanningRequest(applianceLogger, now, appliance);
            addPlanningRequest(planningRequests, planningRequest);
        }
    }
    Device2EM device2EM = new Device2EM();
    if (planningRequests.size() > 0) {
        device2EM.setPlanningRequest(planningRequests);
    }
    return marshall(device2EM);
}

From source file:edu.harvard.med.screensaver.io.workbook2.Cell.java

License:Open Source License

/**
 * Get an <code>Date</code> value for the cell.
 * //w ww  .j  a v  a2s  . co  m
 * @return a <code>Date</code> value if cell contains a valid date; if cell
 *         does not contain a date or an error occurs <code>null</code> is
 *         returned, unless cell is required, in which case the current date
 *         is returned (to allow parsing code to proceed w/a default value)
 *         contain a value
 */
public LocalDateTime getDate() {
    try {
        jxl.Cell cell = getJxlCell();
        if (cell.getType() == CellType.EMPTY) {
            if (_required) {
                addError(CELL_VALUE_REQUIRED_ERROR);
                return new LocalDateTime();
            }
            return null;
        }
        Date date = ((DateCell) cell).getDate();
        return convertGmtDateToLocalTimeZone(date);
    } catch (CellOutOfRangeException e) {
        if (_required) {
            addError(CELL_VALUE_REQUIRED_ERROR);
            return new LocalDateTime();
        }
        return null;
    } catch (ClassCastException e) {
        if (_required) {
            addError(INVALID_CELL_TYPE_ERROR + " (expected a date)");
            return new LocalDateTime();
        }
        return null;
    }
}

From source file:ee.ut.soras.ajavtV2.Main.java

License:Open Source License

/**
 *    Loob etteantud sisends6ne p6hjal referentsaja: granulaarsuste <i>aasta, kuu, kuupaev,
 *    tund, minut</i> vaartuste j2rjendi. Kui sisends6ne ei rahulda regulaaravaldisi 
 *    <code>/[0-9X]{4}-[0-9X]{2}-[0-9X]{2}T[0-9X]{2}:[0-9X]{2}/</code> vi
 *    <code>/[0-9X]{4}-[0-9X]{2}-[0-9X]{2}/</code> , tagastatakse null.
 *    Kui sisends6ne on null, luuakse referentsaja j2rjend minuti-t2psusega hetkeaja p6hjal.
 *    <br><br> // ww w  .j  a  v  a  2  s  . c  o m
 *    Tagastatud j2rjendis on granulaarsuste vaartused j2rjekorras 
 *    <i>aasta, kuu, kuupaev, tund, minut</i>. 
 */
public static String[] looSonePohjalReferentsAeg(String sone) {
    if (sone != null) {
        if (sone.matches("[0-9X]{4}-[0-9X]{2}-[0-9X]{2}T[0-9X]{2}:[0-9X]{2}")) {
            // 1) Kui sisends6ne vastab etteantud mustrile
            String[] kalendriValjadeVaartused = new String[5];
            int j = 0;
            boolean seenXXXvalues = false;
            StringTokenizer tokens1 = new StringTokenizer(sone, "-:T");
            while (tokens1.hasMoreTokens()) {
                String s = (String) tokens1.nextToken();
                if (j < kalendriValjadeVaartused.length) {
                    kalendriValjadeVaartused[j] = s;
                }
                if (s.matches("X+")) {
                    seenXXXvalues = true;
                } else {
                    if (seenXXXvalues) {
                        // Kui on l2bisegi numbrid ja XX-v22rtused, on tegemist mitte-
                        // koosk6lalise  sisendajaga:   parandame   numbrid   XX-ideks
                        kalendriValjadeVaartused[j] = "XX";
                    }
                }
                if (j < kalendriValjadeVaartused.length) {
                    j++;
                }
            }
            return kalendriValjadeVaartused;
        } else if (sone.matches("^[0-9X]{4}-[0-9X]{2}-[0-9X]{2}$")) {
            // 2) Kui sisends6ne vastab etteantud mustrile
            String[] kalendriValjadeVaartused = new String[5];
            int j = 0;
            boolean seenXXXvalues = false;
            StringTokenizer tokens2 = new StringTokenizer(sone, "-");
            while (tokens2.hasMoreTokens()) {
                String s = (String) tokens2.nextToken();
                if (j < kalendriValjadeVaartused.length) {
                    kalendriValjadeVaartused[j] = s;
                }
                if (s.matches("X+")) {
                    seenXXXvalues = true;
                } else {
                    if (seenXXXvalues) {
                        // Kui on l2bisegi numbrid ja XX-v22rtused, on tegemist mitte-
                        // koosk6lalise  sisendajaga:   parandame   numbrid   XX-ideks
                        kalendriValjadeVaartused[j] = "XX";
                    }
                }
                if (j < kalendriValjadeVaartused.length) {
                    j++;
                }
            }
            // Viimased (kellaaja osa) ongi selle mustri puhul teadmata
            kalendriValjadeVaartused[3] = "XX";
            kalendriValjadeVaartused[4] = "XX";
            return kalendriValjadeVaartused;
        }
        return null;
    } else {
        // 2) Kui sisends6ne puudub v6i ei vasta etteantud mustrile, loome uue
        // referentsaja, milleks saab hetkeaeg
        LocalDateTime hetkeAeg = new LocalDateTime();
        String[] kalendriValjadeVaartused = new String[5];
        kalendriValjadeVaartused[0] = String.valueOf(hetkeAeg.getYear());
        kalendriValjadeVaartused[1] = String.valueOf(hetkeAeg.getMonthOfYear());
        kalendriValjadeVaartused[2] = String.valueOf(hetkeAeg.getDayOfMonth());
        kalendriValjadeVaartused[3] = String.valueOf(hetkeAeg.getHourOfDay());
        kalendriValjadeVaartused[4] = String.valueOf(hetkeAeg.getMinuteOfHour());
        for (int i = 1; i < kalendriValjadeVaartused.length; i++) {
            if (kalendriValjadeVaartused[i].length() == 1) {
                kalendriValjadeVaartused[i] = "0" + kalendriValjadeVaartused[i];
            }
        }
        return kalendriValjadeVaartused;
    }
}

From source file:energy.usef.agr.workflow.step.AgrNonUdiRetrieveAdsGoalRealizationStub.java

License:Apache License

private ConnectionGroupPortfolioDto handleCongestionPointConnectionGroupPortfolio(
        ConnectionGroupPortfolioDto connectionGroupPortfolioDto, LocalDate period, Integer ptuDuration) {
    Optional<CongestionManagementStatusDto> congestionManagementStatusDtoOptional = powerMatcher
            .retrieveCongestionPointAdsGoalRealization(connectionGroupPortfolioDto.getUsefIdentifier());
    congestionManagementStatusDtoOptional.ifPresent(congestionManagementStatusDto -> {
        Integer ptuIndex = PtuUtil.getPtuIndex(new LocalDateTime(), ptuDuration);
        updateObservedValue(connectionGroupPortfolioDto, period, ptuIndex,
                congestionManagementStatusDto.getCurrentAllocation().toBigInteger());

    });/* w  w  w . j a v a2  s  . c o m*/
    return connectionGroupPortfolioDto;
}

From source file:energy.usef.agr.workflow.step.AgrNonUdiRetrieveAdsGoalRealizationStub.java

License:Apache License

private ConnectionGroupPortfolioDto handleBrpConnectionGroupPortfolio(
        ConnectionGroupPortfolioDto connectionGroupPortfolioDto, LocalDate period, Integer ptuDuration) {
    Optional<ObjectiveAgentStatusDto> objectiveAgentStatusDtoOptional = powerMatcher
            .retrieveBrpAdsGoalRealization(connectionGroupPortfolioDto.getUsefIdentifier());
    objectiveAgentStatusDtoOptional.ifPresent(objectiveAgentStatusDto -> {
        Integer ptuIndex = PtuUtil.getPtuIndex(new LocalDateTime(), ptuDuration);
        updateObservedValue(connectionGroupPortfolioDto, period, ptuIndex,
                objectiveAgentStatusDto.getCurrentAllocation().toBigInteger());
    });// w  ww  .j  a  v a 2s. co  m
    return connectionGroupPortfolioDto;
}

From source file:energy.usef.core.util.DateTimeUtil.java

License:Apache License

private static LocalDateTime getTime() {
    if (useServer) {
        return getUDPTime();
    }/* w w  w  . j  a  v  a  2 s  .c  o m*/
    return new LocalDateTime();
}

From source file:energy.usef.core.util.DateTimeUtil.java

License:Apache License

private static synchronized LocalDateTime getUDPTime() {
    do {/*from   w  w  w .ja  va  2  s  .co m*/
        if (lastProcessed == null || lastProcessed.plusMillis(BUFFER_TIME).isBefore(new LocalDateTime())) {
            String udpTime = getUDPInfo(UDP_TIME);
            if (udpTime != null) {
                latestUDPDateTime = new LocalDateTime(udpTime);
                lastProcessed = new LocalDateTime();
            }
        }
    } while (latestUDPDateTime == null);
    return latestUDPDateTime;
}

From source file:es.ucm.fdi.avisos.util.CustomRssViewer.java

License:Open Source License

@Override
protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) {

    feed.setTitle("Feed de la Facultad de Informatica, Universidad Complutense de Madrid");
    feed.setDescription("Noticias acerca de la Fdi-UCM");
    feed.setLink("http://informatica.ucm.es");

    LocalDateTime today = new LocalDateTime();
    feed.setLastBuildDate(today.toDate());

    super.buildFeedMetadata(model, feed, request);
}

From source file:femr.util.calculations.dateUtils.java

License:Open Source License

public static String getCurrentDateTimeString() {
    DateTimeFormatter dateFormat = DateTimeFormat.forPattern("yyyy/mm/dd HH:mm:ss");
    LocalDateTime localDateTime = new LocalDateTime();
    dateFormat.print(localDateTime);//  w  w w  .  j  av  a 2s .  c o  m
    String dt = localDateTime.toString();
    return dt;
}

From source file:fr.mycellar.application.user.impl.ResetPasswordRequestServiceImpl.java

License:Open Source License

@Override
public void createAndSendEmail(User user, String url) {
    // Create request
    ResetPasswordRequest request = new ResetPasswordRequest();
    request.setDateTime(new LocalDateTime());
    request.setKey(new String(Base64.encodeBase64(secureRandom.generateSeed(128), false)).substring(0, 32));
    request.setUser(user);/*from w  ww.ja  v  a 2  s.c o m*/
    // Merge it in repository
    resetPasswordRequestRepository.save(request);
    // Send email to email
    final String email = user.getEmail();
    final String address;
    try {
        address = url + "?key=" + URLEncoder.encode(request.getKey(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("UTF-8 encoding not supported.", e);
    }

    MimeMessagePreparator mimeMessagePreparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
            helper.setTo(email);
            helper.setFrom(configurationService.getMailAddressSender());
            helper.setSubject("Changement de mot de passe");
            helper.setText("Allez  l'adresse suivante : " + address);
        }
    };
    try {
        javaMailSender.send(mimeMessagePreparator);
    } catch (Exception e) {
        throw new RuntimeException("Cannot send email.", e);
    }
}