FIRTimestamp.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * A Timestamp represents a point in time independent of any time zone or calendar, represented as
  20. * seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using
  21. * the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one. It
  22. * is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are "smeared" so that no
  23. * leap second table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
  24. * 9999-12-31T23:59:59.999999999Z. By restricting to that range, we ensure that we can convert to
  25. * and from RFC 3339 date strings.
  26. *
  27. * @see https://github.com/google/protobuf/blob/main/src/google/protobuf/timestamp.proto for the
  28. * reference timestamp definition.
  29. */
  30. NS_SWIFT_SENDABLE
  31. NS_SWIFT_NAME(Timestamp)
  32. @interface FIRTimestamp : NSObject <NSCopying>
  33. /** :nodoc: */
  34. - (instancetype)init NS_UNAVAILABLE;
  35. /**
  36. * Creates a new timestamp.
  37. *
  38. * @param seconds the number of seconds since epoch.
  39. * @param nanoseconds the number of nanoseconds after the seconds.
  40. */
  41. - (instancetype)initWithSeconds:(int64_t)seconds
  42. nanoseconds:(int32_t)nanoseconds NS_DESIGNATED_INITIALIZER;
  43. /**
  44. * Creates a new timestamp.
  45. *
  46. * @param seconds the number of seconds since epoch.
  47. * @param nanoseconds the number of nanoseconds after the seconds.
  48. */
  49. + (instancetype)timestampWithSeconds:(int64_t)seconds nanoseconds:(int32_t)nanoseconds;
  50. /** Creates a new timestamp from the given date. */
  51. + (instancetype)timestampWithDate:(NSDate *)date;
  52. /** Creates a new timestamp with the current date / time. */
  53. + (instancetype)timestamp;
  54. /** Returns a new `Date` corresponding to this timestamp. This may lose precision. */
  55. - (NSDate *)dateValue;
  56. /**
  57. * Returns the result of comparing the receiver with another timestamp.
  58. * @param other the other timestamp to compare.
  59. * @return `orderedAscending` if `other` is chronologically following self,
  60. * `orderedDescending` if `other` is chronologically preceding self,
  61. * `orderedSame` otherwise.
  62. */
  63. - (NSComparisonResult)compare:(FIRTimestamp *)other;
  64. /**
  65. * Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  66. * Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
  67. */
  68. @property(nonatomic, assign, readonly) int64_t seconds;
  69. /**
  70. * Non-negative fractions of a second at nanosecond resolution. Negative second values with
  71. * fractions must still have non-negative nanos values that count forward in time.
  72. * Must be from 0 to 999,999,999 inclusive.
  73. */
  74. @property(nonatomic, assign, readonly) int32_t nanoseconds;
  75. @end
  76. NS_ASSUME_NONNULL_END