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:com.cfelde.cron4joda.SchedulingPattern.java

License:Open Source License

/**
 * This methods returns true if the given timestamp (expressed as a UNIX-era
 * millis value) matches the pattern, according to the given time zone.
 *
 * @param timezone A time zone.// w w  w  .  j  a v a  2s  .  com
 * @param millis The timestamp, as a UNIX-era millis value.
 * @return true if the given timestamp matches the pattern.
 */
public boolean match(DateTime dt) {
    int minute = dt.getMinuteOfHour();
    int hour = dt.getHourOfDay();
    int dayOfMonth = dt.getDayOfMonth();
    int month = dt.getMonthOfYear(); //gc.get(Calendar.MONTH) + 1;
    int dayOfWeek = dt.getDayOfWeek(); //gc.get(Calendar.DAY_OF_WEEK) - 1;

    for (int i = 0; i < matcherSize; i++) {
        ValueMatcher minuteMatcher = (ValueMatcher) minuteMatchers.get(i);
        ValueMatcher hourMatcher = (ValueMatcher) hourMatchers.get(i);
        ValueMatcher dayOfMonthMatcher = (ValueMatcher) dayOfMonthMatchers.get(i);
        ValueMatcher monthMatcher = (ValueMatcher) monthMatchers.get(i);
        ValueMatcher dayOfWeekMatcher = (ValueMatcher) dayOfWeekMatchers.get(i);

        boolean eval = minuteMatcher.match(minute) && hourMatcher.match(hour)
                && ((dayOfMonthMatcher instanceof DayOfMonthValueMatcher)
                        ? ((DayOfMonthValueMatcher) dayOfMonthMatcher).match(dayOfMonth, month,
                                dt.year().getField().isLeap(dt.getMillis())) /*gc.isLeapYear(year))*/
                        : dayOfMonthMatcher.match(dayOfMonth))
                && monthMatcher.match(month) && dayOfWeekMatcher.match(dayOfWeek);

        if (eval) {
            return true;
        }
    }

    return false;
}

From source file:com.chiorichan.dvr.VideoWriter.java

License:Mozilla Public License

private void frameHandler(DateTime dt, BufferedImage img) {
    try {/*from  w  w  w . j  a  v a  2s  . c o  m*/
        if (img == null)
            return;

        frameEncoding = true;

        long start = System.currentTimeMillis();

        if (lastTen != storageInterface.getTen(dt)) {
            lastTen = storageInterface.getTen(dt);
            changeDestFile();
        }

        containerStream.putNextEntry(new ZipEntry(dt.getMillis() + ".jpg"));

        ByteArrayOutputStream bs = new ByteArrayOutputStream();
        ImageIO.write(img, "JPG", bs);

        containerStream.write(bs.toByteArray());

        containerStream.closeEntry();

        Loader.getLogger()
                .info(ChatColor.YELLOW + "Writing Frame: Capture Time: " + dt.toString() + ", File Size: "
                        + bs.size() + " bytes, Frames Buffered: " + timeCodedFrames.size() + ", Time Taken: "
                        + (System.currentTimeMillis() - start) + ", Thread: "
                        + Thread.currentThread().getName());

        frameEncoding = false;
    } catch (IOException ex) {
        Loader.getLogger().severe("Exception encountered within the frameHandler method:", ex);
    }
}

From source file:com.cinchapi.concourse.Timestamp.java

License:Apache License

/**
 * Construct a new instance./*from w w w  . j a v  a2 s . c o  m*/
 * 
 * @param joda
 */
private Timestamp(DateTime joda) {
    this.joda = joda;
    this.microseconds = TimeUnit.MICROSECONDS.convert(joda.getMillis(), TimeUnit.MILLISECONDS);
    this.description = null;
}

