下面列出了org.joda.time.DateTimeUtils#currentTimeMillis ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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;
}
@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;
}
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);
}
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();
}
}
/**
* 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);
}
/**
* @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;
}
@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)));
}
private String calculateTimestamp() {
int daysSinceEpoch =
(int) (DateTimeUtils.currentTimeMillis() / 1000 / 24 / 60 / 60);
int modulo1 = daysSinceEpoch % (2 << 10);
int modulo = modulo1;
return Base32Int.encode10Bits(modulo);
}
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);
}
/**
* 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);
}
}
public static Date resetClock() {
DateTimeUtils.setCurrentMillisSystem();
return new Date(DateTimeUtils.currentTimeMillis());
}
/**
* 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());
}
/**
* 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));
}
/**
* 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);
}
/**
* 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());
}
/**
* 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();
}
/**
* 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);
}
/**
* 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);
}
/**
* 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));
}