Example usage for org.joda.time DateTime getMillis

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

Introduction

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

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java

License:Open Source License

/**
 * Decodiere die Nachricht ber einen Logverzeichniseintrag Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from ww w .j  a v  a 2  s.c o  m
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 05.05.2012
 * @param entryMsg
 * @return
 */
private String decodeLogDirEntry(String entryMsg) {
    // Message etwa so <~41:21:9_4_10_20_44_55.txt:22>
    String[] fields;
    String fileName;
    int number, max;
    int day, month, year, hour, minute, second;
    //
    // Felder aufteilen
    fields = fieldPatternDp.split(entryMsg);
    if (fields.length < 4) {
        lg.error("recived message for logdir has lower than 4 fields. It is wrong! Abort!");
        return (null);
    }
    // Wandel die Nummerierung in Integer um
    try {
        number = Integer.parseInt(fields[1], 16);
        max = Integer.parseInt(fields[3], 16);
    } catch (NumberFormatException ex) {
        lg.error("Fail to convert Hex to int: " + ex.getLocalizedMessage());
        return (null);
    }
    fileName = fields[2];
    // verwandle die Dateiangabe in eine lesbare Datumsangabe
    // Format des Strings ist ja
    // TAG_MONAT_JAHR_STUNDE_MINUTE_SEKUNDE
    // des Beginns der Aufzeichnung
    fields = fieldPatternUnderln.split(fields[2]);
    try {
        day = Integer.parseInt(fields[0]);
        month = Integer.parseInt(fields[1]);
        year = Integer.parseInt(fields[2]) + 2000;
        hour = Integer.parseInt(fields[3]);
        minute = Integer.parseInt(fields[4]);
        second = Integer.parseInt(fields[5]);
    } catch (NumberFormatException ex) {
        lg.error("Fail to convert Hex to int: " + ex.getLocalizedMessage());
        return (null);
    }
    // So, die Angaben des SPX sind immer im Localtime-Format
    // daher werde ich die auch so interpretieren
    // Die Funktion macht das in der default-Lokalzone, sollte also
    // da sein, wio der SPX auch ist... (schwieriges Thema)
    DateTime tm = new DateTime(year, month, day, hour, minute, second);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(timeFormatterString);
    return (String.format("%d;%s;%s;%d;%d", number, fileName, tm.toString(fmt), max, tm.getMillis()));
}

From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PgExpressionHandler.java

License:Open Source License

@Override
public Expression<?> visit(DateTimeConstant node) {
    DateTime value = node.getValue();
    DateTimeZone zone = value.getZone();
    return new ConstantDateTimeExpression(new Timestamp(value.getMillis()), zone == DateTimeZone.UTC);
}

From source file:de.geeksfactory.opacclient.frontend.MainPreferenceFragment.java

License:MIT License

private void refreshLastConfigUpdate(Preference updateLibraryConfig) {
    DateTime lastUpdate = new PreferenceDataSource(context).getLastLibraryConfigUpdate();
    if (lastUpdate != null) {
        CharSequence lastUpdateStr = DateUtils.getRelativeTimeSpanString(context, lastUpdate.getMillis(), true);
        updateLibraryConfig.setSummary(getString(R.string.library_config_last_update, lastUpdateStr));
    } else {//w  ww.ja  va 2 s .co m
        updateLibraryConfig.setSummary(getString(R.string.library_config_last_update_never));
    }
}

From source file:de.hpi.bpmn2_0.animation.AnimationJSONBuilder.java

License:Open Source License

protected JSONObject parseSequenceFlow(AnimationLog animationLog, SequenceFlow sequenceFlow)
        throws JSONException {

    if (((TraceNode) (sequenceFlow.getSourceRef())).getStart() == null
            || ((TraceNode) sequenceFlow.getTargetRef()).getStart() == null) {
        return null;
    }//from  ww w.  java 2  s .  c om

    JSONObject json = new JSONObject();
    json.put("id", sequenceFlow.getId());

    //DateTime logStart = animationLog.getStartDate();
    DateTime logStart = totalRealInterval.getStart(); //Bruce 15.06.2015: fix bug of playing multiple logs with different start dates
    DateTime start = ((TraceNode) sequenceFlow.getSourceRef()).getComplete();
    DateTime end = ((TraceNode) sequenceFlow.getTargetRef()).getStart();
    double begin = Seconds.secondsBetween(logStart, start).getSeconds() * this.getTimeConversionRatio();
    //double duration = Seconds.secondsBetween(start, end).getSeconds()*this.getTimeConversionRatio();
    double duration = (end.getMillis() - start.getMillis()) * this.getTimeConversionRatio(); // in milliseconds

    DecimalFormat df = new DecimalFormat("#.#####");
    json.put("begin", df.format(begin));
    json.put("dur", df.format(1.0 * duration / 1000));

    /*
    if (((TraceNode)sequenceFlow.getSourceRef()).isVirtual()) {
    json.put("sourceIsVirtual", "true");
    } else {
    json.put("sourceIsVirtual", "false");
    }
    */

    return json;
}

