LoginSignup
6
2

More than 3 years have passed since last update.

Firebase / Firestore のTimestamp の比較メソッドisEqualとcompare

Last updated at Posted at 2019-11-03

FirestoreにてTimestamp型を使用していますが、2つのTimestampの比較方法がわからなかったので今回調べました。

isEqual(object:)

インスタンスが同一かどうか

let now = Timestamp()
now.isEqual(now) // -> true

compare(object:)

2つのTimestampが同一時間か、もしくは以上・以下か

let now = Timestamp()
now.compare(now) // -> `.orderedSame`

compare(object:)メソッドによる結果

// 左は右よりも小さい
case orderedAscending
// 左は右よりも大きい
case orderedDescending
// 左右が同じ
case orderedSame

以上、備忘録です。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2