Java Code Examples for org.joda.time.DateTimeUtils#currentTimeMillis()

The following examples show how to use org.joda.time.DateTimeUtils#currentTimeMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoordinatorTxnCtx.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * @return current timestamp in ms. Subsequent calls will always return the same value. (Not thread-safe)
 */
@Override
public long currentTimeMillis() {
    if (currentTimeMillis == null) {
        // no synchronization because StmtCtx is mostly used during single-threaded analysis phase
        currentTimeMillis = DateTimeUtils.currentTimeMillis();
    }
    return currentTimeMillis;
}
 
Example 2
Source File: BaseInterval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an interval from a start and end instant.
 * 
 * @param start  start of this interval, null means now
 * @param end  end of this interval, null means now
 * @throws IllegalArgumentException if the end is before the start
 */
protected BaseInterval(ReadableInstant start, ReadableInstant end) {
    super();
    if (start == null && end == null) {
        iStartMillis = iEndMillis = DateTimeUtils.currentTimeMillis();
        iChronology = ISOChronology.getInstance();
    } else {
        iChronology = DateTimeUtils.getInstantChronology(start);
        iStartMillis = DateTimeUtils.getInstantMillis(start);
        iEndMillis = DateTimeUtils.getInstantMillis(end);
        checkInterval(iStartMillis, iEndMillis);
    }
}
 
Example 3
Source File: TimestampedEvent.java    From ingestion with Apache License 2.0 5 votes vote down vote up
TimestampedEvent(Event base) {
  setBody(base.getBody());
  Map<String, String> headers = Maps.newHashMap(base.getHeaders());
  String timestampString = headers.get("timestamp");
  if (StringUtils.isBlank(timestampString)) {
    timestampString = headers.get("@timestamp");
  }
  if (StringUtils.isBlank(timestampString)) {
    this.timestamp = DateTimeUtils.currentTimeMillis();
    headers.put("timestamp", String.valueOf(timestamp ));
  } else {
    this.timestamp = Long.valueOf(timestampString);
  }
  setHeaders(headers);
}
 
Example 4
Source File: Srs.java    From mireka with Apache License 2.0 5 votes vote down vote up
private String calculateTimestamp() {
    int daysSinceEpoch =
            (int) (DateTimeUtils.currentTimeMillis() / 1000 / 24 / 60 / 60);
    int modulo1 = daysSinceEpoch % (2 << 10);
    int modulo = modulo1;
    return Base32Int.encode10Bits(modulo);
}
 
Example 5
Source File: TransportSQLActionClassLifecycleTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void selectCurrentTimestamp() throws Exception {
    long before = DateTimeUtils.currentTimeMillis();
    SQLResponse response = execute("select current_timestamp from sys.cluster");
    long after = DateTimeUtils.currentTimeMillis();
    assertThat(response.cols(), arrayContaining("current_timestamp(3)"));
    assertThat((long) response.rows()[0][0], allOf(greaterThanOrEqualTo(before), lessThanOrEqualTo(after)));
}
 
Example 6
Source File: TimestampedEvent.java    From ns4_gear_watchdog with Apache License 2.0 5 votes vote down vote up
public TimestampedEvent(Event base) {
  setBody(base.getBody());
  Map<String, String> headers = Maps.newHashMap(base.getHeaders());
  String timestampString = headers.get("timestamp");
  if (StringUtils.isBlank(timestampString)) {
    timestampString = headers.get("@timestamp");
  }
  if (StringUtils.isBlank(timestampString)) {
    this.timestamp = DateTimeUtils.currentTimeMillis();
    headers.put("timestamp", String.valueOf(timestamp));
  } else {
    this.timestamp = Long.valueOf(timestampString);
  }
  setHeaders(headers);
}
 
Example 7
Source File: AbstractInterval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Is this time interval entirely after the specified interval.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * Only the end time of the specified interval is used in the comparison.
 * 
 * @param interval  the interval to compare to, null means now
 * @return true if this time interval is after the interval specified
 */
public boolean isAfter(ReadableInterval interval) {
    long endMillis;
    if (interval == null) {
        endMillis = DateTimeUtils.currentTimeMillis();
    } else {
        endMillis = interval.getEndMillis();
    }
    return (getStartMillis() >= endMillis);
}
 
Example 8
Source File: ThriftByFieldNamesFn.java    From hdfs2cass with Apache License 2.0 5 votes vote down vote up
private long getTimestamp(final T input) {
  if (timestampIndex > -1) {
    Object value = input.get(timestampIndex);
    if (value instanceof Long) {
      return (long) value;
    } else {
      throw new CrunchRuntimeException("Can not transform timestamp field (class: " + value.getClass() + ") to long");
    }
  } else {
    return DateTimeUtils.currentTimeMillis();
  }
}
 
Example 9
Source File: TimestampedEvent.java    From ElasticsearchSink2 with Apache License 2.0 5 votes vote down vote up
TimestampedEvent(Event base) {
  setBody(base.getBody());
  Map<String, String> headers = Maps.newHashMap(base.getHeaders());
  String timestampString = headers.get("timestamp");
  if (StringUtils.isBlank(timestampString)) {
    timestampString = headers.get("@timestamp");
  }
  if (StringUtils.isBlank(timestampString)) {
    this.timestamp = DateTimeUtils.currentTimeMillis();
    headers.put("timestamp", String.valueOf(timestamp ));
  } else {
    this.timestamp = Long.valueOf(timestampString);
  }
  setHeaders(headers);
}
 