From source file:de.hpi.bpmn2_0.animation.AnimationJSONBuilder.java

License:Open Source License

protected JSONObject parseNode(AnimationLog animationLog, TraceNode node) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("id", node.getId());

    //DateTime logStart = animationLog.getStartDate();
    DateTime logStart = totalRealInterval.getStart(); //Bruce 15.06.2015: fix bug of multiple logs with different start dates
    DateTime start = node.getStart();//from   w w  w .j a v a  2 s . c o  m
    DateTime end = node.getComplete();
    double begin = Seconds.secondsBetween(logStart, start).getSeconds() * this.getTimeConversionRatio();
    //double duration = Seconds.secondsBetween(start, end).getSeconds()*this.getTimeConversionRatio();
    double duration = (end.getMillis() - start.getMillis()) * this.getTimeConversionRatio(); // in milliseconds

    DecimalFormat df = new DecimalFormat("#.#####");
    json.put("begin", df.format(begin));
    json.put("dur", df.format(1.0 * duration / 1000));

    if (node.isActivitySkipped()) {
        json.put("isVirtual", "true");
    } else {
        json.put("isVirtual", "false");
    }
    return json;
}

From source file:de.hpi.bpmn2_0.animation.AnimationJSONBuilder.java

License:Open Source License

/**
 * Generate json for the progress bar//from  ww w. jav a2  s. c  o  m
 * @param animationLog
 * @return
 * @throws JSONException 
 * Bruce 24.08.2015: fix bug of start time and duration of the progress bar
 * Add begin and duration attribute for the progress log tag, similar to SequenceFlow
 */
protected JSONObject parseLogProgress(AnimationLog animationLog) throws JSONException {
    String keyTimes = "";
    String values = "";
    final int PROGRESS_BAR_LEVELS = 100; //divide the progress bar into 100 levels
    final int TOTAL_TRACES = animationLog.getTraces().size();

    DateTime logStart = animationLog.getStartDate();
    DateTime logEnd = animationLog.getEndDate();
    double begin = Seconds.secondsBetween(totalRealInterval.getStart(), logStart).getSeconds()
            * this.getTimeConversionRatio();
    double durEngine = (logEnd.getMillis() - logStart.getMillis()) * this.getTimeConversionRatio(); // in milliseconds  
    double durData = logEnd.getMillis() - logStart.getMillis(); // in milliseconds  
    double levelTime = 1.0 * durData / (1000 * PROGRESS_BAR_LEVELS); //number of seconds for every movement level

    //-------------------------------------------
    // The progress bar is divided into PROGRESS_BAR_LEVELS levels
    // Remember: keyTimes is the percentage relative to begin and duration value, within 0-1 range,
    // values are relative to the length of the progress bar and must start from 0.        
    // Calculate keyTimes: the percentage of the current level number over the total number of levels
    // Calculate values: move to every level, calculate the level timestamp, then count
    // the total number of traces that end after that timestamp
    //-------------------------------------------
    DateTime currentLevelTimestamp;
    int traceCount;
    double keyTimeVal;
    double totalVal = 2 * Math.PI * params.getProgressCircleBarRadius(); //the perimeter of the progress circle bar
    DecimalFormat df = new DecimalFormat("#.##");

    for (int i = 1; i <= PROGRESS_BAR_LEVELS; i++) {
        keyTimeVal = 1.0 * i / PROGRESS_BAR_LEVELS; //params.getTimelineSlots();
        currentLevelTimestamp = logStart.plusSeconds(Double.valueOf(i * levelTime).intValue());
        traceCount = 0;
        for (ReplayTrace trace : animationLog.getTraces()) {
            if (trace.getInterval().getEnd().isBefore(currentLevelTimestamp)
                    || trace.getInterval().getEnd().isEqual(currentLevelTimestamp)) {
                traceCount++;
            }
        }
        if (i == 1) {
            keyTimes += "0;"; //required by SVG keytimes specification
            values += "0;"; //required by SVG values specification
        } else if (i == PROGRESS_BAR_LEVELS) {
            keyTimes += "1;"; //required by SVG keyTimes specification
            values += (df.format(totalVal) + ";"); //(Math.round((1.0*traceCount/animationLog.getTraces().size())*totalVal) + ";");
        } else {
            keyTimes += (df.format(keyTimeVal) + ";");
            double value = (1.0 * traceCount / TOTAL_TRACES) * totalVal;
            values += (df.format(value) + ";");
        }
    }
    if (keyTimes.length() > 0) {
        keyTimes = keyTimes.substring(0, keyTimes.length() - 1);
    }
    if (values.length() > 0) {
        values = values.substring(0, values.length() - 1);
    }

    JSONObject json = new JSONObject();
    json.put("keyTimes", keyTimes);
    json.put("values", values);

    df.applyPattern("#.#####");
    json.put("begin", df.format(begin));
    json.put("dur", df.format(1.0 * durEngine / 1000));

    return json;
}

