Example usage for org.joda.time DateTime toLocalDateTime

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

Introduction

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

Prototype

public LocalDateTime toLocalDateTime() 

Source Link

Document

Converts this object to a LocalDateTime with the same datetime and chronology.

Usage

From source file:org.smartdeveloperhub.harvesters.it.testing.generator.ProjectActivityGenerator.java

License:Apache License

private boolean mustCloseIssue(final Issue issue, final LocalDateTime now) {
    long threshold = 80;
    final DateTime dueTo = issue.getDueTo();
    if (dueTo != null) {
        final double mark = toPOSIXMillis(now);
        final double opened = toPOSIXMillis(issue.getOpened().toLocalDateTime());
        final double deadline = toPOSIXMillis(dueTo.toLocalDateTime());
        final double maxDeadline = toPOSIXMillis(dueTo.toLocalDateTime().plusDays(14));
        final long onTime = DoubleMath.roundToLong(90 * ((mark - opened) / (deadline - opened)),
                RoundingMode.CEILING);
        final long delayed = DoubleMath.roundToLong(
                10 * (Math.max(0, mark - deadline) / (maxDeadline - deadline)), RoundingMode.CEILING);
        threshold = onTime + delayed;//from  ww  w .j  ava 2s  .  c o m
    }
    return this.random.nextInt(100) < threshold;
}

From source file:org.smartdeveloperhub.harvesters.it.testing.generator.Utils.java

License:Apache License

static LocalDateTime toLocalDateTime(final DateTime dateTime) {
    LocalDateTime result = null;// w w w. ja v  a  2s  . c o  m
    if (dateTime != null) {
        result = dateTime.toLocalDateTime();
    }
    return result;
}

From source file:org.specrunner.converters.core.ConverterLocalDateTimePatternArgs.java

License:Open Source License

@Override
public Object convert(Object value, Object[] args) throws ConverterException {
    if (value instanceof LocalDateTime) {
        return value;
    }/*from   w w w . j  a  v  a 2 s. co  m*/
    DateTime date = (DateTime) super.convert(value, args);
    return date != null ? date.toLocalDateTime() : null;
}

From source file:sos.scheduler.CheckRunHistory.JobSchedulerCheckRunHistory.java

License:Apache License

/**
 * //  w  w  w .ja v  a2  s.  c  om
 * \brief Execute - Start the Execution of JobSchedulerCheckRunHistory
 * 
 * \details
 * 
 * For more details see
 * 
 * \see JobSchedulerAdapterClass 
 * \see JobSchedulerCheckRunHistoryMain
 * 
 * \return JobSchedulerCheckRunHistory
 *
 * @return
 */
public JobSchedulerCheckRunHistory Execute() throws Exception {
    final String conMethodName = conClassName + "::Execute"; //$NON-NLS-1$
    logger.info(conSVNVersion);
    logger.debug(String.format(Messages.getMsg("JSJ-I-110"), conMethodName));
    try {
        Object objSp = objJSCommands.getSpoolerObject();
        boolean flgRunAsSchedulerAPIJob = objSp != null;

        @SuppressWarnings("unused")
        String strOperation = Options().operation.Value();
        String strJobName = Options().JobName.Value();
        String strMessage = Options().message.Value();
        String strMailTo = Options().mail_to.Value();
        String strMailCc = Options().mail_cc.Value();
        String strMailBcc = Options().mail_bcc.Value();

        strMessage = Messages.getMsg("JCH_T_0001", strJobName,
                myReplaceAll(strMessage, "\\[?JOB_NAME\\]?", strJobName));
        Date objDateStartTime = Options().start_time.getDateObject();

        if (flgRunAsSchedulerAPIJob) {
            Spooler objSpooler = (Spooler) objSp;
            Mail objMail = objSpooler.log().mail();
            if (isNotEmpty(strMailTo)) {
                objMail.set_to(strMailTo);
            }
            if (isNotEmpty(strMailCc)) {
                objMail.set_cc(strMailCc);
            }
            if (isNotEmpty(strMailBcc)) {
                objMail.set_bcc(strMailBcc);
            }
            if (isNotEmpty(strMessage)) {
                objMail.set_subject(strMessage);
            }
            if (Options().SchedulerHostName.isDirty() == false) {
                Options().SchedulerHostName.Value(objSpooler.hostname());
            }
            if (Options().scheduler_port.isDirty() == false) {
                Options().scheduler_port.value(objSpooler.tcp_port());
            }
        }

        //         if(!flgRunAsSchedulerAPIJob) {
        //            Options().SchedulerHostName.isMandatory(true);
        //            Options().scheduler_port.isMandatory(true);
        //         }

        Options().CheckMandatory();
        logger.debug(Options().toString());

        SchedulerObjectFactory objJSFactory = new SchedulerObjectFactory();
        objJSFactory.initMarshaller(ShowHistory.class);
        JSCmdShowHistory objShowHistory = objJSFactory.createShowHistory();
        objShowHistory.setJob(strJobName);
        objShowHistory.setPrev(BigInteger.valueOf(1));
        Answer objAnswer = null;

        //         if(flgRunAsSchedulerAPIJob) {
        //            String strShowHistoryXML = objShowHistory.toXMLString();
        //            String answerXML = objJSCommands.executeXML(strShowHistoryXML);
        //            objAnswer = objShowHistory.getAnswer(answerXML);
        //         }
        //         else {
        objJSFactory.Options().ServerName.Value(Options().SchedulerHostName.Value());
        objJSFactory.Options().PortNumber.value(Options().scheduler_port.value());
        objShowHistory.run();
        objAnswer = objShowHistory.getAnswer();
        //         }

        if (objAnswer != null) {
            ERROR objError = objAnswer.getERROR();
            if (objError != null) {
                throw new JSCommandErrorException(objError.getText());
            }
            List<HistoryEntry> objHistoryEntries = objAnswer.getHistory().getHistoryEntry();
            if (objHistoryEntries.size() == 0) {
                logger.error(Messages.getMsg("JCH_E_0001", strJobName));
                throw new JobSchedulerException(Messages.getMsg("JCH_E_0001", strJobName));
            } else {
                HistoryEntry objHistoryEntry = objHistoryEntries.get(0);
                String strErrorText = objHistoryEntry.getErrorText();
                String strEndTime = objHistoryEntry.getEndTime();
                DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'H:mm:ss.SSSZ");
                DateTime objEndDateTime = dateTimeFormatter
                        .parseDateTime(strEndTime.replaceFirst("Z", "+00:00"));
                DateTime objStartDateTime = new DateTime(objDateStartTime);
                //Date objDateEndTime = SOSDate.getDate(strEndTime, SOSDate.dateTimeFormat);
                //boolean flgRunTooLate = objDateEndTime.before(objDateStartTime);
                boolean flgRunSuccessful = isEmpty(strErrorText);
                boolean flgRunTooLate = objEndDateTime.toLocalDateTime()
                        .isBefore(objStartDateTime.toLocalDateTime());

                if (flgRunTooLate || !flgRunSuccessful) {
                    //logger.info(Messages.getMsg("JCH_I_0001", strJobName, strEndTime));
                    logger.info(Messages.getMsg("JCH_I_0001", strJobName, objEndDateTime.toString()));
                    if (!flgRunSuccessful) {
                        logger.info(Messages.getMsg("JCH_I_0002", strErrorText));
                    }
                    logger.error(strMessage);
                    throw new JobSchedulerException(strMessage);
                } else {
                    //logger.info(Messages.getMsg("JCH_I_0003", strJobName, strEndTime));
                    logger.info(Messages.getMsg("JCH_I_0003", strJobName, objEndDateTime.toString()));
                }
            }
        } else {
            throw new JobSchedulerException(Messages.getMsg("JSJ_E_0140", Options().SchedulerHostName.Value(),
                    Options().scheduler_port.value()));
        }
    } catch (Exception e) {
        //         e.printStackTrace(System.err);
        logger.error(Messages.getMsg("JSJ-F-107", conMethodName), e);
        throw e;
    }
    return this;
}