From source file:com.cisco.dvbu.ps.utils.date.DateAddDate.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 */// w w  w. j  av  a 2 s .com
@Override
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    java.util.Date startDate = null;
    Calendar startCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    int dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null || inputValues[1] == null || inputValues[2] == null) {
            return;
        }

        datePart = (String) inputValues[0];
        dateLength = (Integer) inputValues[1];

        startDate = (java.util.Date) inputValues[2];
        startCal = Calendar.getInstance();
        startCal.setTime(startDate);
        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);

        if (datePart.equalsIgnoreCase("second")) {
            endDateTime = startDateTime.plusSeconds(dateLength);
        }

        if (datePart.equalsIgnoreCase("minute")) {
            endDateTime = startDateTime.plusMinutes(dateLength);
        }

        if (datePart.equalsIgnoreCase("hour")) {
            endDateTime = startDateTime.plusHours(dateLength);
        }

        if (datePart.equalsIgnoreCase("day")) {
            endDateTime = startDateTime.plusDays(dateLength);
        }

        if (datePart.equalsIgnoreCase("week")) {
            endDateTime = startDateTime.plusWeeks(dateLength);
        }

        if (datePart.equalsIgnoreCase("month")) {
            endDateTime = startDateTime.plusMonths(dateLength);
        }

        if (datePart.equalsIgnoreCase("year")) {
            endDateTime = startDateTime.plusYears(dateLength);
        }

        result = new java.sql.Date(endDateTime.getMillis());
    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.citrix.g2w.webdriver.flows.Session.java

License:Open Source License

/**
 * Method to end webinar//from   ww  w .j  a v  a 2  s.co  m
 * 
 * @param webinarId
 *            Webinar Id
 * @param endTime
 *            Fake end time to use in session outcome event
 */
public void endWebinar(final Long webinarId, final DateTime endTime) {
    WebinarSession webinarSession = this.sessions.get(webinarId);
    this.endpoint.endWebinar(webinarId, webinarSession.getDelegationToken(), null);
    if (!webinarSession.getParticipants().isEmpty()) {
        this.commService.createSession(webinarSession.getSessionId(), webinarSession.getStartTime().getMillis(),
                endTime.getMillis());
        for (Participant participant : webinarSession.getParticipants()) {
            DateTime leaveTime = (participant.getLeaveTime() != null) ? participant.getLeaveTime() : endTime;
            this.commService.addParticipantToSession(webinarSession.getSessionId(),
                    participant.getParticipantId(), participant.joinTime.getMillis(), leaveTime.getMillis());
        }

        this.commService.sendSessionOutcomeEvent(webinarSession.getSessionId());
    }
}

From source file:com.claresco.tinman.sql.SQLUtility.java

License:Open Source License

protected static Timestamp getTimestamp(DateTime theTS) {
    return new Timestamp(theTS.getMillis());
}

From source file:com.cloud.agent.api.CheckVMActivityOnStoragePoolCommand.java

License:Apache License

