23
23
#import " FIRTimestamp.h"
24
24
25
25
#import " Firestore/Source/API/FIRGeoPoint+Internal.h"
26
+ #import " Firestore/Source/API/FIRTimestamp+Internal.h"
26
27
#import " Firestore/Source/API/converters.h"
27
28
#import " Firestore/Source/Model/FSTDocumentKey.h"
28
29
#import " Firestore/Source/Util/FSTClasses.h"
@@ -127,66 +128,6 @@ - (double)doubleValue {
127
128
128
129
@end
129
130
130
- #pragma mark - FSTTimestampValue
131
-
132
- @implementation FSTTimestampValue {
133
- Timestamp _internalValue;
134
- }
135
-
136
- + (instancetype )timestampValue : (const Timestamp &)value {
137
- return [[FSTTimestampValue alloc ] initWithValue: value];
138
- }
139
-
140
- - (id )initWithValue : (const Timestamp &)value {
141
- self = [super init ];
142
- if (self) {
143
- _internalValue = value;
144
- }
145
- return self;
146
- }
147
-
148
- - (FieldValue::Type)type {
149
- return FieldValue::Type::Timestamp;
150
- }
151
-
152
- - (FSTTypeOrder)typeOrder {
153
- return FSTTypeOrderTimestamp;
154
- }
155
-
156
- - (id )value {
157
- return MakeFIRTimestamp (_internalValue);
158
- }
159
-
160
- - (id )valueWithOptions : (const FieldValueOptions &)options {
161
- if (options.timestamps_in_snapshots_enabled ()) {
162
- return self.value ;
163
- } else {
164
- return [self .value dateValue ];
165
- }
166
- }
167
-
168
- - (BOOL )isEqual : (id )other {
169
- return [other isKindOfClass: [FSTFieldValue class ]] &&
170
- ((FSTFieldValue *)other).type == FieldValue::Type::Timestamp &&
171
- _internalValue == ((FSTTimestampValue *)other)->_internalValue ;
172
- }
173
-
174
- - (NSUInteger )hash {
175
- return TimestampInternal::Hash (_internalValue);
176
- }
177
-
178
- - (NSComparisonResult )compare : (FSTFieldValue *)other {
179
- if (other.type == FieldValue::Type::Timestamp) {
180
- return WrapCompare (_internalValue, ((FSTTimestampValue *)other)->_internalValue );
181
- } else if (other.type == FieldValue::Type::ServerTimestamp) {
182
- // Concrete timestamps come before server timestamps.
183
- return NSOrderedAscending;
184
- } else {
185
- return [self defaultCompare: other];
186
- }
187
- }
188
-
189
- @end
190
131
#pragma mark - FSTServerTimestampValue
191
132
192
133
@implementation FSTServerTimestampValue {
@@ -226,7 +167,7 @@ - (id)valueWithOptions:(const FieldValueOptions &)options {
226
167
case ServerTimestampBehavior::kNone :
227
168
return [NSNull null ];
228
169
case ServerTimestampBehavior::kEstimate :
229
- return [[FSTTimestampValue timestampValue: self .localWriteTime] valueWithOptions: options];
170
+ return [FieldValue::FromTimestamp ( self .localWriteTime). Wrap () valueWithOptions: options];
230
171
case ServerTimestampBehavior::kPrevious :
231
172
return self.previousValue ? [self .previousValue valueWithOptions: options] : [NSNull null ];
232
173
default :
@@ -683,7 +624,11 @@ - (id)value {
683
624
return @(self.internalValue .integer_value ());
684
625
case FieldValue::Type::Double:
685
626
return @(self.internalValue .double_value ());
686
- case FieldValue::Type::Timestamp:
627
+ case FieldValue::Type::Timestamp: {
628
+ auto timestamp = self.internalValue .timestamp_value ();
629
+ return [[FIRTimestamp alloc ] initWithSeconds: timestamp.seconds ()
630
+ nanoseconds: timestamp.nanoseconds ()];
631
+ }
687
632
case FieldValue::Type::ServerTimestamp:
688
633
HARD_FAIL (" TODO(rsgowman): implement" );
689
634
case FieldValue::Type::String:
@@ -701,6 +646,20 @@ - (id)value {
701
646
UNREACHABLE ();
702
647
}
703
648
649
+ - (id )valueWithOptions : (const model::FieldValueOptions &)options {
650
+ switch (self.internalValue .type ()) {
651
+ case FieldValue::Type::Timestamp:
652
+ if (options.timestamps_in_snapshots_enabled ()) {
653
+ return [self value ];
654
+ } else {
655
+ return [[self value ] dateValue ];
656
+ }
657
+
658
+ default :
659
+ return [self value ];
660
+ }
661
+ }
662
+
704
663
- (NSComparisonResult )compare : (FSTFieldValue *)other {
705
664
// TODO(rsgowman): Port the other FST*Value's, and then remove this comment:
706
665
//
@@ -710,8 +669,14 @@ - (NSComparisonResult)compare:(FSTFieldValue *)other {
710
669
// FSTDelegateValue handles (eg) booleans to ensure this case never occurs.
711
670
712
671
if (FieldValue::Comparable (self.type , other.type )) {
713
- HARD_ASSERT ([other isKindOfClass: [FSTDelegateValue class ]]);
714
- return WrapCompare<FieldValue>(self.internalValue , ((FSTDelegateValue *)other).internalValue );
672
+ if ([other isKindOfClass: [FSTServerTimestampValue class ]]) {
673
+ HARD_ASSERT (self.type == FieldValue::Type::Timestamp);
674
+ // Server timestamps come after all concrete timestamps.
675
+ return NSOrderedAscending;
676
+ } else {
677
+ HARD_ASSERT ([other isKindOfClass: [FSTDelegateValue class ]]);
678
+ return WrapCompare<FieldValue>(self.internalValue , ((FSTDelegateValue *)other).internalValue );
679
+ }
715
680
} else {
716
681
return [self defaultCompare: other];
717
682
}
0 commit comments