From source file:test.utilities.SemStoreLeakConverter.java

License:Apache License

void processLine(String line, PrintStream ps) throws Exception {

    if (line == null)
        return;//www .  ja v a  2 s  .  c  o  m

    StringTokenizer tokens = new StringTokenizer(line);
    if (tokens.countTokens() == 0)
        return;

    String dstr = tokens.nextToken();
    String tstr = tokens.nextToken();

    String datestr = dstr + "T" + tstr;

    DateTime dtime = new DateTime(datestr);

    // peel off Info:
    String info = tokens.nextToken();
    // peel off [Event
    String event = tokens.nextToken();
    // grab hold of operation with trailing ]
    String operation = tokens.nextToken();
    int bracket = operation.indexOf(']');
    if (bracket > 0)
        operation = operation.substring(0, bracket);

    // type of TripleStore in hand
    String storeType = tokens.nextToken();

    // the operation again
    String op = tokens.nextToken();

    // the address
    String addrStr = tokens.nextToken();
    int eq = addrStr.indexOf('=');
    if (eq > 0)
        addrStr = addrStr.substring(eq + 1);

    String memsize = null;
    // if it's a created line, we might have a trailing , and a mem size out there
    if (op.equals("created:")) {
        int comma = addrStr.indexOf(',');
        if (comma > 0)
            addrStr = addrStr.substring(0, comma);
        try {
            memsize = tokens.nextToken();
            if (memsize != null) {
                eq = memsize.indexOf('=');
                if (eq > 0)
                    memsize = memsize.substring(eq + 1);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
        }
    }

    int month = dtime.monthOfYear().get();
    int day = dtime.monthOfYear().get();
    int hour = dtime.hourOfDay().get();
    int minute = dtime.minuteOfHour().get();
    int seconds = dtime.secondOfMinute().get();
    int millis = dtime.millisOfSecond().get();

    // construct a key
    String subject = "tstore:" + dtime.year().getAsText() + (month < 10 ? "0" + month : month)
            + (day < 10 ? "0" + day : day) + (hour < 10 ? "0" + hour : hour)
            + (minute < 10 ? "0" + minute : minute) + (seconds < 10 ? "0" + seconds : seconds) + "."
            + (millis < 100 ? "0" : "") + (millis < 10 ? "0" + millis : millis) + "_" + operation;

    ps.println(subject + "\t" + "tstore:timestamp" + "\t\"" + dtime.toLocalDateTime() + "\"^^xsd:dateTime .");
    ps.println(subject + "\t" + "tstore:type" + "\t\"" + operation + "\" .");
    ps.println(subject + "\t" + "tstore:address" + "\t\"" + addrStr + "\" .");
    if (memsize != null)
        ps.println(subject + "\t" + "tstore:memsize" + "\t\"" + memsize + "\"^^xsd:integer .");
    ps.println("");

}