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

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

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

Timestamp.parseTimestamp介绍

[英]Creates a Timestamp instance from the given string. String is in the RFC 3339 format without the timezone offset (always ends in "Z").
[中]从给定字符串创建时间戳实例。字符串采用RFC 3339格式,不带时区偏移(始终以“Z”结尾)。

代码示例

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

  1. @Test
  2. public void parseTimestamp() {
  3. assertThat(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")).isEqualTo(Timestamp.MIN_VALUE);
  4. assertThat(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999Z"))
  5. .isEqualTo(Timestamp.MAX_VALUE);
  6. assertThat(Timestamp.parseTimestamp(TEST_TIME_ISO))
  7. .isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0));
  8. }

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

  1. @Test
  2. public void timestampArray() {
  3. String t1 = "2015-09-15T00:00:00Z";
  4. String t2 = "2015-09-14T00:00:00Z";
  5. Value v =
  6. Value.timestampArray(
  7. Arrays.asList(Timestamp.parseTimestamp(t1), null, Timestamp.parseTimestamp(t2)));
  8. assertThat(v.isNull()).isFalse();
  9. assertThat(v.getTimestampArray())
  10. .containsExactly(Timestamp.parseTimestamp(t1), null, Timestamp.parseTimestamp(t2))
  11. .inOrder();
  12. assertThat(v.toString()).isEqualTo("[" + t1 + ",NULL," + t2 + "]");
  13. }

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

  1. @Test
  2. public void serialization() throws Exception {
  3. reserializeAndAssert(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999Z"));
  4. }
  5. }

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

  1. @Test
  2. public void bindTimestampArray() {
  3. Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
  4. Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
  5. Struct row =
  6. execute(
  7. Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(asList(t1, t2, null)),
  8. Type.array(Type.timestamp()));
  9. assertThat(row.isNull(0)).isFalse();
  10. assertThat(row.getTimestampList(0)).containsExactly(t1, t2, null).inOrder();
  11. }

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

  1. value.getKindCase() == KindCase.NULL_VALUE
  2. ? null
  3. : Timestamp.parseTimestamp(value.getStringValue()));

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

  1. @Test
  2. public void testBatchReadOnlyTxnWithTxnId() throws Exception {
  3. when(txnID.getSessionId()).thenReturn(SESSION_NAME);
  4. when(txnID.getTransactionId()).thenReturn(TXN_ID);
  5. Timestamp t = Timestamp.parseTimestamp(TIMESTAMP);
  6. when(txnID.getTimestamp()).thenReturn(t);
  7. BatchReadOnlyTransaction batchTxn = client.batchReadOnlyTransaction(txnID);
  8. assertThat(batchTxn.getBatchTransactionId().getSessionId()).isEqualTo(SESSION_NAME);
  9. assertThat(batchTxn.getBatchTransactionId().getTransactionId()).isEqualTo(TXN_ID);
  10. assertThat(batchTxn.getReadTimestamp()).isEqualTo(t);
  11. assertThat(batchTxn.getReadTimestamp())
  12. .isEqualTo(batchTxn.getBatchTransactionId().getTimestamp());
  13. }
  14. }

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

  1. @Test
  2. public void writeTimestampArray() {
  3. Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
  4. Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
  5. write(
  6. baseInsert()
  7. .set("TimestampArrayValue")
  8. .toTimestampArray(Arrays.asList(t1, null, t2))
  9. .build());
  10. Struct row = readLastRow("TimestampArrayValue");
  11. assertThat(row.isNull(0)).isFalse();
  12. assertThat(row.getTimestampList(0)).containsExactly(t1, null, t2).inOrder();
  13. }

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

  1. @Test
  2. public void timestamp() {
  3. String timestamp = "2016-09-15T00:00:00Z";
  4. Timestamp t = Timestamp.parseTimestamp(timestamp);
  5. Value v = Value.timestamp(t);
  6. assertThat(v.getType()).isEqualTo(Type.timestamp());
  7. assertThat(v.isNull()).isFalse();
  8. assertThat(v.isCommitTimestamp()).isFalse();
  9. assertThat(v.getTimestamp()).isSameAs(t);
  10. assertThat(v.toString()).isEqualTo(timestamp);
  11. }

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

  1. @Test
  2. public void getTimestampList() {
  3. List<Timestamp> timestampList = new ArrayList<>();
  4. timestampList.add(Timestamp.parseTimestamp("0001-01-01T00:00:00Z"));
  5. timestampList.add(Timestamp.parseTimestamp("0002-02-02T02:00:00Z"));
  6. consumer.onPartialResultSet(
  7. PartialResultSet.newBuilder()
  8. .setMetadata(
  9. makeMetadata(Type.struct(Type.StructField.of("f", Type.array(Type.timestamp())))))
  10. .addValues(Value.timestampArray(timestampList).toProto())
  11. .build());
  12. consumer.onCompleted();
  13. assertThat(resultSet.next()).isTrue();
  14. assertThat(resultSet.getTimestampList(0)).isEqualTo(timestampList);
  15. }

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

  1. @Test
  2. public void bindTimestamp() {
  3. Timestamp t = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
  4. Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(t), Type.timestamp());
  5. assertThat(row.isNull(0)).isFalse();
  6. assertThat(row.getTimestamp(0)).isEqualTo(t);
  7. }

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

  1. @Test
  2. public void testBatchReadOnlyTxnWithBound() throws Exception {
  3. Session sessionProto = Session.newBuilder().setName(SESSION_NAME).build();
  4. when(gapicRpc.createSession(
  5. eq(DB_NAME), (Map<String, String>) anyMap(), optionsCaptor.capture()))
  6. .thenReturn(sessionProto);
  7. com.google.protobuf.Timestamp timestamp = Timestamps.parse(TIMESTAMP);
  8. Transaction txnMetadata =
  9. Transaction.newBuilder().setId(TXN_ID).setReadTimestamp(timestamp).build();
  10. when(spannerOptions.getSpannerRpcV1()).thenReturn(gapicRpc);
  11. when(gapicRpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), optionsCaptor.capture()))
  12. .thenReturn(txnMetadata);
  13. BatchReadOnlyTransaction batchTxn = client.batchReadOnlyTransaction(TimestampBound.strong());
  14. assertThat(batchTxn.getBatchTransactionId().getSessionId()).isEqualTo(SESSION_NAME);
  15. assertThat(batchTxn.getBatchTransactionId().getTransactionId()).isEqualTo(TXN_ID);
  16. Timestamp t = Timestamp.parseTimestamp(TIMESTAMP);
  17. assertThat(batchTxn.getReadTimestamp()).isEqualTo(t);
  18. assertThat(batchTxn.getReadTimestamp())
  19. .isEqualTo(batchTxn.getBatchTransactionId().getTimestamp());
  20. }

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

  1. @Test
  2. public void getTimestamp() {
  3. consumer.onPartialResultSet(
  4. PartialResultSet.newBuilder()
  5. .setMetadata(makeMetadata(Type.struct(Type.StructField.of("f", Type.timestamp()))))
  6. .addValues(Value.timestamp(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")).toProto())
  7. .build());
  8. consumer.onCompleted();
  9. assertThat(resultSet.next()).isTrue();
  10. assertThat(resultSet.getTimestamp(0))
  11. .isEqualTo(Timestamp.parseTimestamp("0001-01-01T00:00:00Z"));
  12. }

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

  1. @Test
  2. public void writeTimestamp() {
  3. Timestamp timestamp = Timestamp.parseTimestamp("2016-09-15T00:00:00.111111Z");
  4. write(baseInsert().set("TimestampValue").to(timestamp).build());
  5. Struct row = readLastRow("TimestampValue");
  6. assertThat(row.isNull(0)).isFalse();
  7. assertThat(row.getTimestamp(0)).isEqualTo(timestamp);
  8. }

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

  1. @Test
  2. public void testToString() {
  3. assertThat(Key.of().toString()).isEqualTo("[]");
  4. assertThat(Key.of(new Object[] {null}).toString()).isEqualTo("[<null>]");
  5. assertThat(Key.of(true).toString()).isEqualTo("[true]");
  6. assertThat(Key.of(32).toString()).isEqualTo("[32]");
  7. assertThat(Key.of(2.0).toString()).isEqualTo("[2.0]");
  8. assertThat(Key.of("xyz").toString()).isEqualTo("[xyz]");
  9. ByteArray b = ByteArray.copyFrom("xyz");
  10. assertThat(Key.of(b).toString()).isEqualTo("[" + b.toString() + "]");
  11. String timestamp = "2015-09-15T00:00:00Z";
  12. assertThat(Key.of(Timestamp.parseTimestamp(timestamp)).toString())
  13. .isEqualTo("[" + timestamp + "]");
  14. String date = "2015-09-15";
  15. assertThat(Key.of(Date.parseDate(date)).toString()).isEqualTo("[" + date + "]");
  16. assertThat(Key.of(1, 2, 3).toString()).isEqualTo("[1,2,3]");
  17. }

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

  1. case TIMESTAMP:
  2. checkType(fieldType, proto, KindCase.STRING_VALUE);
  3. return Timestamp.parseTimestamp(proto.getStringValue());
  4. case DATE:
  5. checkType(fieldType, proto, KindCase.STRING_VALUE);

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

  1. "x",
  2. ByteArray.copyFrom("y"),
  3. Timestamp.parseTimestamp(timestamp),
  4. Date.parseDate(date));
  5. assertThat(k.size()).isEqualTo(10);
  6. "x",
  7. ByteArray.copyFrom("y"),
  8. Timestamp.parseTimestamp(timestamp),
  9. Date.parseDate(date))
  10. .inOrder();

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

  1. .append("x")
  2. .append(ByteArray.copyFrom("y"))
  3. .append(Timestamp.parseTimestamp(timestamp))
  4. .append(Date.parseDate(date))
  5. .build();
  6. "x",
  7. ByteArray.copyFrom("y"),
  8. Timestamp.parseTimestamp(timestamp),
  9. Date.parseDate(date))
  10. .inOrder();

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

  1. Timestamp.parseTimestamp("2015-09-15T00:00:00Z"),
  2. "getTimestamp",
  3. null
  4. "getTimestampListInternal",
  5. Arrays.asList(
  6. Timestamp.parseTimestamp("2015-09-15T00:00:00Z"),
  7. Timestamp.parseTimestamp("2015-09-14T00:00:00Z")),
  8. "getTimestampList",
  9. null,

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

  1. @Test
  2. public void serialization() throws Exception {
  3. reserializeAndAssert(Key.of());
  4. reserializeAndAssert(Key.of(new Object[] {null}));
  5. reserializeAndAssert(Key.of(true));
  6. reserializeAndAssert(Key.of(32));
  7. reserializeAndAssert(Key.of(2.0));
  8. reserializeAndAssert(Key.of("xyz"));
  9. reserializeAndAssert(Key.of(ByteArray.copyFrom("xyz")));
  10. reserializeAndAssert(Key.of(Timestamp.parseTimestamp("2015-09-15T00:00:00Z")));
  11. reserializeAndAssert(Key.of(Date.parseDate("2015-09-15")));
  12. reserializeAndAssert(Key.of(1, 2, 3));
  13. }
  14. }

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

  1. tester.addEqualityGroup(
  2. Key.of(ByteArray.copyFrom("a")), Key.newBuilder().append(ByteArray.copyFrom("a")).build());
  3. Timestamp t = Timestamp.parseTimestamp("2015-09-15T00:00:00Z");
  4. tester.addEqualityGroup(Key.of(t), Key.newBuilder().append(t).build());
  5. Date d = Date.parseDate("2016-09-15");

相关文章