timestamp_internal.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FIRESTORE_CORE_SRC_TIMESTAMP_INTERNAL_H_
  17. #define FIRESTORE_CORE_SRC_TIMESTAMP_INTERNAL_H_
  18. #include "Firestore/core/include/firebase/firestore/timestamp.h"
  19. #include "Firestore/core/src/util/statusor.h"
  20. #include "absl/time/time.h"
  21. namespace firebase {
  22. /**
  23. * Details about the Timestamp class which are useful internally, but we don't
  24. * want to expose publicly.
  25. */
  26. class TimestampInternal {
  27. public:
  28. /**
  29. * Represents the maximum allowable time that the Timestamp class handles,
  30. * specifically 9999-12-31T23:59:59.999999999Z.
  31. */
  32. static firebase::Timestamp Max() {
  33. return {253402300800L - 1, 999999999};
  34. }
  35. /**
  36. * Represents the minimum allowable time that the Timestamp class handles,
  37. * specifically 0001-01-01T00:00:00Z.
  38. */
  39. static firebase::Timestamp Min() {
  40. return {-62135596800L, 0};
  41. }
  42. static firestore::util::StatusOr<firebase::Timestamp> FromUntrustedTime(
  43. absl::Time time);
  44. static firestore::util::StatusOr<firebase::Timestamp>
  45. FromUntrustedSecondsAndNanos(int64_t seconds, int32_t nanos);
  46. static size_t Hash(const Timestamp& timestamp);
  47. /**
  48. * Truncates the input timestamp to microsecond precision to match backend
  49. * behavior.
  50. */
  51. static Timestamp Truncate(const Timestamp& timestamp);
  52. };
  53. } // namespace firebase
  54. #endif // FIRESTORE_CORE_SRC_TIMESTAMP_INTERNAL_H_