From source file:de.hpi.bpmn2_0.animation.AnimationJSONBuilder.java

License:Open Source License

protected JSONArray parseTraceStartDates() {
    SortedSet<DateTime> sortedDates = new TreeSet<>(new Comparator<DateTime>() {
        @Override/* w  w w  .ja  va2 s  . c  om*/
        public int compare(DateTime o1, DateTime o2) {
            return o1.compareTo(o2);
        }
    });
    for (AnimationLog log : animations) {
        for (ReplayTrace trace : log.getTraces()) {
            sortedDates.add(trace.getStartDate());
        }
    }

    JSONArray jsonArray = new JSONArray();
    for (DateTime dateTime : sortedDates) {
        jsonArray.put(dateTime.getMillis());
    }

    return jsonArray;
}

From source file:de.ifgi.fmt.mongo.conv.DateTimeConverter.java

License:Open Source License

/**
 * //from w  w w  . ja  va  2 s .c  om
 * @param value
 * @param optionalExtraInfo
 * @return
 */
@Override
public Object encode(Object value, MappedField optionalExtraInfo) {
    if (value == null)
        return null;
    DateTime dt = (DateTime) value;
    return new Date(dt.getMillis());
}

From source file:de.ii.ldproxy.service.LdProxyServiceStoreDefault.java

License:Apache License

@Override
protected void writeResource(String[] path, String resourceId, ResourceTransaction.OPERATION operation,
        LdProxyService resource) throws IOException {
    // caution: for update operations, "resource" contains only the changes, not the actual service
    LdProxyService service = resource;//from ww w. ja  va  2  s. com

    DateTime now = new DateTime();

    switch (operation) {
    case DELETE:
        service = getResource(path, resourceId);
        service.stop();
        break;
    case ADD:
        resource.setDateCreated(now.getMillis());
    case UPDATE:
    case UPDATE_OVERRIDE:
        resource.setLastModified(now.getMillis());
        break;
    }

    super.writeResource(path, resourceId, operation, resource);
    if (operation != ResourceTransaction.OPERATION.DELETE) {
        service = getResource(path, resourceId);
    }
    switch (operation) {
    case ADD:
        service.initialize(path, httpClient, sslHttpClient, staxFactory, jsonMapper, crsTransformation);
        service.initialize(indexStore, sparqlAdapter);
    case UPDATE:
    case UPDATE_OVERRIDE:
        if (service.getTargetStatus() == Service.STATUS.STARTED) {
            service.start();
        }
    }
}

From source file:de.iteratec.iteraplan.persistence.dao.HistoryDAOImpl.java

License:Open Source License

public <T extends BuildingBlock> int getHistoryLengthFor(Class<T> entityClass, Integer id, DateTime fromDate,
        DateTime toDate) {/*  w w w  . j  ava 2  s.  c  o  m*/
    Preconditions.checkArgument(id != null && id.intValue() >= 0, "Param id is invalid, should be >=0");
    AuditReader auditReader = getAuditReader();
    AuditQuery totalCountQuery = auditReader.createQuery().forRevisionsOfEntity(entityClass, false, false)
            .add(AuditEntity.id().eq(id));

    if (fromDate != null) {
        Long fromDateLong = Long.valueOf(fromDate.getMillis());
        totalCountQuery.add(AuditEntity.revisionProperty(TIMESTAMP_PROPERTY).ge(fromDateLong));
    }
    if (toDate != null) {
        Long toDateLong = Long.valueOf(toDate.getMillis());
        totalCountQuery.add(AuditEntity.revisionProperty(TIMESTAMP_PROPERTY).le(toDateLong));
    }

    // Can't get the total count from the other query because it might be limited to results of the current page
    return totalCountQuery.getResultList().size();
}