Example 10
Source File: CurrentTimestampFunction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Long evaluate(Input<Integer>... args) {
    long millis = DateTimeUtils.currentTimeMillis();
    if (args.length == 1) {
        Integer precision = args[0].value();
        if (precision == null) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "NULL precision not supported for %s", NAME));
        }
        int factor;
        switch (precision) {
            case 0:
                factor = 1000;
                break;
            case 1:
                factor = 100;
                break;
            case 2:
                factor = 10;
                break;
            case 3:
                factor = 1;
                break;
            default:
                throw new IllegalArgumentException("Precision must be between 0 and 3");
        }
        millis = LongMath.divide(millis, factor, RoundingMode.DOWN) * factor;
    }
    return millis;
}
 
Example 11
Source File: SCMMaterialSource.java    From gocd with Apache License 2.0 5 votes vote down vote up
boolean hasUpdateIntervalElapsedForScmMaterial(Material material) {
    Long lastMaterialUpdateTime = materialLastUpdateTimeMap.get(material);
    if (lastMaterialUpdateTime != null) {
        boolean shouldUpdateMaterial = (DateTimeUtils.currentTimeMillis() - lastMaterialUpdateTime) >= materialUpdateInterval;
        if (LOGGER.isDebugEnabled() && !shouldUpdateMaterial) {
            LOGGER.debug("[Material Update] Skipping update of material {} which has been last updated at {}", material, new Date(lastMaterialUpdateTime));
        }
        return shouldUpdateMaterial;
    }
    return true;
}
 
Example 12
Source File: ClockUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static Date resetClock() {
  DateTimeUtils.setCurrentMillisSystem();
  return new Date(DateTimeUtils.currentTimeMillis());
}
 
Example 13
Source File: ClockUtil.java    From camunda-bpm-platform with Apache License 2.0 2 votes vote down vote up
/**
 * Moves the clock by the given offset and keeps it running from that point
 * on.
 * 
 * @param offsetInMillis
 *          the offset to move the clock by
 * @return the new 'now'
 */
public static Date offset(Long offsetInMillis) {
  DateTimeUtils.setCurrentMillisOffset(offsetInMillis);
  return new Date(DateTimeUtils.currentTimeMillis());
}
 
Example 14
Source File: BaseDateTime.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance set to the current system millisecond time
 * using the specified chronology.
 * <p>
 * If the chronology is null, <code>ISOChronology</code>
 * in the default time zone is used.
 *
 * @param chronology the chronology, null means ISOChronology in default zone
 */
public BaseDateTime(Chronology chronology) {
    this(DateTimeUtils.currentTimeMillis(), chronology);
}
 
Example 15
Source File: AbstractConverter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extracts the millis from an object of this convertor's type.
 * <p>
 * This implementation returns the current time.
 * 
 * @param object  the object to convert
 * @param chrono  the chronology to use, which is always non-null
 * @return the millisecond value
 */
public long getInstantMillis(Object object, Chronology chrono) {
    return DateTimeUtils.currentTimeMillis();
}
 
Example 16
Source File: BasePartial.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs a partial with the current time, using ISOChronology in
 * the default zone to extract the fields.
 * <p>
 * The constructor uses the default time zone, resulting in the local time
 * being initialised. Once the constructor is complete, all further calculations
 * are performed without reference to a timezone (by switching to UTC).
 */
protected BasePartial() {
    this(DateTimeUtils.currentTimeMillis(), null);
}
 
Example 17
Source File: BasePartial.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs a partial with the current time, using the specified chronology
 * and zone to extract the fields.
 * <p>
 * The constructor uses the time zone of the chronology specified.
 * Once the constructor is complete, all further calculations are performed
 * without reference to a timezone (by switching to UTC).
 *
 * @param chronology  the chronology, null means ISOChronology in the default zone
 */
protected BasePartial(Chronology chronology) {
    this(DateTimeUtils.currentTimeMillis(), chronology);
}
 
Example 18
Source File: BaseDateTime.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an instance set to the current system millisecond time
 * using <code>ISOChronology</code> in the specified time zone.
 * <p>
 * If the specified time zone is null, the default zone is used.
 *
 * @param zone  the time zone, null means default zone
 */
public BaseDateTime(DateTimeZone zone) {
    this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone));
}
 
Example 19
Source File: BaseDateTime.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance set to the current system millisecond time
 * using <code>ISOChronology</code> in the specified time zone.
 * <p>
 * If the specified time zone is null, the default zone is used.
 *
 * @param zone the time zone, null means default zone
 */
public BaseDateTime(DateTimeZone zone) {
    this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone));
}
 
Example 20
Source File: BaseDateTime.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance set to the current system millisecond time
 * using <code>ISOChronology</code> in the default time zone.
 */
public BaseDateTime() {
    this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance());
}