Skip to content

Commit 7255a42

Browse files
authored
chore!: remove deprecated FirestoreOptions#setTimestampsInSnapshotsEnabled (#308)
1 parent 557e669 commit 7255a42

File tree

6 files changed

+6
-65
lines changed

6 files changed

+6
-65
lines changed

google-cloud-firestore/clirr-ignored-differences.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
1919
<differences>
20-
2120
<!-- v2.0.0 -->
2221
<difference>
2322
<differenceType>7002</differenceType>
@@ -29,6 +28,11 @@
2928
<className>com/google/cloud/firestore/Firestore</className>
3029
<method>java.lang.Iterable getCollections()</method>
3130
</difference>
31+
<difference>
32+
<differenceType>7002</differenceType>
33+
<className>com/google/cloud/firestore/FirestoreOptions$Builder</className>
34+
<method>com.google.cloud.firestore.FirestoreOptions$Builder setTimestampsInSnapshotsEnabled(boolean)</method>
35+
</difference>
3236

3337
<!--
3438
createIndex -> createIndexAsync

google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ public Map<String, Object> getData() {
215215
Map<String, Object> decodedFields = new HashMap<>();
216216
for (Map.Entry<String, Value> entry : fields.entrySet()) {
217217
Object decodedValue = decodeValue(entry.getValue());
218-
decodedValue = convertToDateIfNecessary(decodedValue);
219218
decodedFields.put(entry.getKey(), decodedValue);
220219
}
221220
return decodedFields;
@@ -294,8 +293,7 @@ public Object get(@Nonnull FieldPath fieldPath) {
294293
return null;
295294
}
296295

297-
Object decodedValue = decodeValue(value);
298-
return convertToDateIfNecessary(decodedValue);
296+
return decodeValue(value);
299297
}
300298

301299
/**
@@ -312,15 +310,6 @@ public <T> T get(@Nonnull FieldPath fieldPath, Class<T> valueType) {
312310
return data == null ? null : CustomClassMapper.convertToCustomClass(data, valueType, docRef);
313311
}
314312

315-
private Object convertToDateIfNecessary(Object decodedValue) {
316-
if (decodedValue instanceof Timestamp) {
317-
if (!this.rpcContext.areTimestampsInSnapshotsEnabled()) {
318-
decodedValue = ((Timestamp) decodedValue).toDate();
319-
}
320-
}
321-
return decodedValue;
322-
}
323-
324313
/** Returns the Value Proto at 'fieldPath'. Returns null if the field was not found. */
325314
@Nullable
326315
Value extractField(@Nonnull FieldPath fieldPath) {
@@ -394,9 +383,6 @@ public Long getLong(@Nonnull String field) {
394383
/**
395384
* Returns the value of the field as a Date.
396385
*
397-
* <p>This method ignores the global setting {@link
398-
* FirestoreOptions#areTimestampsInSnapshotsEnabled}.
399-
*
400386
* @param field The path to the field.
401387
* @throws RuntimeException if the value is not a Date.
402388
* @return The value of the field.
@@ -409,9 +395,6 @@ public Date getDate(@Nonnull String field) {
409395
/**
410396
* Returns the value of the field as a {@link Timestamp}.
411397
*
412-
* <p>This method ignores the global setting {@link
413-
* FirestoreOptions#areTimestampsInSnapshotsEnabled}.
414-
*
415398
* @param field The path to the field.
416399
* @throws RuntimeException if the value is not a Date.
417400
* @return The value of the field.

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,6 @@ public <T> ApiFuture<T> runAsyncTransaction(
310310
return transactionRunner.run();
311311
}
312312

313-
/** Returns whether the user has opted into receiving dates as com.google.cloud.Timestamp. */
314-
@Override
315-
public boolean areTimestampsInSnapshotsEnabled() {
316-
return this.firestoreOptions.areTimestampsInSnapshotsEnabled();
317-
}
318-
319313
/** Returns the name of the Firestore project associated with this client. */
320314
@Override
321315
public String getDatabaseName() {

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -189,33 +189,6 @@ public Builder setDatabaseId(@Nonnull String databaseId) {
189189
return this;
190190
}
191191

192-
/**
193-
* Specifies whether to use {@link com.google.cloud.Timestamp Timestamps} for timestamp fields
194-
* in {@link DocumentSnapshot DocumentSnapshots}. This is now enabled by default and should not
195-
* be disabled.
196-
*
197-
* <p>Previously, Firestore returned timestamp fields as {@link java.util.Date} but {@link
198-
* java.util.Date} only supports millisecond precision, which leads to truncation and causes
199-
* unexpected behavior when using a timestamp from a snapshot as a part of a subsequent query.
200-
*
201-
* <p>So now Firestore returns {@link com.google.cloud.Timestamp Timestamp} values instead of
202-
* {@link java.util.Date}, avoiding this kind of problem.
203-
*
204-
* <p>To opt into the old behavior of returning {@link java.util.Date Dates}, you can
205-
* temporarily set {@link FirestoreOptions#areTimestampsInSnapshotsEnabled} to false.
206-
*
207-
* @deprecated This setting now defaults to true and will be removed in a future release. If you
208-
* are already setting it to true, just remove the setting. If you are setting it to false,
209-
* you should update your code to expect {@link com.google.cloud.Timestamp Timestamps}
210-
* instead of {@link java.util.Date Dates} and then remove the setting.
211-
*/
212-
@Deprecated
213-
@Nonnull
214-
public Builder setTimestampsInSnapshotsEnabled(boolean value) {
215-
this.timestampsInSnapshotsEnabled = value;
216-
return this;
217-
}
218-
219192
@Override
220193
@Nonnull
221194
public FirestoreOptions build() {

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreRpcContext.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ interface FirestoreRpcContext<FS extends Firestore> {
3131

3232
FS getFirestore();
3333

34-
boolean areTimestampsInSnapshotsEnabled();
35-
3634
String getDatabaseName();
3735

3836
ResourcePath getResourcePath();

google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ public void deserializeBasicTypes() throws Exception {
211211
streamObserverCapture.capture(),
212212
Matchers.<ServerStreamingCallable>any());
213213

214-
doReturn(true).when(firestoreMock).areTimestampsInSnapshotsEnabled();
215-
216214
DocumentSnapshot snapshot = documentReference.get().get();
217215
assertEquals(snapshot.getData(), ALL_SUPPORTED_TYPES_MAP);
218216

@@ -299,15 +297,6 @@ public void deserializesDates() throws Exception {
299297

300298
DocumentSnapshot snapshot = documentReference.get().get();
301299

302-
doReturn(false).when(firestoreMock).areTimestampsInSnapshotsEnabled();
303-
304-
assertEquals(DATE, snapshot.get("dateValue"));
305-
assertEquals(TIMESTAMP.toDate(), snapshot.get("timestampValue"));
306-
assertEquals(DATE, snapshot.getData().get("dateValue"));
307-
assertEquals(TIMESTAMP.toDate(), snapshot.getData().get("timestampValue"));
308-
309-
doReturn(true).when(firestoreMock).areTimestampsInSnapshotsEnabled();
310-
311300
assertEquals(Timestamp.of(DATE), snapshot.get("dateValue"));
312301
assertEquals(TIMESTAMP, snapshot.get("timestampValue"));
313302
assertEquals(Timestamp.of(DATE), snapshot.getData().get("dateValue"));

0 commit comments

Comments
 (0)