本文整理了Java中com.google.cloud.Timestamp.parseTimestamp()
方法的一些代码示例,展示了Timestamp.parseTimestamp()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.parseTimestamp()
方法的具体详情如下:
包路径:com.google.cloud.Timestamp
类名称: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
@Test
public void parseTimestamp() {
assertThat(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")).isEqualTo(Timestamp.MIN_VALUE);
assertThat(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999Z"))
.isEqualTo(Timestamp.MAX_VALUE);
assertThat(Timestamp.parseTimestamp(TEST_TIME_ISO))
.isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void timestampArray() {
String t1 = "2015-09-15T00:00:00Z";
String t2 = "2015-09-14T00:00:00Z";
Value v =
Value.timestampArray(
Arrays.asList(Timestamp.parseTimestamp(t1), null, Timestamp.parseTimestamp(t2)));
assertThat(v.isNull()).isFalse();
assertThat(v.getTimestampArray())
.containsExactly(Timestamp.parseTimestamp(t1), null, Timestamp.parseTimestamp(t2))
.inOrder();
assertThat(v.toString()).isEqualTo("[" + t1 + ",NULL," + t2 + "]");
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void serialization() throws Exception {
reserializeAndAssert(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999Z"));
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void bindTimestampArray() {
Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
Struct row =
execute(
Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(asList(t1, t2, null)),
Type.array(Type.timestamp()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestampList(0)).containsExactly(t1, t2, null).inOrder();
}
代码示例来源:origin: googleapis/google-cloud-java
value.getKindCase() == KindCase.NULL_VALUE
? null
: Timestamp.parseTimestamp(value.getStringValue()));
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testBatchReadOnlyTxnWithTxnId() throws Exception {
when(txnID.getSessionId()).thenReturn(SESSION_NAME);
when(txnID.getTransactionId()).thenReturn(TXN_ID);
Timestamp t = Timestamp.parseTimestamp(TIMESTAMP);
when(txnID.getTimestamp()).thenReturn(t);
BatchReadOnlyTransaction batchTxn = client.batchReadOnlyTransaction(txnID);
assertThat(batchTxn.getBatchTransactionId().getSessionId()).isEqualTo(SESSION_NAME);
assertThat(batchTxn.getBatchTransactionId().getTransactionId()).isEqualTo(TXN_ID);
assertThat(batchTxn.getReadTimestamp()).isEqualTo(t);
assertThat(batchTxn.getReadTimestamp())
.isEqualTo(batchTxn.getBatchTransactionId().getTimestamp());
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void writeTimestampArray() {
Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
write(
baseInsert()
.set("TimestampArrayValue")
.toTimestampArray(Arrays.asList(t1, null, t2))
.build());
Struct row = readLastRow("TimestampArrayValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestampList(0)).containsExactly(t1, null, t2).inOrder();
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void timestamp() {
String timestamp = "2016-09-15T00:00:00Z";
Timestamp t = Timestamp.parseTimestamp(timestamp);
Value v = Value.timestamp(t);
assertThat(v.getType()).isEqualTo(Type.timestamp());
assertThat(v.isNull()).isFalse();
assertThat(v.isCommitTimestamp()).isFalse();
assertThat(v.getTimestamp()).isSameAs(t);
assertThat(v.toString()).isEqualTo(timestamp);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void getTimestampList() {
List<Timestamp> timestampList = new ArrayList<>();
timestampList.add(Timestamp.parseTimestamp("0001-01-01T00:00:00Z"));
timestampList.add(Timestamp.parseTimestamp("0002-02-02T02:00:00Z"));
consumer.onPartialResultSet(
PartialResultSet.newBuilder()
.setMetadata(
makeMetadata(Type.struct(Type.StructField.of("f", Type.array(Type.timestamp())))))
.addValues(Value.timestampArray(timestampList).toProto())
.build());
consumer.onCompleted();
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.getTimestampList(0)).isEqualTo(timestampList);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void bindTimestamp() {
Timestamp t = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(t), Type.timestamp());
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestamp(0)).isEqualTo(t);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testBatchReadOnlyTxnWithBound() throws Exception {
Session sessionProto = Session.newBuilder().setName(SESSION_NAME).build();
when(gapicRpc.createSession(
eq(DB_NAME), (Map<String, String>) anyMap(), optionsCaptor.capture()))
.thenReturn(sessionProto);
com.google.protobuf.Timestamp timestamp = Timestamps.parse(TIMESTAMP);
Transaction txnMetadata =
Transaction.newBuilder().setId(TXN_ID).setReadTimestamp(timestamp).build();
when(spannerOptions.getSpannerRpcV1()).thenReturn(gapicRpc);
when(gapicRpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), optionsCaptor.capture()))
.thenReturn(txnMetadata);
BatchReadOnlyTransaction batchTxn = client.batchReadOnlyTransaction(TimestampBound.strong());
assertThat(batchTxn.getBatchTransactionId().getSessionId()).isEqualTo(SESSION_NAME);
assertThat(batchTxn.getBatchTransactionId().getTransactionId()).isEqualTo(TXN_ID);
Timestamp t = Timestamp.parseTimestamp(TIMESTAMP);
assertThat(batchTxn.getReadTimestamp()).isEqualTo(t);
assertThat(batchTxn.getReadTimestamp())
.isEqualTo(batchTxn.getBatchTransactionId().getTimestamp());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void getTimestamp() {
consumer.onPartialResultSet(
PartialResultSet.newBuilder()
.setMetadata(makeMetadata(Type.struct(Type.StructField.of("f", Type.timestamp()))))
.addValues(Value.timestamp(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")).toProto())
.build());
consumer.onCompleted();
assertThat(resultSet.next()).isTrue();
assertThat(resultSet.getTimestamp(0))
.isEqualTo(Timestamp.parseTimestamp("0001-01-01T00:00:00Z"));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void writeTimestamp() {
Timestamp timestamp = Timestamp.parseTimestamp("2016-09-15T00:00:00.111111Z");
write(baseInsert().set("TimestampValue").to(timestamp).build());
Struct row = readLastRow("TimestampValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestamp(0)).isEqualTo(timestamp);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testToString() {
assertThat(Key.of().toString()).isEqualTo("[]");
assertThat(Key.of(new Object[] {null}).toString()).isEqualTo("[<null>]");
assertThat(Key.of(true).toString()).isEqualTo("[true]");
assertThat(Key.of(32).toString()).isEqualTo("[32]");
assertThat(Key.of(2.0).toString()).isEqualTo("[2.0]");
assertThat(Key.of("xyz").toString()).isEqualTo("[xyz]");
ByteArray b = ByteArray.copyFrom("xyz");
assertThat(Key.of(b).toString()).isEqualTo("[" + b.toString() + "]");
String timestamp = "2015-09-15T00:00:00Z";
assertThat(Key.of(Timestamp.parseTimestamp(timestamp)).toString())
.isEqualTo("[" + timestamp + "]");
String date = "2015-09-15";
assertThat(Key.of(Date.parseDate(date)).toString()).isEqualTo("[" + date + "]");
assertThat(Key.of(1, 2, 3).toString()).isEqualTo("[1,2,3]");
}
代码示例来源:origin: googleapis/google-cloud-java
case TIMESTAMP:
checkType(fieldType, proto, KindCase.STRING_VALUE);
return Timestamp.parseTimestamp(proto.getStringValue());
case DATE:
checkType(fieldType, proto, KindCase.STRING_VALUE);
代码示例来源:origin: googleapis/google-cloud-java
"x",
ByteArray.copyFrom("y"),
Timestamp.parseTimestamp(timestamp),
Date.parseDate(date));
assertThat(k.size()).isEqualTo(10);
"x",
ByteArray.copyFrom("y"),
Timestamp.parseTimestamp(timestamp),
Date.parseDate(date))
.inOrder();
代码示例来源:origin: googleapis/google-cloud-java
.append("x")
.append(ByteArray.copyFrom("y"))
.append(Timestamp.parseTimestamp(timestamp))
.append(Date.parseDate(date))
.build();
"x",
ByteArray.copyFrom("y"),
Timestamp.parseTimestamp(timestamp),
Date.parseDate(date))
.inOrder();
代码示例来源:origin: googleapis/google-cloud-java
Timestamp.parseTimestamp("2015-09-15T00:00:00Z"),
"getTimestamp",
null
"getTimestampListInternal",
Arrays.asList(
Timestamp.parseTimestamp("2015-09-15T00:00:00Z"),
Timestamp.parseTimestamp("2015-09-14T00:00:00Z")),
"getTimestampList",
null,
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void serialization() throws Exception {
reserializeAndAssert(Key.of());
reserializeAndAssert(Key.of(new Object[] {null}));
reserializeAndAssert(Key.of(true));
reserializeAndAssert(Key.of(32));
reserializeAndAssert(Key.of(2.0));
reserializeAndAssert(Key.of("xyz"));
reserializeAndAssert(Key.of(ByteArray.copyFrom("xyz")));
reserializeAndAssert(Key.of(Timestamp.parseTimestamp("2015-09-15T00:00:00Z")));
reserializeAndAssert(Key.of(Date.parseDate("2015-09-15")));
reserializeAndAssert(Key.of(1, 2, 3));
}
}
代码示例来源:origin: googleapis/google-cloud-java
tester.addEqualityGroup(
Key.of(ByteArray.copyFrom("a")), Key.newBuilder().append(ByteArray.copyFrom("a")).build());
Timestamp t = Timestamp.parseTimestamp("2015-09-15T00:00:00Z");
tester.addEqualityGroup(Key.of(t), Key.newBuilder().append(t).build());
Date d = Date.parseDate("2016-09-15");
内容来源于网络,如有侵权,请联系作者删除!