firebase / firebase/firebase-ios-sdk

Saving Date.distantPast to Firestore leads to crash

Open
#10,001 2 comments 0 reactions 0 assignees View on GitHub
api: firestore
Dominant language
C++
Stars
6.7k
Forks
1.8k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

* Xcode version: 13.4.1
* Firebase SDK version: 8.10.0
* Installation method: `CocoaPods `
* Firebase Component: Firestore
* Target platform(s): `iOS`

When I try to save to Firestore a date object that is `Date.distantPast`, I get the following crash:

```
*** Terminating app due to uncaught exception 'Invalid timestamp', reason: 'Timestamp seconds out of range: -62135769600'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20405604 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff201a4a45 objc_exception_throw + 48
2 CoreFoundation 0x00007fff204054e2 -[NSException initWithCoder:] + 0
3 FirebaseFirestore 0x000000010dba641d -[FIRTimestamp initWithSeconds:nanoseconds:] + 269
4 FirebaseFirestore 0x000000010dba6219 +[FIRTimestamp timestampWithDate:] + 201
5 FirebaseFirestore 0x000000010da5bf07 _ZN8firebase9firestore3api13MakeTimestampEP6NSDate + 55
6 FirebaseFirestore 0x000000010dbb6bc0 -[FSTUserDataReader parseScalarValue:context:] + 1616
7 FirebaseFirestore 0x000000010dbb43eb -[FSTUserDataReader parseData:context:] + 1275
8 FirebaseFirestore 0x000000010dbb4d4e __45-[FSTUserDataReader parseDictionary:context:]_block_invoke.65 + 254
9 libswiftCore.dylib 0x00007fff30c50631 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTf4dnn_n + 321
10 libswiftCore.dylib 0x00007fff30a316c5 $ss26_SwiftDeferredNSDictionaryC23enumerateKeysAndObjects7options5usingySi_ys9UnmanagedVyyXlG_AHSpys5UInt8VGtXBtFTo + 37
11 FirebaseFirestore 0x000000010dbb495b -[FSTUserDataReader parseDictionary:context:] + 1067
12 FirebaseFirestore 0x000000010dbb4079 -[FSTUserDataReader parseData:context:] + 393
13 FirebaseFirestore 0x000000010dbb25d5 -[FSTUserDataReader parsedMergeData:fieldMask:] + 405
14 FirebaseFirestore 0x000000010dafb5d3 -[FIRDocumentReference setData:merge:completion:] + 323
15 FirebaseFirestore 0x000000010dafb2c9 -[FIRDocumentReference setData:merge:] + 89
```

Looks like a bug, but if that's an intended behavior, is there a convenient way to check if a date object is ok for Firestore (or to convert it to the nearest valid one)?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.