Example usage for org.joda.time DateTime DateTime

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

Introduction

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

Prototype

public DateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:cl.usach.managedbeans.EscritorioManagedBean.java

public int obtenerSegundosDiff(Date inicio, Date fin) {
    DateTime dtI = new DateTime(inicio);
    DateTime dtF = new DateTime(fin);
    int tiempo = Seconds.secondsBetween(dtI, dtF).getSeconds();
    return tiempo;
}

From source file:cl.usach.managedbeans.EscritorioManagedBean.java

public String obtenerTiempo(Date inicio) {
    if (inicio == null)
        return "-";
    DateTime dtI = new DateTime(inicio);
    DateTime dtF = new DateTime(new Date());
    String tiempo = "";
    String aux;//from  ww  w.  j  a  va  2s .c  om
    if (Days.daysBetween(dtI, dtF).getDays() > 0)
        tiempo += Days.daysBetween(dtI, dtF).getDays() + " d, ";
    aux = Hours.hoursBetween(dtI, dtF).getHours() % 24 + ":";
    if (aux.length() == 2)
        aux = "0" + aux;
    tiempo += aux;
    aux = Minutes.minutesBetween(dtI, dtF).getMinutes() % 60 + "";
    if (aux.length() == 1)
        aux = "0" + aux;
    tiempo += aux + " hrs";
    return tiempo;
}

From source file:cl.usach.managedbeans.GraficoManagedBean.java