public CheckVMActivityOnStoragePoolCommand(final Host host, final StoragePool pool,
        final List<Volume> volumeList, final DateTime suspectTime) {
    this.host = new HostTO(host);
    this.pool = new StorageFilerTO(pool);
    this.suspectTimeSeconds = suspectTime.getMillis() / 1000L;
    final StringBuilder stringBuilder = new StringBuilder();
    for (final Volume v : volumeList) {
        stringBuilder.append(v.getUuid()).append(",");
    }/*w ww  .  j a v  a 2 s. com*/

    this.volumeList = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method of copying a DateTime
 * <br>// www.  j a v  a  2s.  com
 * NOTE: The timestamp also should be in UTC.
 * @return A UTC DateTime
 */
public static DateTime copy(DateTime value) {
    if (value == null) {
        return null;
    } else {
        return new DateTime(value.getMillis(), DateTimeZone.UTC);
    }
}

From source file:com.cloudhopper.commons.util.DateTimeUtil.java

License:Apache License

/**
 * Null-safe method of converting a DateTime to a Timestamp.
 * <br>//from   w w  w. j  ava2 s  .c  om
 * NOTE: The timestamp also should be in UTC.
 * @return A UTC DateTime
 */
public static Timestamp toTimestamp(DateTime dt) {
    if (dt == null) {
        return null;
    } else {
        return new Timestamp(dt.getMillis());
    }
}

From source file:com.clustercontrol.hub.util.CollectStringDataParser.java

License:Open Source License

/**
 * ????????????//from   w ww . j  a v a 2s. co m
 * 
 * @param data
 * @return
 */
public CollectStringData parse(CollectStringData data) {
    Map<String, CollectDataTag> tagMap = new HashMap<>();
    for (CollectDataTag tag : data.getTagList()) {
        tagMap.put(tag.getKey(), tag);
    }

    if (isNullOrZeroLength(format.getTimestampRegex()) && isNullOrZeroLength(format.getTimestampFormat())) {
        // do nothing, use currentTimeMillis as timestamp
    } else {
        Matcher m = timestampPattern.matcher(data.getValue());
        if (m.find() && m.groupCount() > 0) {
            String timestampStr = m.group(1);

            try {
                DateTime datetime = timestampFormatter.parseDateTime(timestampStr);

                if (datetime.year().get() == 0) {
                    // for messages without year, like syslog

                    DateTime now = new DateTime();
                    DateTimeFormatter timestampFormatterWithCurrentYear = timestampFormatter
                            .withDefaultYear(now.year().get());
                    DateTimeFormatter timestampFormatterWithLastYear = timestampFormatter
                            .withDefaultYear(now.year().get() - 1);

                    datetime = timestampFormatterWithCurrentYear.parseDateTime(timestampStr);
                    if (datetime.getMillis() - now.getMillis() > 1000 * 60 * 60 * 24 * 7) {
                        // treat messages as end of year (threshold : 1 week)
                        datetime = timestampFormatterWithLastYear.parseDateTime(timestampStr);
                    }
                }

                tagMap.put(CollectStringTag.TIMESTAMP_IN_LOG.name(), new CollectDataTag(
                        new CollectDataTagPK(data.getCollectId(), data.getDataId(),
                                CollectStringTag.TIMESTAMP_IN_LOG.name()),
                        CollectStringTag.TIMESTAMP_IN_LOG.valueType(), Long.toString(datetime.getMillis())));
            } catch (IllegalArgumentException e) {
                log.warn(String.format("invalid timestamp string : format = %s, string = %s",
                        format.getTimestampRegex(), timestampStr));
            }
        }
    }

    for (LogFormatKey keyword : format.getKeyPatternList()) {
        Pattern p = keywordPatternMap.get(keyword.getKey());
        if (null == p) {
            log.debug(String.format("Pattern is null keyword : pattern=%s", keyword.getPattern()));
            continue;
        }

        Matcher m = p.matcher(data.getValue());
        String matchedStr = null;
        switch (keyword.getKeyType()) {
        case parsing:
            if (m.find() && m.groupCount() > 0) {
                matchedStr = m.group(1);
            }
            break;
        case fixed:
            if (m.find()) {
                matchedStr = keyword.getValue();
            }
            break;
        }

        if (matchedStr != null && keyword.getValueType() == ValueType.string) {
            tagMap.put(keyword.getKey(),
                    new CollectDataTag(
                            new CollectDataTagPK(data.getCollectId(), data.getDataId(), keyword.getKey()),
                            keyword.getValueType(), matchedStr));
        } else if (matchedStr != null && keyword.getValueType() != ValueType.string) {
            tagMap.put(keyword.getKey(),
                    new CollectDataTag(
                            new CollectDataTagPK(data.getCollectId(), data.getDataId(), keyword.getKey()),
                            keyword.getValueType(), matchedStr));

            switch (keyword.getValueType()) {
            case number:
                try {
                    new BigDecimal(matchedStr);
                } catch (NumberFormatException e) {
                    log.warn(String.format("not match number format : value=%s, source=%s, pattern=%s",
                            matchedStr, data.getValue(), p.pattern()));
                }
                break;
            case bool:
                if (!"true".equalsIgnoreCase(matchedStr) || !"false".equalsIgnoreCase(matchedStr)) {
                    log.warn(String.format("not match boolean type : value=%s, source=%s, pattern=%s",
                            matchedStr, data.getValue(), p.pattern()));
                }
                break;
            default:
                log.warn(String.format("unexpected value type : type=%s, value=source=%s, pattern=%s",
                        keyword.getValueType().name(), data.getValue(), p.pattern()));
                break;
            }
        }
    }

    data.setTagList(new ArrayList<>(tagMap.values()));
    return data;
}