com.google.cloud.Timestamp.of()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中com.google.cloud.Timestamp.of()方法的一些代码示例,展示了Timestamp.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.of()方法的具体详情如下:
包路径:com.google.cloud.Timestamp
类名称:Timestamp
方法名:of

Timestamp.of介绍

[英]Creates an instance representing the value of timestamp.
[中]创建一个表示时间戳值的实例。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

/** Creates an instance with current time. */
public static Timestamp now() {
 java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis());
 return of(date);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void equalsAndHashCode() {
 EqualsTester tester = new EqualsTester();
 tester.addEqualityGroup(
   Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0),
   Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0),
   Timestamp.of(new java.sql.Timestamp(TEST_TIME_SECONDS * 1000)));
 tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS + 1, 0));
 tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1));
 tester.testEquals();
}

代码示例来源:origin: googleapis/google-cloud-java

private static Timestamp convertTimestamp(Object o, ErrorPath path) {
 if (o instanceof Timestamp) {
  return (Timestamp) o;
 } else if (o instanceof Date) {
  return Timestamp.of((Date) o);
 } else {
  throw deserializeError(
    path, "Failed to convert value of type " + o.getClass().getName() + " to Timestamp");
 }
}

代码示例来源:origin: googleapis/google-cloud-java

private TimestampBound getRandomBound() {
 Date date = new Date();
 switch (RANDOM.nextInt(3)) {
  case 0:
   return TimestampBound.strong();
  case 1:
   return TimestampBound.ofExactStaleness(STALENESS_MILLISEC, TimeUnit.MILLISECONDS);
  default:
   return TimestampBound.ofReadTimestamp(
     Timestamp.of(new Date(date.getTime() - STALENESS_MILLISEC)));
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void ofDate() {
 Timestamp timestamp = Timestamp.of(TEST_DATE);
 Long expectedSeconds = TimeUnit.MILLISECONDS.toSeconds(TEST_TIME_MILLISECONDS);
 Long expectedNanos =
   TimeUnit.MILLISECONDS.toNanos(TEST_TIME_MILLISECONDS)
     - TimeUnit.SECONDS.toNanos(expectedSeconds);
 assertThat(timestamp.getSeconds()).isEqualTo(expectedSeconds);
 assertThat(timestamp.getNanos()).isEqualTo(expectedNanos);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void boundsSqlTimestampMin() {
 expectedException.expect(IllegalArgumentException.class);
 Timestamp.of(new java.sql.Timestamp((Timestamp.MIN_VALUE.getSeconds() - 1) * 1000));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void boundsSqlTimestampMax() {
 expectedException.expect(IllegalArgumentException.class);
 Timestamp.of(new java.sql.Timestamp((Timestamp.MAX_VALUE.getSeconds() + 1) * 1000));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void toFromSqlTimestamp() {
 long seconds = TEST_TIME_SECONDS;
 int nanos = 500000000;
 java.sql.Timestamp sqlTs = new java.sql.Timestamp(seconds * 1000);
 sqlTs.setNanos(nanos);
 Timestamp ts = Timestamp.of(sqlTs);
 assertThat(ts.getSeconds()).isEqualTo(seconds);
 assertThat(ts.getNanos()).isEqualTo(nanos);
 assertThat(ts.toSqlTimestamp()).isEqualTo(sqlTs);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testGetTimestamp() throws Exception {
 BaseEntity<Key> entity = builder.build();
 assertEquals(TIMESTAMP, entity.getTimestamp("timestamp"));
 Calendar cal = Calendar.getInstance();
 cal.add(Calendar.DATE, -1);
 Timestamp timestamp = Timestamp.of(cal.getTime());
 entity = builder.set("timestamp", TimestampValue.of(timestamp)).build();
 assertEquals(timestamp, entity.getTimestamp("timestamp"));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void deserializesDates() throws Exception {
 doAnswer(getAllResponse(ALL_SUPPORTED_TYPES_PROTO))
   .when(firestoreMock)
   .streamRequest(
     getAllCapture.capture(),
     streamObserverCapture.capture(),
     Matchers.<ServerStreamingCallable>any());
 DocumentSnapshot snapshot = documentReference.get().get();
 doReturn(false).when(firestoreMock).areTimestampsInSnapshotsEnabled();
 assertEquals(DATE, snapshot.get("dateValue"));
 assertEquals(TIMESTAMP.toDate(), snapshot.get("timestampValue"));
 assertEquals(DATE, snapshot.getData().get("dateValue"));
 assertEquals(TIMESTAMP.toDate(), snapshot.getData().get("timestampValue"));
 doReturn(true).when(firestoreMock).areTimestampsInSnapshotsEnabled();
 assertEquals(Timestamp.of(DATE), snapshot.get("dateValue"));
 assertEquals(TIMESTAMP, snapshot.get("timestampValue"));
 assertEquals(Timestamp.of(DATE), snapshot.getData().get("dateValue"));
 assertEquals(TIMESTAMP, snapshot.getData().get("timestampValue"));
}

代码示例来源:origin: objectify/objectify

@Override
  protected Value<Timestamp> toDatastore(final Date value) {
    return TimestampValue.of(Timestamp.of(value));
  }
}

代码示例来源:origin: objectify/objectify

@Override
  protected Value<Timestamp> toDatastore(final Date value) {
    return TimestampValue.of(Timestamp.of(value));
  }
}

代码示例来源:origin: objectify/objectify

@Override
  protected Value<Timestamp> saveValue(final ReadableInstant value, final SaveContext ctx, final Path path) throws SkipException {
    return TimestampValue.of(Timestamp.of(value.toInstant().toDate()));
  }
};

代码示例来源:origin: sai-pullabhotla/catatumbo

/**
 * Converts the given Date to a Timestamp.
 * 
 * @param date
 *          the Date to convert
 * @return Timestamp object that is equivalent to the given Date.
 */
private static Timestamp toTimestamp(Date date) {
 return Timestamp.of(date);
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

@Nullable
  @Override
  public Timestamp convert(java.sql.Timestamp timestamp) {
    return Timestamp.of(timestamp);
  }
};

代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-spanner

@Nullable
  @Override
  public Timestamp convert(java.sql.Timestamp timestamp) {
    return Timestamp.of(timestamp);
  }
};

代码示例来源:origin: com.google.cloud/google-cloud-core

/** Creates an instance with current time. */
public static Timestamp now() {
 java.sql.Timestamp date = new java.sql.Timestamp(System.currentTimeMillis());
 return of(date);
}

代码示例来源:origin: com.google.cloud/google-cloud-firestore

private static Timestamp convertTimestamp(Object o, ErrorPath path) {
 if (o instanceof Timestamp) {
  return (Timestamp) o;
 } else if (o instanceof Date) {
  return Timestamp.of((Date) o);
 } else {
  throw deserializeError(
    path, "Failed to convert value of type " + o.getClass().getName() + " to Timestamp");
 }
}

代码示例来源:origin: sai-pullabhotla/catatumbo

@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
 if (input == null) {
  return NullValue.newBuilder();
 }
 Calendar calendar = (Calendar) input;
 return TimestampValue.newBuilder(Timestamp.of(calendar.getTime()));
}

代码示例来源:origin: sai-pullabhotla/catatumbo

@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
 if (input == null) {
  return NullValue.newBuilder();
 }
 return TimestampValue.newBuilder(Timestamp.of((Date) input));
}

相关文章