Example usage for org.joda.time DateTimeUtils getInstantMillis

List of usage examples for org.joda.time DateTimeUtils getInstantMillis

Introduction

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

Prototype

public static final long getInstantMillis(ReadableInstant instant) 

Source Link

Document

Gets the millisecond instant from the specified instant object handling null.

Usage

From source file:com.ning.metrics.collector.processing.db.DatabaseFeedEventStorage.java

License:Apache License

@Override
public List<String> insert(final Collection<FeedEvent> feedEvents) {
    return dbi.withHandle(new HandleCallback<List<String>>() {

        @Override/*from   ww  w.j a v  a  2s . c  o  m*/
        public List<String> withHandle(Handle handle) throws Exception {
            final List<String> idList = Lists.newArrayListWithCapacity(feedEvents.size());
            PreparedBatch batch = handle.prepareBatch(
                    "insert into feed_events (id, channel, created_at, metadata, event, subscription_id) values (:id, :channel, :now, :metadata, :event, :subscription_id)");

            for (FeedEvent feedEvent : feedEvents) {
                String id = UUID.randomUUID().toString();
                idList.add(id);
                batch.bind("id", id).bind("channel", feedEvent.getChannel())
                        .bind("metadata", mapper.writeValueAsString(feedEvent.getMetadata()))
                        .bind("event", mapper.writeValueAsString(feedEvent.getEvent()))
                        .bind("now", DateTimeUtils.getInstantMillis(new DateTime(DateTimeZone.UTC)))
                        .bind("subscription_id", feedEvent.getSubscriptionId()).add();
            }

            batch.execute();

            return idList;
        }
    });
}

From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java

License:Open Source License

private ASSystemTime standardDate(TimeZone timeZone) {
    DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);

    DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone);

    long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis());
    long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant);

    if (firstDSTTransitionInstant == secondDSTTransitionInstant) {
        return systemTimeFromInstant(0, DateTimeZone.UTC);
    }//  w ww. j  ava2s . c om

    if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) {
        return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone);
    }
    return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone);
}

From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java

License:Open Source License

private ASSystemTime dayLightDate(TimeZone timeZone) {
    DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);

    DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone);

    long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis());
    long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant);

    if (firstDSTTransitionInstant == secondDSTTransitionInstant) {
        return systemTimeFromInstant(0, DateTimeZone.UTC);
    }//www  .  jav  a  2s .com

    if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) {
        return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone);
    }
    return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone);
}