public Map<String, Number> inicializarMAP(Date fechai, Date fechaf) {
    Map<String, Number> valores = new HashMap<>();
    try {//  www.ja  v a 2 s.co m
        fechai = formatter.parse(formatter.format(fechai));
        fechaf = formatter.parse(formatter.format(fechaf));

        DateTime datei = new DateTime(fechai);
        DateTime datef = new DateTime(fechaf);

        int dias = Days.daysBetween(datei, datef).getDays();
        for (int i = 0; i <= dias; i++) {
            DateTime d = datei.withFieldAdded(DurationFieldType.days(), i);
            valores.put(formatter.format(d.toDate()), 0);
        }
        return valores;

    } catch (ParseException ex) {
        Logger.getLogger(GraficoManagedBean.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:cl.usach.managedbeans.TrabajoSemanalManagedBean.java

public List<Semana> buscarSemanas(Date datei, Date datef) {
    DateTime fechai = new DateTime(datei);
    DateTime fechaf = new DateTime(datef);
    LocalDate lunesI = fechai.toLocalDate().withDayOfWeek(DateTimeConstants.MONDAY);
    LocalDate domingoF = fechaf.toLocalDate().withDayOfWeek(DateTimeConstants.SUNDAY);

    List<Semana> semanas = new ArrayList<>();
    DateTime i = lunesI.toDateTimeAtStartOfDay();
    while (i.isBefore(domingoF.toDateTimeAtStartOfDay())) {
        DateTime domingoi = i.toLocalDate().withDayOfWeek(DateTimeConstants.SUNDAY).toDateTimeAtStartOfDay();
        domingoi = domingoi.plusHours(23).plusMinutes(59).plusSeconds(59);
        semanas.add(new Semana(i.toDate(), domingoi.toDate()));
        i = i.plusWeeks(1);/*from  w w w  .j  a v  a  2s  . com*/
    }
    return semanas;
}

From source file:Clases.Utils.java

public static int comparaHorario(Date horaEntrada, Date horaSalida) {
    int respuesta = 0;
    DateTime horaEntra = new DateTime(horaEntrada);
    DateTime horaSal = new DateTime(horaSalida);
    Period periodo = new Period(horaEntra, horaSal);
    respuesta = periodo.getHours();/*  ww w .  jav  a2  s. c  o m*/
    return respuesta;
}

From source file:classes.ManipulaDatas.java

public static long calculaAtraso(String dataVenc, String dataFim) {
    long calculo = 0;

    try {/*  w ww . j  a  v  a 2 s  .  co m*/
        java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("dd/MM/yyyy"); // criando um modelo de datas
        java.util.Date d1 = df.parse(dataVenc); //passando os valores das Strings para objetos do tipo Date
        java.util.Date d2 = df.parse(dataFim);

        DateTime dtf2 = new DateTime(d2);
        DateTime dtv2 = new DateTime(d1);

        Duration d = new Duration(dtf2, dtv2);
        long dias = (d.getStandardDays()) * -1;

        calculo = dias;
        calc_datas = calculo; //variavel global que armazena o conteudo do calculo

    } catch (ParseException ex) {
        Logger.getLogger(ManipulaDatas.class.getName()).log(Level.SEVERE, null, ex);
    }

    return calc_datas;
}

From source file:cmg.org.monitor.app.schedule.MailServiceScheduler.java

License:Open Source License

/**
 * Do schedule.//from  www.j  a v a  2  s  .  com
 */
public void doSchedule() {
    // BEGIN LOG
    UtilityDAO utilDAO = new UtilityDaoImpl();
    long start = System.currentTimeMillis();
    logger.log(Level.INFO, MonitorUtil.parseTime(start, true) + " -> START: Scheduled send alert mail ...");
    String currentZone = utilDAO.getCurrentTimeZone();
    DateTime dtStart = new DateTime(start);
    dtStart = dtStart.withZone(DateTimeZone.forID(currentZone));
    // BEGIN LOG
    String alertName = MonitorConstant.ALERTSTORE_DEFAULT_NAME + ": "
            + dtStart.toString(DateTimeFormat.forPattern(MonitorConstant.SYSTEM_DATE_FORMAT));
    SystemAccountDAO accountDao = new SystemAccountDaoImpl();
    SystemDAO sysDAO = new SystemDaoImpl();
    AlertDao alertDAO = new AlertDaoImpl();
    ArrayList<SystemMonitor> systems = sysDAO.listSystemsFromMemcache(false);

    MailMonitorDAO mailDAO = new MailMonitorDaoImpl();

    SystemGroupDAO groupDao = new SystemGroupDaoImpl();
    if (systems != null && systems.size() > 0) {
        ArrayList<UserMonitor> listUsers = utilDAO.listAllUsers();
        if (listUsers != null && listUsers.size() > 0) {
            for (UserMonitor user : listUsers) {
                for (SystemMonitor sys : systems) {
                    try {
                        SystemGroup gr = groupDao.getByName(sys.getGroupEmail());
                        if (gr != null) {
                            if (user.checkGroup(gr.getId())) {
                                user.addSystem(sys);
                            }
                        }
                    } catch (Exception e) {
                        logger.log(Level.WARNING, "Error: " + e.getMessage());
                    }
                }
            }

            for (UserMonitor user : listUsers) {
                if (user.getSystems() != null && user.getSystems().size() > 0) {
                    for (Object tempSys : user.getSystems()) {
                        AlertStoreMonitor alertstore = alertDAO.getLastestAlertStore((SystemMonitor) tempSys);
                        if (alertstore != null) {
                            alertstore.setName(alertName);
                            alertstore.setTimeStamp(new Date(start));
                            NotifyMonitor notify = null;
                            try {
                                notify = sysDAO.getNotifyOption(((SystemMonitor) tempSys).getCode());
                            } catch (Exception e) {
                            }
                            if (notify == null) {
                                notify = new NotifyMonitor();
                            }
                            alertstore.fixAlertList(notify);
                            if (alertstore.getAlerts().size() > 0) {
                                user.addAlertStore(alertstore);
                            }
                        }
                    }
                }
            }
        }
        List<GoogleAccount> googleAccs = null;
        try {
            googleAccs = accountDao.listAllGoogleAccount();
        } catch (Exception e1) {
            logger.log(Level.WARNING, "Error: " + e1.getMessage());
        }
        if (listUsers != null && listUsers.size() > 0 && googleAccs != null && googleAccs.size() > 0) {
            for (UserMonitor user : listUsers) {
                if (user.getUser().getDomain().equalsIgnoreCase(SystemUser.THIRD_PARTY_USER)) {
                    if (user.getStores() != null && user.getStores().size() > 0) {
                        MailConfigMonitor config = mailDAO.getMailConfig(user.getId());
                        MailService mailService = new MailService();
                        try {
                            String content = mailService.parseContent(user.getStores(), config);
                            MailAsync mailUtil = new MailAsync(new String[] { user.getId() }, alertName,
                                    content);
                            mailUtil.run();
                            logger.log(Level.INFO, "send mail" + content);
                        } catch (Exception e) {
                            logger.log(Level.INFO, "Can not send mail" + e.getMessage());
                        }

                    }
                }

            }

            for (GoogleAccount gAcc : googleAccs) {
                MailService mailService = new MailService(gAcc);
                for (UserMonitor user : listUsers) {
                    if (user.getUser().getDomain().equalsIgnoreCase(gAcc.getDomain())) {
                        if (user.getStores() != null && user.getStores().size() > 0) {
                            MailConfigMonitor config = mailDAO.getMailConfig(user.getId());
                            try {
                                String content = mailService.parseContent(user.getStores(), config);
                                mailService.sendMail(alertName, content, config);
                                logger.log(Level.INFO, "send mail" + content);
                            } catch (Exception e) {
                                logger.log(Level.INFO, "Can not send mail" + e.getMessage());
                            }

                        }
                    }

                }
            }
            for (SystemMonitor sys : systems) {
                AlertStoreMonitor store = alertDAO.getLastestAlertStore(sys);
                alertDAO.putAlertStore(store);
                alertDAO.clearTempStore(sys);
            }

        }
        for (SystemMonitor sys : systems) {
            AlertStoreMonitor asm = alertDAO.getLastestAlertStore(sys);
            if (asm == null) {
                asm = new AlertStoreMonitor();
            }
            asm.setCpuUsage(sys.getLastestCpuUsage());
            asm.setMemUsage(sys.getLastestMemoryUsage());
            asm.setSysId(sys.getId());
            asm.setName(alertName);
            asm.setTimeStamp(new Date(start));
            alertDAO.putAlertStore(asm);
            alertDAO.clearTempStore(sys);
        }
    } else {
        logger.log(Level.INFO, "NO SYSTEM FOUND");
    }

    /*
     * mailDAO.getMailConfig(maiId); mailService.sendMail(subject, content,
     * mailConfig);
     */

    // END LOG
    long end = System.currentTimeMillis();
    long time = end - start;
    logger.log(Level.INFO, MonitorUtil.parseTime(end, true)
            + " -> END: Scheduled send alert mail. Time executed: " + time + " ms");
    // END LOG

}

From source file:cmg.org.monitor.ext.util.DateTimeUtils.java

License:Open Source License

public static Date convertDateWithZone(Date input) {
    if (currentZone == null) {
        Object obj = MonitorMemcache.get(Key.create(Key.CURRENT_ZONE));
        if (obj != null && obj instanceof String) {
            currentZone = (String) obj;
        } else {// w  w  w  .  j a  va 2s  .  c  o m
            currentZone = MonitorConstant.DEFAULT_SYSTEM_TIME_ZONE;
        }
    }

    DateTime temp = new DateTime(input);

    return temp.withZone(DateTimeZone.forID(currentZone)).toDate();
}

From source file:cmg.org.monitor.services.GoogleAccountService.java

License:Open Source License

/**
 * Gets the timestamp string.//from  w  w  w  .  ja v  a 2  s  .co  m
 *
 * @return the timestamp string
 */
private String getTimestampString() {
    DateTime t = new DateTime(new Date(System.currentTimeMillis()));
    t = t.withZone(DateTimeZone.forID(currentZone));
    return t.toString(DateTimeFormat.forPattern("dd/MM/yyyy hh:mm:ss.SSS"));
}

From source file:cn.cuizuoli.appranking.typehandler.DateTimeTypeHandler.java

License:Apache License

@Override
public DateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
    DateTime dateTime = null;/*from  w  ww .j a v  a2 s .  c om*/
    Timestamp timestamp = rs.getTimestamp(columnName);
    if (timestamp != null) {
        dateTime = new DateTime(timestamp);
    }
    return dateTime;
}