aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Firestore/Example/Firestore.xcodeproj/project.pbxproj8
-rw-r--r--Firestore/Example/Tests/API/FIRTimestampTest.m102
-rw-r--r--Firestore/Example/Tests/Core/FSTTimestampTests.mm88
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRFieldsTests.mm25
-rw-r--r--Firestore/Example/Tests/Integration/FSTDatastoreTests.mm4
-rw-r--r--Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm6
-rw-r--r--Firestore/Example/Tests/Local/FSTLocalStoreTests.mm6
-rw-r--r--Firestore/Example/Tests/Local/FSTMutationQueueTests.mm8
-rw-r--r--Firestore/Example/Tests/Model/FSTFieldValueTests.mm18
-rw-r--r--Firestore/Example/Tests/Model/FSTMutationTests.mm6
-rw-r--r--Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm4
-rw-r--r--Firestore/Example/Tests/Util/FSTHelpers.h6
-rw-r--r--Firestore/Example/Tests/Util/FSTHelpers.mm8
-rw-r--r--Firestore/Source/API/FIRTimestamp+Internal.h35
-rw-r--r--Firestore/Source/API/FIRTimestamp.m (renamed from Firestore/Source/Core/FSTTimestamp.mm)115
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.mm5
-rw-r--r--Firestore/Source/Core/FSTSnapshotVersion.h6
-rw-r--r--Firestore/Source/Core/FSTSnapshotVersion.mm8
-rw-r--r--Firestore/Source/Local/FSTLevelDBMutationQueue.mm2
-rw-r--r--Firestore/Source/Local/FSTLocalSerializer.mm2
-rw-r--r--Firestore/Source/Local/FSTLocalStore.mm4
-rw-r--r--Firestore/Source/Local/FSTMemoryMutationQueue.mm2
-rw-r--r--Firestore/Source/Local/FSTMutationQueue.h4
-rw-r--r--Firestore/Source/Model/FSTFieldValue.h10
-rw-r--r--Firestore/Source/Model/FSTFieldValue.mm15
-rw-r--r--Firestore/Source/Model/FSTMutation.h6
-rw-r--r--Firestore/Source/Model/FSTMutation.mm17
-rw-r--r--Firestore/Source/Model/FSTMutationBatch.h6
-rw-r--r--Firestore/Source/Model/FSTMutationBatch.mm5
-rw-r--r--Firestore/Source/Public/FIRTimestamp.h (renamed from Firestore/Source/Core/FSTTimestamp.h)48
-rw-r--r--Firestore/Source/Public/FirebaseFirestore.h1
-rw-r--r--Firestore/Source/Remote/FSTSerializerBeta.h6
-rw-r--r--Firestore/Source/Remote/FSTSerializerBeta.mm12
33 files changed, 356 insertions, 242 deletions
diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj
index f230cb4..2398caa 100644
--- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj
+++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj
@@ -54,7 +54,6 @@
5492E057202154AB00B64F25 /* FIRSnapshotMetadataTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04D202154AA00B64F25 /* FIRSnapshotMetadataTests.mm */; };
5492E058202154AB00B64F25 /* FSTAPIHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04E202154AA00B64F25 /* FSTAPIHelpers.mm */; };
5492E059202154AB00B64F25 /* FIRQuerySnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04F202154AA00B64F25 /* FIRQuerySnapshotTests.mm */; };
- 5492E062202154B900B64F25 /* FSTTimestampTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E05B202154B800B64F25 /* FSTTimestampTests.mm */; };
5492E063202154B900B64F25 /* FSTViewSnapshotTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E05C202154B800B64F25 /* FSTViewSnapshotTest.mm */; };
5492E064202154B900B64F25 /* FSTQueryListenerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E05D202154B900B64F25 /* FSTQueryListenerTests.mm */; };
5492E065202154B900B64F25 /* FSTViewTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E05E202154B900B64F25 /* FSTViewTests.mm */; };
@@ -153,6 +152,7 @@
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF6506B201131F8005F2C74 /* timestamp_test.cc */; };
AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; };
B6152AD7202A53CB000E5744 /* document_key_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6152AD5202A5385000E5744 /* document_key_test.cc */; };
+ B65D34A9203C995B0076A5E1 /* FIRTimestampTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B65D34A7203C99090076A5E1 /* FIRTimestampTest.m */; };
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2AD2023DDB20028D6BE /* field_path_test.cc */; };
B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2B02024FFD70028D6BE /* resource_path_test.cc */; };
C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; };
@@ -243,7 +243,6 @@
5492E04E202154AA00B64F25 /* FSTAPIHelpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTAPIHelpers.mm; sourceTree = "<group>"; };
5492E04F202154AA00B64F25 /* FIRQuerySnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRQuerySnapshotTests.mm; sourceTree = "<group>"; };
5492E05A202154B800B64F25 /* FSTSyncEngine+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSTSyncEngine+Testing.h"; sourceTree = "<group>"; };
- 5492E05B202154B800B64F25 /* FSTTimestampTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTTimestampTests.mm; sourceTree = "<group>"; };
5492E05C202154B800B64F25 /* FSTViewSnapshotTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTViewSnapshotTest.mm; sourceTree = "<group>"; };
5492E05D202154B900B64F25 /* FSTQueryListenerTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTQueryListenerTests.mm; sourceTree = "<group>"; };
5492E05E202154B900B64F25 /* FSTViewTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTViewTests.mm; sourceTree = "<group>"; };
@@ -359,6 +358,7 @@
ABF6506B201131F8005F2C74 /* timestamp_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = timestamp_test.cc; sourceTree = "<group>"; };
B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B6152AD5202A5385000E5744 /* document_key_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = document_key_test.cc; sourceTree = "<group>"; };
+ B65D34A7203C99090076A5E1 /* FIRTimestampTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRTimestampTest.m; sourceTree = "<group>"; };
B686F2AD2023DDB20028D6BE /* field_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = field_path_test.cc; sourceTree = "<group>"; };
B686F2B02024FFD70028D6BE /* resource_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = resource_path_test.cc; sourceTree = "<group>"; };
CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = "<group>"; };
@@ -697,6 +697,7 @@
DE51B1831F0D48AC0013853F /* API */ = {
isa = PBXGroup;
children = (
+ B65D34A7203C99090076A5E1 /* FIRTimestampTest.m */,
5492E045202154AA00B64F25 /* FIRCollectionReferenceTests.mm */,
5492E049202154AA00B64F25 /* FIRDocumentReferenceTests.mm */,
5492E04B202154AA00B64F25 /* FIRDocumentSnapshotTests.mm */,
@@ -771,7 +772,6 @@
5492E05D202154B900B64F25 /* FSTQueryListenerTests.mm */,
5492E061202154B900B64F25 /* FSTQueryTests.mm */,
5492E05A202154B800B64F25 /* FSTSyncEngine+Testing.h */,
- 5492E05B202154B800B64F25 /* FSTTimestampTests.mm */,
5492E05C202154B800B64F25 /* FSTViewSnapshotTest.mm */,
5492E05E202154B900B64F25 /* FSTViewTests.mm */,
);
@@ -1276,6 +1276,7 @@
5492E09E2021552D00B64F25 /* FSTEagerGarbageCollectorTests.mm in Sources */,
5492E0C62021557E00B64F25 /* FSTWatchChange+Testing.mm in Sources */,
5492E064202154B900B64F25 /* FSTQueryListenerTests.mm in Sources */,
+ B65D34A9203C995B0076A5E1 /* FIRTimestampTest.m in Sources */,
5492E03320213FFC00B64F25 /* FSTSyncEngineTestDriver.mm in Sources */,
AB380CFE201A2F4500D97691 /* string_util_test.cc in Sources */,
5492E0A42021552D00B64F25 /* FSTMemoryQueryCacheTests.mm in Sources */,
@@ -1353,7 +1354,6 @@
AB380D02201BC69F00D97691 /* bits_test.cc in Sources */,
548DB929200D59F600E00ABC /* comparison_test.cc in Sources */,
5492E03D2021401F00B64F25 /* FSTAssertTests.mm in Sources */,
- 5492E062202154B900B64F25 /* FSTTimestampTests.mm in Sources */,
AB38D93020236E21000A432D /* database_info_test.cc in Sources */,
5492E052202154AB00B64F25 /* FIRGeoPointTests.mm in Sources */,
5492E0C72021557E00B64F25 /* FSTSerializerBetaTests.mm in Sources */,
diff --git a/Firestore/Example/Tests/API/FIRTimestampTest.m b/Firestore/Example/Tests/API/FIRTimestampTest.m
new file mode 100644
index 0000000..070da96
--- /dev/null
+++ b/Firestore/Example/Tests/API/FIRTimestampTest.m
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2017 Google
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import <XCTest/XCTest.h>
+
+#import "Firestore/Source/API/FIRTimestamp+Internal.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface FIRTimestampTest : XCTestCase
+@end
+
+NSDate *TestDate(int year, int month, int day, int hour, int minute, int second) {
+ NSDateComponents *comps = [[NSDateComponents alloc] init];
+ comps.year = year;
+ comps.month = month;
+ comps.day = day;
+ comps.hour = hour;
+ comps.minute = minute;
+ comps.second = second;
+ // Force time zone to UTC to avoid these values changing due to daylight saving.
+ comps.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
+
+ return [[NSCalendar currentCalendar] dateFromComponents:comps];
+}
+
+@implementation FIRTimestampTest
+
+- (void)testFromDate {
+ // Use an NSDate such that its fractional seconds have an exact representation to avoid losing
+ // precision.
+ NSDate *input = [NSDate dateWithTimeIntervalSinceReferenceDate:1.5];
+
+ FIRTimestamp *actual = [FIRTimestamp timestampWithDate:input];
+ static const int64_t kSecondsFromEpochToReferenceDate = 978307200;
+ XCTAssertEqual(kSecondsFromEpochToReferenceDate + 1, actual.seconds);
+ XCTAssertEqual(500000000, actual.nanoseconds);
+
+ FIRTimestamp *expected =
+ [[FIRTimestamp alloc] initWithSeconds:(kSecondsFromEpochToReferenceDate + 1)
+ nanoseconds:500000000];
+ XCTAssertEqualObjects(expected, actual);
+}
+
+- (void)testSO8601String {
+ NSDate *date = TestDate(1912, 4, 14, 23, 40, 0);
+ FIRTimestamp *timestamp =
+ [[FIRTimestamp alloc] initWithSeconds:(int64_t)date.timeIntervalSince1970
+ nanoseconds:543000000];
+ XCTAssertEqualObjects(timestamp.ISO8601String, @"1912-04-14T23:40:00.543000000Z");
+}
+
+- (void)testISO8601String_withLowMilliseconds {
+ NSDate *date = TestDate(1912, 4, 14, 23, 40, 0);
+ FIRTimestamp *timestamp =
+ [[FIRTimestamp alloc] initWithSeconds:(int64_t)date.timeIntervalSince1970
+ nanoseconds:7000000];
+ XCTAssertEqualObjects(timestamp.ISO8601String, @"1912-04-14T23:40:00.007000000Z");
+}
+
+- (void)testISO8601String_withLowNanos {
+ FIRTimestamp *timestamp = [[FIRTimestamp alloc] initWithSeconds:0 nanoseconds:1];
+ XCTAssertEqualObjects(timestamp.ISO8601String, @"1970-01-01T00:00:00.000000001Z");
+}
+
+- (void)testISO8601String_withNegativeSeconds {
+ FIRTimestamp *timestamp = [[FIRTimestamp alloc] initWithSeconds:-1 nanoseconds:999999999];
+ XCTAssertEqualObjects(timestamp.ISO8601String, @"1969-12-31T23:59:59.999999999Z");
+}
+
+- (void)testCompare {
+ NSArray<FIRTimestamp *> *timestamps = @[
+ [[FIRTimestamp alloc] initWithSeconds:12344 nanoseconds:999999999],
+ [[FIRTimestamp alloc] initWithSeconds:12345 nanoseconds:0],
+ [[FIRTimestamp alloc] initWithSeconds:12345 nanoseconds:000000001],
+ [[FIRTimestamp alloc] initWithSeconds:12345 nanoseconds:99999999],
+ [[FIRTimestamp alloc] initWithSeconds:12345 nanoseconds:100000000],
+ [[FIRTimestamp alloc] initWithSeconds:12345 nanoseconds:100000001],
+ [[FIRTimestamp alloc] initWithSeconds:12346 nanoseconds:0],
+ ];
+ for (int i = 0; i < timestamps.count - 1; ++i) {
+ XCTAssertEqual(NSOrderedAscending, [timestamps[i] compare:timestamps[i + 1]]);
+ XCTAssertEqual(NSOrderedDescending, [timestamps[i + 1] compare:timestamps[i]]);
+ }
+}
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Firestore/Example/Tests/Core/FSTTimestampTests.mm b/Firestore/Example/Tests/Core/FSTTimestampTests.mm
deleted file mode 100644
index a3765fe..0000000
--- a/Firestore/Example/Tests/Core/FSTTimestampTests.mm
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#import "Firestore/Source/Core/FSTTimestamp.h"
-
-#import <XCTest/XCTest.h>
-
-#import "Firestore/Source/Util/FSTAssert.h"
-
-#import "Firestore/Example/Tests/Util/FSTHelpers.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface FSTTimestampTests : XCTestCase
-@end
-
-@implementation FSTTimestampTests
-
-- (void)testFromDate {
- // Very carefully construct an NSDate that won't lose precision with its milliseconds.
- NSDate *input = [NSDate dateWithTimeIntervalSinceReferenceDate:1.5];
-
- FSTTimestamp *actual = [FSTTimestamp timestampWithDate:input];
- static const int64_t kSecondsFromEpochToReferenceDate = 978307200;
- XCTAssertEqual(kSecondsFromEpochToReferenceDate + 1, actual.seconds);
- XCTAssertEqual(500000000, actual.nanos);
-
- FSTTimestamp *expected =
- [[FSTTimestamp alloc] initWithSeconds:(kSecondsFromEpochToReferenceDate + 1) nanos:500000000];
- XCTAssertEqualObjects(expected, actual);
-}
-
-- (void)testSO8601String {
- NSDate *date = FSTTestDate(1912, 4, 14, 23, 40, 0);
- FSTTimestamp *timestamp =
- [[FSTTimestamp alloc] initWithSeconds:(int64_t)date.timeIntervalSince1970 nanos:543000000];
- XCTAssertEqualObjects(timestamp.ISO8601String, @"1912-04-14T23:40:00.543000000Z");
-}
-
-- (void)testISO8601String_withLowMilliseconds {
- NSDate *date = FSTTestDate(1912, 4, 14, 23, 40, 0);
- FSTTimestamp *timestamp =
- [[FSTTimestamp alloc] initWithSeconds:(int64_t)date.timeIntervalSince1970 nanos:7000000];
- XCTAssertEqualObjects(timestamp.ISO8601String, @"1912-04-14T23:40:00.007000000Z");
-}
-
-- (void)testISO8601String_withLowNanos {
- FSTTimestamp *timestamp = [[FSTTimestamp alloc] initWithSeconds:0 nanos:1];
- XCTAssertEqualObjects(timestamp.ISO8601String, @"1970-01-01T00:00:00.000000001Z");
-}
-
-- (void)testISO8601String_withNegativeSeconds {
- FSTTimestamp *timestamp = [[FSTTimestamp alloc] initWithSeconds:-1 nanos:999999999];
- XCTAssertEqualObjects(timestamp.ISO8601String, @"1969-12-31T23:59:59.999999999Z");
-}
-
-- (void)testCompare {
- NSArray<FSTTimestamp *> *timestamps = @[
- [[FSTTimestamp alloc] initWithSeconds:12344 nanos:999999999],
- [[FSTTimestamp alloc] initWithSeconds:12345 nanos:0],
- [[FSTTimestamp alloc] initWithSeconds:12345 nanos:000000001],
- [[FSTTimestamp alloc] initWithSeconds:12345 nanos:99999999],
- [[FSTTimestamp alloc] initWithSeconds:12345 nanos:100000000],
- [[FSTTimestamp alloc] initWithSeconds:12345 nanos:100000001],
- [[FSTTimestamp alloc] initWithSeconds:12346 nanos:0],
- ];
- for (int i = 0; i < timestamps.count - 1; ++i) {
- XCTAssertEqual(NSOrderedAscending, [timestamps[i] compare:timestamps[i + 1]]);
- XCTAssertEqual(NSOrderedDescending, [timestamps[i + 1] compare:timestamps[i]]);
- }
-}
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Example/Tests/Integration/API/FIRFieldsTests.mm b/Firestore/Example/Tests/Integration/API/FIRFieldsTests.mm
index 34bd87e..0e75b8e 100644
--- a/Firestore/Example/Tests/Integration/API/FIRFieldsTests.mm
+++ b/Firestore/Example/Tests/Integration/API/FIRFieldsTests.mm
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <FirebaseFirestore/FirebaseFirestore.h>
#import <XCTest/XCTest.h>
@@ -220,4 +221,28 @@
[self awaitExpectations];
}
+- (NSDictionary<NSString *, id> *)testDataWithTimestamp:(FIRTimestamp *)timestamp {
+ return @{
+ @"timestamp" : [timestamp approximateDateValue],
+ @"metadata" : @{@"nestedTimestamp" : [timestamp approximateDateValue]}
+ };
+}
+
+// This test should break once the default for how timestamps are returned changes.
+- (void)testThatDataContainsNativeDateType {
+ NSDate *date = [NSDate date];
+ FIRTimestamp *timestamp = [FIRTimestamp timestampWithDate:date];
+ FIRDocumentReference *doc = [self documentRef];
+ [self writeDocumentRef:doc data:[self testDataWithTimestamp:timestamp]];
+
+ FIRDocumentSnapshot *result = [self readDocumentForRef:doc];
+ NSDate *resultDate = result.data[@"timestamp"];
+ XCTAssertEqualWithAccuracy([resultDate timeIntervalSince1970], [date timeIntervalSince1970],
+ 0.000001);
+ XCTAssertEqualObjects(result.data[@"timestamp"], resultDate);
+ NSDate *resultNestedDate = result[@"metadata.nestedTimestamp"];
+ XCTAssertEqualWithAccuracy([resultNestedDate timeIntervalSince1970], [date timeIntervalSince1970],
+ 0.000001);
+}
+
@end
diff --git a/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm b/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm
index 36b0494..b48e5d0 100644
--- a/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm
+++ b/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm
@@ -16,6 +16,7 @@
#import <FirebaseFirestore/FirebaseFirestore.h>
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <GRPCClient/GRPCCall+ChannelCredentials.h>
#import <GRPCClient/GRPCCall+Tests.h>
#import <XCTest/XCTest.h>
@@ -26,7 +27,6 @@
#import "Firestore/Source/Core/FSTFirestoreClient.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
@@ -214,7 +214,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTSetMutation *mutation = [self setMutation];
FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:23
- localWriteTime:[FSTTimestamp timestamp]
+ localWriteTime:[FIRTimestamp timestamp]
mutations:@[ mutation ]];
[_testWorkerQueue dispatchAsync:^{
[_remoteStore commitBatch:batch];
diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm
index 1b55795..1793b23 100644
--- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm
+++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm
@@ -16,6 +16,7 @@
#import "Firestore/Source/Local/FSTLocalSerializer.h"
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <XCTest/XCTest.h>
#import "Firestore/Protos/objc/firestore/local/MaybeDocument.pbobjc.h"
@@ -29,7 +30,6 @@
#import "Firestore/Protos/objc/google/type/Latlng.pbobjc.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
@@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
@"num" : @1 })
precondition:[FSTPrecondition preconditionWithExists:YES]];
FSTMutation *del = FSTTestDeleteMutation(@"baz/quux");
- FSTTimestamp *writeTime = [FSTTimestamp timestamp];
+ FIRTimestamp *writeTime = [FIRTimestamp timestamp];
FSTMutationBatch *model = [[FSTMutationBatch alloc] initWithBatchID:42
localWriteTime:writeTime
mutations:@[ set, patch, del ]];
@@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN
GPBTimestamp *writeTimeProto = [GPBTimestamp message];
writeTimeProto.seconds = writeTime.seconds;
- writeTimeProto.nanos = writeTime.nanos;
+ writeTimeProto.nanos = writeTime.nanoseconds;
FSTPBWriteBatch *batchProto = [FSTPBWriteBatch message];
batchProto.batchId = 42;
diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm
index f3493ce..393f77b 100644
--- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm
+++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm
@@ -16,10 +16,10 @@
#import "Firestore/Source/Local/FSTLocalStore.h"
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <XCTest/XCTest.h>
#import "Firestore/Source/Core/FSTQuery.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTEagerGarbageCollector.h"
#import "Firestore/Source/Local/FSTLocalWriteResult.h"
#import "Firestore/Source/Local/FSTNoOpGarbageCollector.h"
@@ -127,7 +127,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
FSTLocalWriteResult *result = [self.localStore locallyWriteMutations:mutations];
XCTAssertNotNil(result);
[self.batches addObject:[[FSTMutationBatch alloc] initWithBatchID:result.batchID
- localWriteTime:[FSTTimestamp timestamp]
+ localWriteTime:[FIRTimestamp timestamp]
mutations:mutations]];
self.lastChanges = result.changes;
}
@@ -228,7 +228,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
FSTMutation *set1 = FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"});
FSTMutation *set2 = FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"});
FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:1
- localWriteTime:[FSTTimestamp timestamp]
+ localWriteTime:[FIRTimestamp timestamp]
mutations:@[ set1, set2 ]];
FSTDocumentKeySet *keys = [batch keys];
XCTAssertEqual(keys.count, 2);
diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm
index 62d30fb..7d305d0 100644
--- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm
+++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm
@@ -16,8 +16,8 @@
#import "Firestore/Example/Tests/Local/FSTMutationQueueTests.h"
+#import <FirebaseFirestore/FIRTimestamp.h>
#import "Firestore/Source/Core/FSTQuery.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTEagerGarbageCollector.h"
#import "Firestore/Source/Local/FSTMutationQueue.h"
#import "Firestore/Source/Local/FSTPersistence.h"
@@ -258,7 +258,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTWriteGroup *group = [self.persistence startGroupWithAction:@"New mutation batch"];
for (FSTMutation *mutation in mutations) {
FSTMutationBatch *batch =
- [self.mutationQueue addMutationBatchWithWriteTime:[FSTTimestamp timestamp]
+ [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp]
mutations:@[ mutation ]
group:group];
[batches addObject:batch];
@@ -295,7 +295,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTWriteGroup *group = [self.persistence startGroupWithAction:@"New mutation batch"];
for (FSTMutation *mutation in mutations) {
FSTMutationBatch *batch =
- [self.mutationQueue addMutationBatchWithWriteTime:[FSTTimestamp timestamp]
+ [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp]
mutations:@[ mutation ]
group:group];
[batches addObject:batch];
@@ -440,7 +440,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTWriteGroup *group = [self.persistence startGroupWithAction:@"New mutation batch"];
FSTMutationBatch *batch =
- [self.mutationQueue addMutationBatchWithWriteTime:[FSTTimestamp timestamp]
+ [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp]
mutations:@[ mutation ]
group:group];
[self.persistence commitGroup:group];
diff --git a/Firestore/Example/Tests/Model/FSTFieldValueTests.mm b/Firestore/Example/Tests/Model/FSTFieldValueTests.mm
index 52d5a4e..c0fb188 100644
--- a/Firestore/Example/Tests/Model/FSTFieldValueTests.mm
+++ b/Firestore/Example/Tests/Model/FSTFieldValueTests.mm
@@ -17,11 +17,11 @@
#import "Firestore/Source/Model/FSTFieldValue.h"
#import <FirebaseFirestore/FIRGeoPoint.h>
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <XCTest/XCTest.h>
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
#import "Firestore/Source/Model/FSTPath.h"
@@ -229,7 +229,7 @@ union DoubleBits {
XCTAssertEqualObjects([wrapped value], value);
XCTAssertEqualObjects(((FSTTimestampValue *)wrapped).internalValue,
- [FSTTimestamp timestampWithDate:value]);
+ [FIRTimestamp timestampWithDate:value]);
}
}
@@ -445,20 +445,20 @@ union DoubleBits {
@[ FSTTestFieldValue(@"\u00e9a") ], // latin small letter e with acute accent
@[
FSTTestFieldValue(date1),
- [FSTTimestampValue timestampValue:[FSTTimestamp timestampWithDate:date1]]
+ [FSTTimestampValue timestampValue:[FIRTimestamp timestampWithDate:date1]]
],
@[ FSTTestFieldValue(date2) ],
@[
// NOTE: ServerTimestampValues can't be parsed via FSTTestFieldValue().
[FSTServerTimestampValue
- serverTimestampValueWithLocalWriteTime:[FSTTimestamp timestampWithDate:date1]
+ serverTimestampValueWithLocalWriteTime:[FIRTimestamp timestampWithDate:date1]
previousValue:nil],
[FSTServerTimestampValue
- serverTimestampValueWithLocalWriteTime:[FSTTimestamp timestampWithDate:date1]
+ serverTimestampValueWithLocalWriteTime:[FIRTimestamp timestampWithDate:date1]
previousValue:nil]
],
@[ [FSTServerTimestampValue
- serverTimestampValueWithLocalWriteTime:[FSTTimestamp timestampWithDate:date2]
+ serverTimestampValueWithLocalWriteTime:[FIRTimestamp timestampWithDate:date2]
previousValue:nil] ],
@[
FSTTestFieldValue(FSTTestGeoPoint(0, 1)),
@@ -574,14 +574,12 @@ union DoubleBits {
{
XCTAssertTrue([output[@"array"][1] isKindOfClass:[NSDate class]]);
NSDate *actual = output[@"array"][1];
- XCTAssertEqualWithAccuracy(date.timeIntervalSince1970, actual.timeIntervalSince1970,
- 0.000000001);
+ XCTAssertEqualWithAccuracy(date.timeIntervalSince1970, actual.timeIntervalSince1970, 0.000001);
}
{
XCTAssertTrue([output[@"obj"][@"date"] isKindOfClass:[NSDate class]]);
NSDate *actual = output[@"obj"][@"date"];
- XCTAssertEqualWithAccuracy(date.timeIntervalSince1970, actual.timeIntervalSince1970,
- 0.000000001);
+ XCTAssertEqualWithAccuracy(date.timeIntervalSince1970, actual.timeIntervalSince1970, 0.000001);
}
}
diff --git a/Firestore/Example/Tests/Model/FSTMutationTests.mm b/Firestore/Example/Tests/Model/FSTMutationTests.mm
index 47fa9b3..1c1375c 100644
--- a/Firestore/Example/Tests/Model/FSTMutationTests.mm
+++ b/Firestore/Example/Tests/Model/FSTMutationTests.mm
@@ -16,9 +16,9 @@
#import "Firestore/Source/Model/FSTMutation.h"
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <XCTest/XCTest.h>
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
@@ -30,11 +30,11 @@
@end
@implementation FSTMutationTests {
- FSTTimestamp *_timestamp;
+ FIRTimestamp *_timestamp;
}
- (void)setUp {
- _timestamp = [FSTTimestamp timestamp];
+ _timestamp = [FIRTimestamp timestamp];
}
- (void)testAppliesSetsToDocuments {
diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm
index 48e5546..f7cc1b0 100644
--- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm
+++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm
@@ -19,6 +19,7 @@
#import <FirebaseFirestore/FIRFieldPath.h>
#import <FirebaseFirestore/FIRFirestoreErrors.h>
#import <FirebaseFirestore/FIRGeoPoint.h>
+#import <FirebaseFirestore/FIRTimestamp.h>
#import <GRPCClient/GRPCCall.h>
#import <XCTest/XCTest.h>
@@ -33,7 +34,6 @@
#import "Firestore/Protos/objc/google/type/Latlng.pbobjc.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
@@ -380,7 +380,7 @@ NS_ASSUME_NONNULL_BEGIN
GCFSWrite *proto = [GCFSWrite message];
proto.update = [self.serializer encodedDocumentWithFields:mutation.value key:mutation.key];
proto.currentDocument.updateTime =
- [self.serializer encodedTimestamp:[[FSTTimestamp alloc] initWithSeconds:0 nanos:4000]];
+ [self.serializer encodedTimestamp:[[FIRTimestamp alloc] initWithSeconds:0 nanoseconds:4000]];
[self assertRoundTripForMutation:mutation proto:proto];
}
diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h
index 4dbf910..9ee9a0b 100644
--- a/Firestore/Example/Tests/Util/FSTHelpers.h
+++ b/Firestore/Example/Tests/Util/FSTHelpers.h
@@ -37,7 +37,7 @@
@class FSTSnapshotVersion;
@class FSTSortOrder;
@class FSTTargetChange;
-@class FSTTimestamp;
+@class FIRTimestamp;
@class FSTTransformMutation;
@class FSTView;
@class FSTViewSnapshot;
@@ -132,8 +132,8 @@ extern "C" {
XCTAssertTrue(__didThrow, ##__VA_ARGS__); \
})
-/** Creates a new FSTTimestamp from components. Note that year, month, and day are all one-based. */
-FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second);
+/** Creates a new FIRTimestamp from components. Note that year, month, and day are all one-based. */
+FIRTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second);
/** Creates a new NSDate from components. Note that year, month, and day are all one-based. */
NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int second);
diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm
index 452e9a6..586fdbc 100644
--- a/Firestore/Example/Tests/Util/FSTHelpers.mm
+++ b/Firestore/Example/Tests/Util/FSTHelpers.mm
@@ -21,12 +21,12 @@
#import <FirebaseFirestore/FIRFieldPath.h>
#import <FirebaseFirestore/FIRGeoPoint.h>
+#import <FirebaseFirestore/FIRTimestamp.h>
#import "Firestore/Source/API/FIRFieldPath+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Core/FSTView.h"
#import "Firestore/Source/Core/FSTViewSnapshot.h"
#import "Firestore/Source/Local/FSTLocalViewChanges.h"
@@ -55,9 +55,9 @@ static NSString *const kDeleteSentinel = @"<DELETE>";
static const int kMicrosPerSec = 1000000;
static const int kMillisPerSec = 1000;
-FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second) {
+FIRTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second) {
NSDate *date = FSTTestDate(year, month, day, hour, minute, second);
- return [FSTTimestamp timestampWithDate:date];
+ return [FIRTimestamp timestampWithDate:date];
}
NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int second) {
@@ -140,7 +140,7 @@ FSTSnapshotVersion *FSTTestVersion(FSTTestSnapshotVersion versionMicroseconds) {
int64_t seconds = versionMicroseconds / kMicrosPerSec;
int32_t nanos = (int32_t)(versionMicroseconds % kMicrosPerSec) * kMillisPerSec;
- FSTTimestamp *timestamp = [[FSTTimestamp alloc] initWithSeconds:seconds nanos:nanos];
+ FIRTimestamp *timestamp = [[FIRTimestamp alloc] initWithSeconds:seconds nanoseconds:nanos];
return [FSTSnapshotVersion versionWithTimestamp:timestamp];
}
diff --git a/Firestore/Source/API/FIRTimestamp+Internal.h b/Firestore/Source/API/FIRTimestamp+Internal.h
new file mode 100644
index 0000000..48e38b2
--- /dev/null
+++ b/Firestore/Source/API/FIRTimestamp+Internal.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2018 Google
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import "FIRTimestamp.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** Internal FIRTimestamp API we don't want exposed in our public header files. */
+@interface FIRTimestamp (Internal)
+
+/**
+ * Converts the given date to an ISO 8601 timestamp string, useful for rendering in JSON.
+ *
+ * ISO 8601 dates times in UTC look like this: "1912-04-14T23:40:00.000000000Z".
+ *
+ * @see http://www.ecma-international.org/ecma-262/6.0/#sec-date-time-string-format
+ */
+- (NSString *)ISO8601String;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Core/FSTTimestamp.mm b/Firestore/Source/API/FIRTimestamp.m
index d2b492a..489b921 100644
--- a/Firestore/Source/Core/FSTTimestamp.mm
+++ b/Firestore/Source/API/FIRTimestamp.m
@@ -14,26 +14,36 @@
* limitations under the License.
*/
-#import "Firestore/Source/Core/FSTTimestamp.h"
-
-#include "Firestore/core/src/firebase/firestore/util/comparison.h"
-
-#import "Firestore/Source/Util/FSTAssert.h"
-
-using firebase::firestore::util::WrapCompare;
+#import "Firestore/Source/API/FIRTimestamp+Internal.h"
NS_ASSUME_NONNULL_BEGIN
static const int kNanosPerSecond = 1000000000;
-@implementation FSTTimestamp
+@implementation FIRTimestamp (Internal)
-#pragma mark - Constructors
+#pragma mark - Internal public methods
-+ (instancetype)timestamp {
- return [FSTTimestamp timestampWithDate:[NSDate date]];
+- (NSString *)ISO8601String {
+ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+ formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
+ formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
+ NSDate *secondsDate = [NSDate dateWithTimeIntervalSince1970:self.seconds];
+ NSString *secondsString = [formatter stringFromDate:secondsDate];
+ if (secondsString.length != 19) {
+ [NSException raise:@"Invalid ISO string" format:@"Invalid ISO string: %@", secondsString];
+ }
+
+ NSString *nanosString = [NSString stringWithFormat:@"%09d", self.nanoseconds];
+ return [NSString stringWithFormat:@"%@.%@Z", secondsString, nanosString];
}
+@end
+
+@implementation FIRTimestamp
+
+#pragma mark - Constructors
+
+ (instancetype)timestampWithDate:(NSDate *)date {
double secondsDouble;
double fraction = modf(date.timeIntervalSince1970, &secondsDouble);
@@ -44,21 +54,41 @@ static const int kNanosPerSecond = 1000000000;
}
int64_t seconds = (int64_t)secondsDouble;
int32_t nanos = (int32_t)(fraction * kNanosPerSecond);
- return [[FSTTimestamp alloc] initWithSeconds:seconds nanos:nanos];
+ return [[FIRTimestamp alloc] initWithSeconds:seconds nanoseconds:nanos];
}
-- (instancetype)initWithSeconds:(int64_t)seconds nanos:(int32_t)nanos {
++ (instancetype)timestampWithSeconds:(int64_t)seconds nanoseconds:(int32_t)nanoseconds {
+ return [[FIRTimestamp alloc] initWithSeconds:seconds nanoseconds:nanoseconds];
+}
+
++ (instancetype)timestamp {
+ return [FIRTimestamp timestampWithDate:[NSDate date]];
+}
+
+- (instancetype)initWithSeconds:(int64_t)seconds nanoseconds:(int32_t)nanoseconds {
self = [super init];
if (self) {
- FSTAssert(nanos >= 0, @"timestamp nanoseconds out of range: %d", nanos);
- FSTAssert(nanos < 1e9, @"timestamp nanoseconds out of range: %d", nanos);
- // Midnight at the beginning of 1/1/1 is the earliest timestamp Firestore supports.
- FSTAssert(seconds >= -62135596800L, @"timestamp seconds out of range: %lld", seconds);
+ if (nanoseconds < 0) {
+ [NSException raise:@"Invalid timestamp"
+ format:@"Timestamp nanoseconds out of range: %d", nanoseconds];
+ }
+ if (nanoseconds >= 1e9) {
+ [NSException raise:@"Invalid timestamp"
+ format:@"Timestamp nanoseconds out of range: %d", nanoseconds];
+ }
+ // Midnight at the beginning of 1/1/1 is the earliest timestamp supported.
+ if (seconds < -62135596800L) {
+ [NSException raise:@"Invalid timestamp"
+ format:@"Timestamp seconds out of range: %lld", seconds];
+ }
// This will break in the year 10,000.
- FSTAssert(seconds < 253402300800L, @"timestamp seconds out of range: %lld", seconds);
+ if (seconds >= 253402300800L) {
+ [NSException raise:@"Invalid timestamp"
+ format:@"Timestamp seconds out of range: %lld", seconds];
+ }
_seconds = seconds;
- _nanos = nanos;
+ _nanoseconds = nanoseconds;
}
return self;
}
@@ -69,19 +99,19 @@ static const int kNanosPerSecond = 1000000000;
if (self == object) {
return YES;
}
- if (![object isKindOfClass:[FSTTimestamp class]]) {
+ if (![object isKindOfClass:[FIRTimestamp class]]) {
return NO;
}
- return [self isEqualToTimestamp:(FSTTimestamp *)object];
+ return [self isEqualToTimestamp:(FIRTimestamp *)object];
}
- (NSUInteger)hash {
- return (NSUInteger)((self.seconds >> 32) ^ self.seconds ^ self.nanos);
+ return (NSUInteger)((self.seconds >> 32) ^ self.seconds ^ self.nanoseconds);
}
- (NSString *)description {
- return [NSString
- stringWithFormat:@"<FSTTimestamp: seconds=%lld nanos=%d>", self.seconds, self.nanos];
+ return [NSString stringWithFormat:@"FIRTimestamp: seconds=%lld nanoseconds=%d>", self.seconds,
+ self.nanoseconds];
}
/** Implements NSCopying without actually copying because timestamps are immutable. */
@@ -92,32 +122,29 @@ static const int kNanosPerSecond = 1000000000;
#pragma mark - Public methods
- (NSDate *)approximateDateValue {
- NSTimeInterval interval = (NSTimeInterval)self.seconds + ((NSTimeInterval)self.nanos) / 1e9;
+ NSTimeInterval interval = (NSTimeInterval)self.seconds + ((NSTimeInterval)self.nanoseconds) / 1e9;
return [NSDate dateWithTimeIntervalSince1970:interval];
}
-- (BOOL)isEqualToTimestamp:(FSTTimestamp *)other {
- return [self compare:other] == NSOrderedSame;
-}
-
-- (NSString *)ISO8601String {
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
- formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
- NSDate *secondsDate = [NSDate dateWithTimeIntervalSince1970:self.seconds];
- NSString *secondsString = [formatter stringFromDate:secondsDate];
- FSTAssert(secondsString.length == 19, @"Invalid ISO string: %@", secondsString);
+- (NSComparisonResult)compare:(FIRTimestamp *)other {
+ if (self.seconds < other.seconds) {
+ return NSOrderedAscending;
+ } else if (self.seconds > other.seconds) {
+ return NSOrderedDescending;
+ }
- NSString *nanosString = [NSString stringWithFormat:@"%09d", self.nanos];
- return [NSString stringWithFormat:@"%@.%@Z", secondsString, nanosString];
+ if (self.nanoseconds < other.nanoseconds) {
+ return NSOrderedAscending;
+ } else if (self.nanoseconds > other.nanoseconds) {
+ return NSOrderedDescending;
+ }
+ return NSOrderedSame;
}
-- (NSComparisonResult)compare:(FSTTimestamp *)other {
- NSComparisonResult result = WrapCompare<int64_t>(self.seconds, other.seconds);
- if (result != NSOrderedSame) {
- return result;
- }
- return WrapCompare<int32_t>(self.nanos, other.nanos);
+#pragma mark - Private methods
+
+- (BOOL)isEqualToTimestamp:(FIRTimestamp *)other {
+ return [self compare:other] == NSOrderedSame;
}
@end
diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm
index 80d4625..f97aea1 100644
--- a/Firestore/Source/API/FSTUserDataConverter.mm
+++ b/Firestore/Source/API/FSTUserDataConverter.mm
@@ -16,13 +16,14 @@
#import "Firestore/Source/API/FSTUserDataConverter.h"
+#import "FIRTimestamp.h"
+
#import "FIRGeoPoint.h"
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRFieldPath+Internal.h"
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/API/FIRSetOptions+Internal.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
#import "Firestore/Source/Model/FSTMutation.h"
@@ -536,7 +537,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
return [FSTStringValue stringValue:input];
} else if ([input isKindOfClass:[NSDate class]]) {
- return [FSTTimestampValue timestampValue:[FSTTimestamp timestampWithDate:input]];
+ return [FSTTimestampValue timestampValue:[FIRTimestamp timestampWithDate:input]];
} else if ([input isKindOfClass:[FIRGeoPoint class]]) {
return [FSTGeoPointValue geoPointValue:input];
diff --git a/Firestore/Source/Core/FSTSnapshotVersion.h b/Firestore/Source/Core/FSTSnapshotVersion.h
index b72e4a2..8649d40 100644
--- a/Firestore/Source/Core/FSTSnapshotVersion.h
+++ b/Firestore/Source/Core/FSTSnapshotVersion.h
@@ -18,7 +18,7 @@
NS_ASSUME_NONNULL_BEGIN
-@class FSTTimestamp;
+@class FIRTimestamp;
/**
* A version of a document in Firestore. This corresponds to the version timestamp, such as
@@ -30,13 +30,13 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)noVersion;
/** Creates a new version representing the given timestamp. */
-+ (instancetype)versionWithTimestamp:(FSTTimestamp *)timestamp;
++ (instancetype)versionWithTimestamp:(FIRTimestamp *)timestamp;
- (instancetype)init NS_UNAVAILABLE;
- (NSComparisonResult)compare:(FSTSnapshotVersion *)other;
-@property(nonatomic, strong, readonly) FSTTimestamp *timestamp;
+@property(nonatomic, strong, readonly) FIRTimestamp *timestamp;
@end
diff --git a/Firestore/Source/Core/FSTSnapshotVersion.mm b/Firestore/Source/Core/FSTSnapshotVersion.mm
index 980ae52..58b2be4 100644
--- a/Firestore/Source/Core/FSTSnapshotVersion.mm
+++ b/Firestore/Source/Core/FSTSnapshotVersion.mm
@@ -16,7 +16,7 @@
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
+#import "FIRTimestamp.h"
NS_ASSUME_NONNULL_BEGIN
@@ -26,17 +26,17 @@ NS_ASSUME_NONNULL_BEGIN
static FSTSnapshotVersion *min;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- FSTTimestamp *timestamp = [[FSTTimestamp alloc] initWithSeconds:0 nanos:0];
+ FIRTimestamp *timestamp = [[FIRTimestamp alloc] initWithSeconds:0 nanoseconds:0];
min = [FSTSnapshotVersion versionWithTimestamp:timestamp];
});
return min;
}
-+ (instancetype)versionWithTimestamp:(FSTTimestamp *)timestamp {
++ (instancetype)versionWithTimestamp:(FIRTimestamp *)timestamp {
return [[FSTSnapshotVersion alloc] initWithTimestamp:timestamp];
}
-- (instancetype)initWithTimestamp:(FSTTimestamp *)timestamp {
+- (instancetype)initWithTimestamp:(FIRTimestamp *)timestamp {
self = [super init];
if (self) {
_timestamp = timestamp;
diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm
index 982e09c..248ef9a 100644
--- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm
+++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm
@@ -269,7 +269,7 @@ static ReadOptions StandardReadOptions() {
}
}
-- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FSTTimestamp *)localWriteTime
+- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime
mutations:(NSArray<FSTMutation *> *)mutations
group:(FSTWriteGroup *)group {
FSTBatchID batchID = self.nextBatchID;
diff --git a/Firestore/Source/Local/FSTLocalSerializer.mm b/Firestore/Source/Local/FSTLocalSerializer.mm
index c531c77..ec70ca0 100644
--- a/Firestore/Source/Local/FSTLocalSerializer.mm
+++ b/Firestore/Source/Local/FSTLocalSerializer.mm
@@ -142,7 +142,7 @@
[mutations addObject:[remoteSerializer decodedMutation:write]];
}
- FSTTimestamp *localWriteTime = [remoteSerializer decodedTimestamp:batch.localWriteTime];
+ FIRTimestamp *localWriteTime = [remoteSerializer decodedTimestamp:batch.localWriteTime];
return [[FSTMutationBatch alloc] initWithBatchID:batchID
localWriteTime:localWriteTime
diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm
index d12a45b..a5b85cd 100644
--- a/Firestore/Source/Local/FSTLocalStore.mm
+++ b/Firestore/Source/Local/FSTLocalStore.mm
@@ -16,10 +16,10 @@
#import "Firestore/Source/Local/FSTLocalStore.h"
+#import "FIRTimestamp.h"
#import "Firestore/Source/Core/FSTListenSequence.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTGarbageCollector.h"
#import "Firestore/Source/Local/FSTLocalDocumentsView.h"
#import "Firestore/Source/Local/FSTLocalViewChanges.h"
@@ -201,7 +201,7 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTLocalWriteResult *)locallyWriteMutations:(NSArray<FSTMutation *> *)mutations {
FSTWriteGroup *group = [self.persistence startGroupWithAction:@"Locally write mutations"];
- FSTTimestamp *localWriteTime = [FSTTimestamp timestamp];
+ FIRTimestamp *localWriteTime = [FIRTimestamp timestamp];
FSTMutationBatch *batch = [self.mutationQueue addMutationBatchWithWriteTime:localWriteTime
mutations:mutations
group:group];
diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.mm b/Firestore/Source/Local/FSTMemoryMutationQueue.mm
index 702f614..2a6a1cc 100644
--- a/Firestore/Source/Local/FSTMemoryMutationQueue.mm
+++ b/Firestore/Source/Local/FSTMemoryMutationQueue.mm
@@ -139,7 +139,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left,
self.lastStreamToken = streamToken;
}
-- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FSTTimestamp *)localWriteTime
+- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime
mutations:(NSArray<FSTMutation *> *)mutations
group:(FSTWriteGroup *)group {
FSTAssert(mutations.count > 0, @"Mutation batches should not be empty");
diff --git a/Firestore/Source/Local/FSTMutationQueue.h b/Firestore/Source/Local/FSTMutationQueue.h
index a1eddd4..12f3284 100644
--- a/Firestore/Source/Local/FSTMutationQueue.h
+++ b/Firestore/Source/Local/FSTMutationQueue.h
@@ -23,7 +23,7 @@
@class FSTMutation;
@class FSTMutationBatch;
@class FSTQuery;
-@class FSTTimestamp;
+@class FIRTimestamp;
@class FSTWriteGroup;
NS_ASSUME_NONNULL_BEGIN
@@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setLastStreamToken:(nullable NSData *)streamToken group:(FSTWriteGroup *)group;
/** Creates a new mutation batch and adds it to this mutation queue. */
-- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FSTTimestamp *)localWriteTime
+- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime
mutations:(NSArray<FSTMutation *> *)mutations
group:(FSTWriteGroup *)group;
diff --git a/Firestore/Source/Model/FSTFieldValue.h b/Firestore/Source/Model/FSTFieldValue.h
index c8118c6..be8ba45 100644
--- a/Firestore/Source/Model/FSTFieldValue.h
+++ b/Firestore/Source/Model/FSTFieldValue.h
@@ -22,7 +22,7 @@
@class FSTDocumentKey;
@class FSTFieldPath;
-@class FSTTimestamp;
+@class FIRTimestamp;
@class FSTFieldValueOptions;
@class FIRGeoPoint;
@class FIRSnapshotOptions;
@@ -164,8 +164,8 @@ typedef NS_ENUM(NSInteger, FSTServerTimestampBehavior) {
* A timestamp value stored in Firestore.
*/
@interface FSTTimestampValue : FSTFieldValue <NSDate *>
-+ (instancetype)timestampValue:(FSTTimestamp *)value;
-- (FSTTimestamp *)internalValue;
++ (instancetype)timestampValue:(FIRTimestamp *)value;
+- (FIRTimestamp *)internalValue;
@end
/**
@@ -181,10 +181,10 @@ typedef NS_ENUM(NSInteger, FSTServerTimestampBehavior) {
* sort by their localWriteTime.
*/
@interface FSTServerTimestampValue : FSTFieldValue <id>
-+ (instancetype)serverTimestampValueWithLocalWriteTime:(FSTTimestamp *)localWriteTime
++ (instancetype)serverTimestampValueWithLocalWriteTime:(FIRTimestamp *)localWriteTime
previousValue:(nullable FSTFieldValue *)previousValue;
-@property(nonatomic, strong, readonly) FSTTimestamp *localWriteTime;
+@property(nonatomic, strong, readonly) FIRTimestamp *localWriteTime;
@property(nonatomic, strong, readonly, nullable) FSTFieldValue *previousValue;
@end
diff --git a/Firestore/Source/Model/FSTFieldValue.mm b/Firestore/Source/Model/FSTFieldValue.mm
index 3f3548c..5ef64e1 100644
--- a/Firestore/Source/Model/FSTFieldValue.mm
+++ b/Firestore/Source/Model/FSTFieldValue.mm
@@ -16,12 +16,13 @@
#import "Firestore/Source/Model/FSTFieldValue.h"
+#import "FIRTimestamp.h"
+
#include "Firestore/core/src/firebase/firestore/util/comparison.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
#import "Firestore/Source/API/FIRGeoPoint+Internal.h"
#import "Firestore/Source/API/FIRSnapshotOptions+Internal.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTPath.h"
#import "Firestore/Source/Util/FSTAssert.h"
@@ -424,19 +425,19 @@ struct Comparator<NSString *> {
#pragma mark - FSTTimestampValue
@interface FSTTimestampValue ()
-@property(nonatomic, strong, readonly) FSTTimestamp *internalValue;
+@property(nonatomic, strong, readonly) FIRTimestamp *internalValue;
@end
@implementation FSTTimestampValue
-+ (instancetype)timestampValue:(FSTTimestamp *)value {
++ (instancetype)timestampValue:(FIRTimestamp *)value {
return [[FSTTimestampValue alloc] initWithValue:value];
}
-- (id)initWithValue:(FSTTimestamp *)value {
+- (id)initWithValue:(FIRTimestamp *)value {
self = [super init];
if (self) {
- _internalValue = value; // FSTTimestamp is immutable.
+ _internalValue = value; // FIRTimestamp is immutable.
}
return self;
}
@@ -476,13 +477,13 @@ struct Comparator<NSString *> {
@implementation FSTServerTimestampValue
-+ (instancetype)serverTimestampValueWithLocalWriteTime:(FSTTimestamp *)localWriteTime
++ (instancetype)serverTimestampValueWithLocalWriteTime:(FIRTimestamp *)localWriteTime
previousValue:(nullable FSTFieldValue *)previousValue {
return [[FSTServerTimestampValue alloc] initWithLocalWriteTime:localWriteTime
previousValue:previousValue];
}
-- (id)initWithLocalWriteTime:(FSTTimestamp *)localWriteTime
+- (id)initWithLocalWriteTime:(FIRTimestamp *)localWriteTime
previousValue:(nullable FSTFieldValue *)previousValue {
self = [super init];
if (self) {
diff --git a/Firestore/Source/Model/FSTMutation.h b/Firestore/Source/Model/FSTMutation.h
index 7c5f6de..72f6a25 100644
--- a/Firestore/Source/Model/FSTMutation.h
+++ b/Firestore/Source/Model/FSTMutation.h
@@ -23,7 +23,7 @@
@class FSTMaybeDocument;
@class FSTObjectValue;
@class FSTSnapshotVersion;
-@class FSTTimestamp;
+@class FIRTimestamp;
NS_ASSUME_NONNULL_BEGIN
@@ -200,7 +200,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) {
*/
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutationResult:(nullable FSTMutationResult *)mutationResult;
/**
@@ -209,7 +209,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) {
*/
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(nullable FSTTimestamp *)localWriteTime;
+ localWriteTime:(nullable FIRTimestamp *)localWriteTime;
@property(nonatomic, strong, readonly) FSTDocumentKey *key;
diff --git a/Firestore/Source/Model/FSTMutation.mm b/Firestore/Source/Model/FSTMutation.mm
index c249138..e702644 100644
--- a/Firestore/Source/Model/FSTMutation.mm
+++ b/Firestore/Source/Model/FSTMutation.mm
@@ -16,8 +16,9 @@
#import "Firestore/Source/Model/FSTMutation.h"
+#import "FIRTimestamp.h"
+
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
@@ -238,14 +239,14 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutationResult:(nullable FSTMutationResult *)mutationResult {
@throw FSTAbstractMethodException(); // NOLINT
}
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(nullable FSTTimestamp *)localWriteTime {
+ localWriteTime:(nullable FIRTimestamp *)localWriteTime {
return
[self applyTo:maybeDoc baseDocument:baseDoc localWriteTime:localWriteTime mutationResult:nil];
}
@@ -292,7 +293,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutationResult:(nullable FSTMutationResult *)mutationResult {
if (mutationResult) {
FSTAssert(!mutationResult.transformResults, @"Transform results received by FSTSetMutation.");
@@ -368,7 +369,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutationResult:(nullable FSTMutationResult *)mutationResult {
if (mutationResult) {
FSTAssert(!mutationResult.transformResults, @"Transform results received by FSTPatchMutation.");
@@ -458,7 +459,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutationResult:(nullable FSTMutationResult *)mutationResult {
if (mutationResult) {
FSTAssert(mutationResult.transformResults,
@@ -500,7 +501,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (NSArray<FSTFieldValue *> *)localTransformResultsWithBaseDocument:
(FSTMaybeDocument *_Nullable)baseDocument
- writeTime:(FSTTimestamp *)localWriteTime {
+ writeTime:(FIRTimestamp *)localWriteTime {
NSMutableArray<FSTFieldValue *> *transformResults = [NSMutableArray array];
for (FSTFieldTransform *fieldTransform in self.fieldTransforms) {
if ([fieldTransform.transform isKindOfClass:[FSTServerTimestampTransform class]]) {
@@ -570,7 +571,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
baseDocument:(nullable FSTMaybeDocument *)baseDoc
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutationResult:(nullable FSTMutationResult *)mutationResult {
if (mutationResult) {
FSTAssert(!mutationResult.transformResults,
diff --git a/Firestore/Source/Model/FSTMutationBatch.h b/Firestore/Source/Model/FSTMutationBatch.h
index 145adfa..1de79fe 100644
--- a/Firestore/Source/Model/FSTMutationBatch.h
+++ b/Firestore/Source/Model/FSTMutationBatch.h
@@ -21,7 +21,7 @@
#import "Firestore/Source/Model/FSTDocumentVersionDictionary.h"
@class FSTMutation;
-@class FSTTimestamp;
+@class FIRTimestamp;
@class FSTMutationResult;
@class FSTMutationBatchResult;
@class FSTSnapshotVersion;
@@ -45,7 +45,7 @@ extern const FSTBatchID kFSTBatchIDUnknown;
/** Initializes a mutation batch with the given batchID, localWriteTime, and mutations. */
- (instancetype)initWithBatchID:(FSTBatchID)batchID
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutations:(NSArray<FSTMutation *> *)mutations NS_DESIGNATED_INITIALIZER;
- (id)init NS_UNAVAILABLE;
@@ -86,7 +86,7 @@ extern const FSTBatchID kFSTBatchIDUnknown;
- (FSTDocumentKeySet *)keys;
@property(nonatomic, assign, readonly) FSTBatchID batchID;
-@property(nonatomic, strong, readonly) FSTTimestamp *localWriteTime;
+@property(nonatomic, strong, readonly) FIRTimestamp *localWriteTime;
@property(nonatomic, strong, readonly) NSArray<FSTMutation *> *mutations;
@end
diff --git a/Firestore/Source/Model/FSTMutationBatch.mm b/Firestore/Source/Model/FSTMutationBatch.mm
index 01adca7..07aadbb 100644
--- a/Firestore/Source/Model/FSTMutationBatch.mm
+++ b/Firestore/Source/Model/FSTMutationBatch.mm
@@ -16,8 +16,9 @@
#import "Firestore/Source/Model/FSTMutationBatch.h"
+#import "FIRTimestamp.h"
+
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTMutation.h"
@@ -30,7 +31,7 @@ const FSTBatchID kFSTBatchIDUnknown = -1;
@implementation FSTMutationBatch
- (instancetype)initWithBatchID:(FSTBatchID)batchID
- localWriteTime:(FSTTimestamp *)localWriteTime
+ localWriteTime:(FIRTimestamp *)localWriteTime
mutations:(NSArray<FSTMutation *> *)mutations {
self = [super init];
if (self) {
diff --git a/Firestore/Source/Core/FSTTimestamp.h b/Firestore/Source/Public/FIRTimestamp.h
index f86779d..d0a77f3 100644
--- a/Firestore/Source/Core/FSTTimestamp.h
+++ b/Firestore/Source/Public/FIRTimestamp.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Google
+ * Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,40 +19,50 @@
NS_ASSUME_NONNULL_BEGIN
/**
- * An FSTTimestamp represents an absolute time from the backend at up to nanosecond precision.
- * An FSTTimestamp is represented in terms of UTC and does not have an associated timezone.
+ * A Timestamp represents a point in time independent of any time zone or calendar, represented as
+ * seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using
+ * the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one. It
+ * is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are "smeared" so that no
+ * leap second table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
+ * 9999-12-31T23:59:59.999999999Z. By restricting to that range, we ensure that we can convert to
+ * and from RFC 3339 date strings.
+ *
+ * @see https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto for the
+ * reference timestamp definition.
*/
-@interface FSTTimestamp : NSObject <NSCopying>
+NS_SWIFT_NAME(Timestamp)
+@interface FIRTimestamp : NSObject <NSCopying>
+/** */
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a new timestamp.
*
* @param seconds the number of seconds since epoch.
- * @param nanos the number of nanoseconds after the seconds.
+ * @param nanoseconds the number of nanoseconds after the seconds.
*/
-- (instancetype)initWithSeconds:(int64_t)seconds nanos:(int32_t)nanos NS_DESIGNATED_INITIALIZER;
+- (instancetype)initWithSeconds:(int64_t)seconds
+ nanoseconds:(int32_t)nanoseconds NS_DESIGNATED_INITIALIZER;
-/** Creates a new timestamp with the current date / time. */
-+ (instancetype)timestamp;
+/**
+ * Creates a new timestamp.
+ *
+ * @param seconds the number of seconds since epoch.
+ * @param nanoseconds the number of nanoseconds after the seconds.
+ */
++ (instancetype)timestampWithSeconds:(int64_t)seconds nanoseconds:(int32_t)nanoseconds;
/** Creates a new timestamp from the given date. */
+ (instancetype)timestampWithDate:(NSDate *)date;
+/** Creates a new timestamp with the current date / time. */
++ (instancetype)timestamp;
+
/** Returns a new NSDate corresponding to this timestamp. This may lose precision. */
- (NSDate *)approximateDateValue;
-/**
- * Converts the given date to a an ISO 8601 timestamp string, useful for rendering in JSON.
- *
- * ISO 8601 dates times in UTC look like this: "1912-04-14T23:40:00.000000000Z".
- *
- * @see http://www.ecma-international.org/ecma-262/6.0/#sec-date-time-string-format
- */
-- (NSString *)ISO8601String;
-
-- (NSComparisonResult)compare:(FSTTimestamp *)other;
+- (NSComparisonResult)compare:(FIRTimestamp *)other;
/**
* Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
@@ -65,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
* fractions must still have non-negative nanos values that count forward in time.
* Must be from 0 to 999,999,999 inclusive.
*/
-@property(nonatomic, assign, readonly) int32_t nanos;
+@property(nonatomic, assign, readonly) int32_t nanoseconds;
@end
diff --git a/Firestore/Source/Public/FirebaseFirestore.h b/Firestore/Source/Public/FirebaseFirestore.h
index ff110fd..36f9fb7 100644
--- a/Firestore/Source/Public/FirebaseFirestore.h
+++ b/Firestore/Source/Public/FirebaseFirestore.h
@@ -29,5 +29,6 @@
#import "FIRQuerySnapshot.h"
#import "FIRSetOptions.h"
#import "FIRSnapshotMetadata.h"
+#import "FIRTimestamp.h"
#import "FIRTransaction.h"
#import "FIRWriteBatch.h"
diff --git a/Firestore/Source/Remote/FSTSerializerBeta.h b/Firestore/Source/Remote/FSTSerializerBeta.h
index 03e6d14..0f1c3ae 100644
--- a/Firestore/Source/Remote/FSTSerializerBeta.h
+++ b/Firestore/Source/Remote/FSTSerializerBeta.h
@@ -28,7 +28,7 @@
@class FSTQuery;
@class FSTQueryData;
@class FSTSnapshotVersion;
-@class FSTTimestamp;
+@class FIRTimestamp;
@class FSTWatchChange;
@class GCFSBatchGetDocumentsResponse;
@@ -61,8 +61,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDatabaseID:(const firebase::firestore::model::DatabaseId *)databaseID
NS_DESIGNATED_INITIALIZER;
-- (GPBTimestamp *)encodedTimestamp:(FSTTimestamp *)timestamp;
-- (FSTTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp;
+- (GPBTimestamp *)encodedTimestamp:(FIRTimestamp *)timestamp;
+- (FIRTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp;
- (GPBTimestamp *)encodedVersion:(FSTSnapshotVersion *)version;
- (FSTSnapshotVersion *)decodedVersion:(GPBTimestamp *)version;
diff --git a/Firestore/Source/Remote/FSTSerializerBeta.mm b/Firestore/Source/Remote/FSTSerializerBeta.mm
index 35ab637..ceb0501 100644
--- a/Firestore/Source/Remote/FSTSerializerBeta.mm
+++ b/Firestore/Source/Remote/FSTSerializerBeta.mm
@@ -19,6 +19,7 @@
#include <inttypes.h>
#import <GRPCClient/GRPCCall.h>
+#import "FIRTimestamp.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Common.pbobjc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Document.pbobjc.h"
@@ -32,7 +33,6 @@
#import "FIRGeoPoint.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
-#import "Firestore/Source/Core/FSTTimestamp.h"
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
@@ -69,15 +69,15 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - FSTSnapshotVersion <=> GPBTimestamp
-- (GPBTimestamp *)encodedTimestamp:(FSTTimestamp *)timestamp {
+- (GPBTimestamp *)encodedTimestamp:(FIRTimestamp *)timestamp {
GPBTimestamp *result = [GPBTimestamp message];
result.seconds = timestamp.seconds;
- result.nanos = timestamp.nanos;
+ result.nanos = timestamp.nanoseconds;
return result;
}
-- (FSTTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp {
- return [[FSTTimestamp alloc] initWithSeconds:timestamp.seconds nanos:timestamp.nanos];
+- (FIRTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp {
+ return [[FIRTimestamp alloc] initWithSeconds:timestamp.seconds nanoseconds:timestamp.nanos];
}
- (GPBTimestamp *)encodedVersion:(FSTSnapshotVersion *)version {
@@ -287,7 +287,7 @@ NS_ASSUME_NONNULL_BEGIN
return result;
}
-- (GCFSValue *)encodedTimestampValue:(FSTTimestamp *)value {
+- (GCFSValue *)encodedTimestampValue:(FIRTimestamp *)value {
GCFSValue *result = [GCFSValue message];
result.timestampValue = [self encodedTimestamp:value];
return result;