本文整理了Java中com.google.protobuf.Timestamp.getSeconds()
方法的一些代码示例,展示了Timestamp.getSeconds()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.getSeconds()
方法的具体详情如下:
包路径:com.google.protobuf.Timestamp
类名称:Timestamp
方法名:getSeconds
[英]```
Represents seconds of UTC time since Unix epoch
1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to
9999-12-31T23:59:59Z inclusive.
`optional int64 seconds = 1;`
[中]```
Represents seconds of UTC time since Unix epoch
1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to
9999-12-31T23:59:59Z inclusive.
optional int64 seconds = 1;
代码示例来源:origin: google/rejoiner
@SchemaModification(addField = "iso", onType = Timestamp.class)
String isoString(Timestamp timestamp) {
return Instant.ofEpochSecond(timestamp.getSeconds()).toString();
}
代码示例来源:origin: google/rejoiner
@SchemaModification(addField = "afterNow", onType = Timestamp.class)
Boolean isAfterNow(Timestamp timestamp) {
return Instant.ofEpochSecond(timestamp.getSeconds()).isAfter(Instant.now());
}
代码示例来源:origin: googleapis/google-cloud-java
private static Long millisFromTimestamp(Timestamp timestamp) {
return timestamp.getSeconds() * MILLIS_PER_SECOND
+ timestamp.getNanos() / NANOS_PER_MILLISECOND;
}
代码示例来源:origin: com.google.protobuf/protobuf-java
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.google.protobuf.Timestamp)) {
return super.equals(obj);
}
com.google.protobuf.Timestamp other = (com.google.protobuf.Timestamp) obj;
boolean result = true;
result = result && (getSeconds()
== other.getSeconds());
result = result && (getNanos()
== other.getNanos());
result = result && unknownFields.equals(other.unknownFields);
return result;
}
代码示例来源:origin: google/rejoiner
@SchemaModification(addField = "localTime", onType = Timestamp.class)
String localTime(Timestamp timestamp, @Arg("timezone") String timezone) {
// TODO: Arg should be required, optional should be optional
return Instant.ofEpochSecond(timestamp.getSeconds()).atZone(ZoneId.of(timezone)).toString();
}
}
代码示例来源:origin: com.google.protobuf/protobuf-java
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + SECONDS_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
getSeconds());
hash = (37 * hash) + NANOS_FIELD_NUMBER;
hash = (53 * hash) + getNanos();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Creates an instance of Timestamp from {@code com.google.protobuf.Timestamp}. */
public static Timestamp fromProto(com.google.protobuf.Timestamp proto) {
return new Timestamp(proto.getSeconds(), proto.getNanos());
}
代码示例来源:origin: googleapis/google-cloud-java
private static int compareTimestamps(Value left, Value right) {
int cmp =
Long.compare(left.getTimestampValue().getSeconds(), right.getTimestampValue().getSeconds());
if (cmp != 0) {
return cmp;
} else {
return Integer.compare(
left.getTimestampValue().getNanos(), right.getTimestampValue().getNanos());
}
}
代码示例来源:origin: com.google.protobuf/protobuf-java
public Builder mergeFrom(com.google.protobuf.Timestamp other) {
if (other == com.google.protobuf.Timestamp.getDefaultInstance()) return this;
if (other.getSeconds() != 0L) {
setSeconds(other.getSeconds());
}
if (other.getNanos() != 0) {
setNanos(other.getNanos());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
代码示例来源:origin: apache/nifi
attributes.put(MESSAGE_ID_ATTRIBUTE, message.getMessage().getMessageId());
attributes.put(MSG_ATTRIBUTES_COUNT_ATTRIBUTE, String.valueOf(message.getMessage().getAttributesCount()));
attributes.put(MSG_PUBLISH_TIME_ATTRIBUTE, String.valueOf(message.getMessage().getPublishTime().getSeconds()));
attributes.putAll(message.getMessage().getAttributesMap());
代码示例来源:origin: pinterest/secor
@Test
public void testExtractPathTimestampMillis() throws Exception {
Map<String, String> classPerTopic = new HashMap<String, String>();
System.out.println(TimestampedMessages.UnitTestTimestamp1.class.getName());
classPerTopic.put("test", TimestampedMessages.UnitTestTimestamp1.class.getName());
Mockito.when(mConfig.getMessageTimestampName()).thenReturn("timestamp");
Mockito.when(mConfig.getProtobufMessageClassPerTopic()).thenReturn(classPerTopic);
ProtobufMessageParser parser = new ProtobufMessageParser(mConfig);
Timestamp timestamp = Timestamp.newBuilder().setSeconds(1405970352l)
.setNanos(0).build();
TimestampedMessages.UnitTestTimestamp1 message = TimestampedMessages.UnitTestTimestamp1.newBuilder().setTimestamp(timestamp).build();
assertEquals(1405970352000l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
Timestamp timestampWithNano = Timestamp.newBuilder().setSeconds(1405970352l)
.setNanos(123000000).build();
message = TimestampedMessages.UnitTestTimestamp1.newBuilder().setTimestamp(timestampWithNano).build();
assertEquals(1405970352123l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
}
代码示例来源:origin: pinterest/secor
@Test
public void testExtractNestedTimestampMillis() throws Exception {
Map<String, String> classPerTopic = new HashMap<String, String>();
classPerTopic.put("*", TimestampedMessages.UnitTestTimestamp2.class.getName());
Mockito.when(mConfig.getMessageTimestampName()).thenReturn("internal.timestamp");
Mockito.when(mConfig.getProtobufMessageClassPerTopic()).thenReturn(classPerTopic);
ProtobufMessageParser parser = new ProtobufMessageParser(mConfig);
Timestamp timestamp = Timestamps.fromMillis(1405970352000L);
TimestampedMessages.UnitTestTimestamp2 message = TimestampedMessages.UnitTestTimestamp2.newBuilder()
.setInternal(TimestampedMessages.UnitTestTimestamp2.Internal.newBuilder().setTimestamp(timestamp).build()).build();
assertEquals(1405970352000l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
timestamp = Timestamps.fromMillis(1405970352123l);
message = TimestampedMessages.UnitTestTimestamp2.newBuilder()
.setInternal(TimestampedMessages.UnitTestTimestamp2.Internal.newBuilder().setTimestamp(timestamp).build()).build();
assertEquals(1405970352123l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
}
}
代码示例来源:origin: gojektech/feast
public static Timestamp maxTimestamp(Timestamp a, Timestamp b) {
if (a.getSeconds() != b.getSeconds()) {
return a.getSeconds() < b.getSeconds() ? b : a;
} else {
return a.getNanos() < b.getNanos() ? b : a;
}
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/**
* Convert a Timestamp to the number of seconds elapsed from the epoch.
*
* <p>The result will be rounded down to the nearest second. E.g., if the timestamp represents
* "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 second.
*/
public static long toSeconds(Timestamp timestamp) {
return checkValid(timestamp).getSeconds();
}
代码示例来源:origin: gojektech/feast
public static long getReversedRoundedMillis(
com.google.protobuf.Timestamp timestamp, Granularity.Enum granularity) {
if (granularity == Granularity.Enum.NONE) {
return 0L; // We store it as zero instead of reversed Long.MAX_VALUE.
}
timestamp = DateUtil.roundToGranularity(timestamp, granularity);
return Long.MAX_VALUE - timestamp.getSeconds() * 1000;
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/**
* Returns true if the given {@link Timestamp} is valid. The {@code seconds} value must be in the
* range [-62,135,596,800, +253,402,300,799] (i.e., between 0001-01-01T00:00:00Z and
* 9999-12-31T23:59:59Z). The {@code nanos} value must be in the range [0, +999,999,999].
*
* <p><b>Note:</b> Negative second values with fractional seconds must still have non-negative
* nanos values that count forward in time.
*/
public static boolean isValid(Timestamp timestamp) {
return isValid(timestamp.getSeconds(), timestamp.getNanos());
}
代码示例来源:origin: com.google.cloud/google-cloud-firestore
private static int compareTimestamps(Value left, Value right) {
int cmp =
Long.compare(left.getTimestampValue().getSeconds(), right.getTimestampValue().getSeconds());
if (cmp != 0) {
return cmp;
} else {
return Integer.compare(
left.getTimestampValue().getNanos(), right.getTimestampValue().getNanos());
}
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/** Calculate the difference between two timestamps. */
public static Duration between(Timestamp from, Timestamp to) {
checkValid(from);
checkValid(to);
return Durations.normalizedDuration(
checkedSubtract(to.getSeconds(), from.getSeconds()),
checkedSubtract(to.getNanos(), from.getNanos()));
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/**
* Convert a Timestamp to the number of microseconds elapsed from the epoch.
*
* <p>The result will be rounded down to the nearest microsecond. E.g., if the timestamp
* represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 microsecond.
*/
public static long toMicros(Timestamp timestamp) {
checkValid(timestamp);
return checkedAdd(
checkedMultiply(timestamp.getSeconds(), MICROS_PER_SECOND),
timestamp.getNanos() / NANOS_PER_MICROSECOND);
}
代码示例来源:origin: com.google.protobuf/protobuf-java-util
/** Subtract a duration from a timestamp. */
public static Timestamp subtract(Timestamp start, Duration length) {
checkValid(start);
Durations.checkValid(length);
return normalizedTimestamp(
checkedSubtract(start.getSeconds(), length.getSeconds()),
checkedSubtract(start.getNanos(), length.getNanos()));
}
内容来源于网络,如有侵权,请联系作者删除!