aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/model
diff options
context:
space:
mode:
authorGravatar Konstantin Varlamov <var-const@users.noreply.github.com>2018-03-27 11:50:03 -0400
committerGravatar GitHub <noreply@github.com>2018-03-27 11:50:03 -0400
commit22c226af3f5570514d3d13d82a399577ecd7d280 (patch)
treefc8f3e1ca146297f2993f8391ed3dab9e0f2c153 /Firestore/core/src/firebase/firestore/model
parent13aa61633f5a98c8dd0a508e5a404017bc79370e (diff)
C++ migration: make Timestamp class a part of public API (#944)
* move Timestamp from model/ to the root directory; * move Timestamp to top-level firebase namespace and update all references; * add conversions to and from native date types; * add a specialization of std::hash; * add comments to public member functions; * rename nanos -> nanoseconds; * add public headers, including Timestamp, to CMake; * increase test coverage.
Diffstat (limited to 'Firestore/core/src/firebase/firestore/model')
-rw-r--r--Firestore/core/src/firebase/firestore/model/CMakeLists.txt2
-rw-r--r--Firestore/core/src/firebase/firestore/model/field_value.h2
-rw-r--r--Firestore/core/src/firebase/firestore/model/snapshot_version.h2
-rw-r--r--Firestore/core/src/firebase/firestore/model/timestamp.cc54
-rw-r--r--Firestore/core/src/firebase/firestore/model/timestamp.h94
5 files changed, 2 insertions, 152 deletions
diff --git a/Firestore/core/src/firebase/firestore/model/CMakeLists.txt b/Firestore/core/src/firebase/firestore/model/CMakeLists.txt
index e7824e3..78f5cd6 100644
--- a/Firestore/core/src/firebase/firestore/model/CMakeLists.txt
+++ b/Firestore/core/src/firebase/firestore/model/CMakeLists.txt
@@ -34,8 +34,6 @@ cc_library(
resource_path.h
snapshot_version.cc
snapshot_version.h
- timestamp.cc
- timestamp.h
types.h
DEPENDS
absl_strings
diff --git a/Firestore/core/src/firebase/firestore/model/field_value.h b/Firestore/core/src/firebase/firestore/model/field_value.h
index fc8619d..9111ffb 100644
--- a/Firestore/core/src/firebase/firestore/model/field_value.h
+++ b/Firestore/core/src/firebase/firestore/model/field_value.h
@@ -25,9 +25,9 @@
#include <vector>
#include "Firestore/core/include/firebase/firestore/geo_point.h"
+#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
-#include "Firestore/core/src/firebase/firestore/model/timestamp.h"
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"
namespace firebase {
diff --git a/Firestore/core/src/firebase/firestore/model/snapshot_version.h b/Firestore/core/src/firebase/firestore/model/snapshot_version.h
index 70f6f4a..56e8c50 100644
--- a/Firestore/core/src/firebase/firestore/model/snapshot_version.h
+++ b/Firestore/core/src/firebase/firestore/model/snapshot_version.h
@@ -17,7 +17,7 @@
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_SNAPSHOT_VERSION_H_
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_SNAPSHOT_VERSION_H_
-#include "Firestore/core/src/firebase/firestore/model/timestamp.h"
+#include "Firestore/core/include/firebase/firestore/timestamp.h"
namespace firebase {
namespace firestore {
diff --git a/Firestore/core/src/firebase/firestore/model/timestamp.cc b/Firestore/core/src/firebase/firestore/model/timestamp.cc
deleted file mode 100644
index b3d1597..0000000
--- a/Firestore/core/src/firebase/firestore/model/timestamp.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.
- */
-
-#include "Firestore/core/src/firebase/firestore/model/timestamp.h"
-
-#include <time.h>
-
-#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"
-
-namespace firebase {
-namespace firestore {
-namespace model {
-
-Timestamp::Timestamp(int64_t seconds, int32_t nanos)
- : seconds_(seconds), nanos_(nanos) {
- FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
- nanos >= 0, nanos >= 0, "timestamp nanoseconds out of range: %d", nanos);
- FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
- nanos < 1e9, nanos < 1e9, "timestamp nanoseconds out of range: %d",
- nanos);
- // Midnight at the beginning of 1/1/1 is the earliest timestamp Firestore
- // supports.
- FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
- seconds >= -62135596800L, seconds >= -62135596800L,
- "timestamp seconds out of range: %lld", seconds);
- // This will break in the year 10,000.
- FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
- seconds < 253402300800L, seconds < 253402300800L,
- "timestamp seconds out of range: %lld", seconds);
-}
-
-Timestamp::Timestamp() : seconds_(0), nanos_(0) {
-}
-
-Timestamp Timestamp::Now() {
- return Timestamp(time(nullptr), 0);
-}
-
-} // namespace model
-} // namespace firestore
-} // namespace firebase
diff --git a/Firestore/core/src/firebase/firestore/model/timestamp.h b/Firestore/core/src/firebase/firestore/model/timestamp.h
deleted file mode 100644
index dd0349c..0000000
--- a/Firestore/core/src/firebase/firestore/model/timestamp.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TIMESTAMP_H_
-#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TIMESTAMP_H_
-
-#include <stdint.h>
-
-namespace firebase {
-namespace firestore {
-namespace model {
-
-/**
- * A Timestamp represents an absolute time from the backend at up to nanosecond
- * precision. A Timestamp is always UTC.
- */
-class Timestamp {
- public:
- /**
- * Creates a new timestamp with seconds and nanos set to 0.
- *
- * PORTING NOTE: This does NOT set to current timestamp by default. To get the
- * current timestamp, call Timestamp::Now().
- */
- Timestamp();
-
- /**
- * Creates a new timestamp.
- *
- * @param seconds the number of seconds since epoch.
- * @param nanos the number of nanoseconds after the seconds.
- */
- Timestamp(int64_t seconds, int32_t nanos);
-
- /** Returns a timestamp with the current date / time. */
- static Timestamp Now();
-
- int64_t seconds() const {
- return seconds_;
- }
-
- int32_t nanos() const {
- return nanos_;
- }
-
- private:
- int64_t seconds_;
- int32_t nanos_;
-};
-
-/** Compares against another Timestamp. */
-inline bool operator<(const Timestamp& lhs, const Timestamp& rhs) {
- return lhs.seconds() < rhs.seconds() ||
- (lhs.seconds() == rhs.seconds() && lhs.nanos() < rhs.nanos());
-}
-
-inline bool operator>(const Timestamp& lhs, const Timestamp& rhs) {
- return rhs < lhs;
-}
-
-inline bool operator>=(const Timestamp& lhs, const Timestamp& rhs) {
- return !(lhs < rhs);
-}
-
-inline bool operator<=(const Timestamp& lhs, const Timestamp& rhs) {
- return !(lhs > rhs);
-}
-
-inline bool operator!=(const Timestamp& lhs, const Timestamp& rhs) {
- return lhs < rhs || lhs > rhs;
-}
-
-inline bool operator==(const Timestamp& lhs, const Timestamp& rhs) {
- return !(lhs != rhs);
-}
-
-} // namespace model
-} // namespace firestore
-} // namespace firebase
-
-#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TIMESTAMP_H_