FIRTimestamp.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/master/src/google/protobuf/timestamp.proto for the
  28. * reference timestamp definition.
  29. */
  30. NS_SWIFT_NAME(Timestamp)
  31. @interface FIRTimestamp : NSObject <NSCopying>
  32. /** :nodoc: */
  33. - (instancetype)init NS_UNAVAILABLE;
  34. /**
  35. * Creates a new timestamp.
  36. *
  37. * @param seconds the number of seconds since epoch.
  38. * @param nanoseconds the number of nanoseconds after the seconds.
  39. */
  40. - (instancetype)initWithSeconds:(int64_t)seconds
  41. nanoseconds:(int32_t)nanoseconds NS_DESIGNATED_INITIALIZER;
  42. /**
  43. * Creates a new timestamp.
  44. *
  45. * @param seconds the number of seconds since epoch.
  46. * @param nanoseconds the number of nanoseconds after the seconds.
  47. */
  48. + (instancetype)timestampWithSeconds:(int64_t)seconds nanoseconds:(int32_t)nanoseconds;
  49. /** Creates a new timestamp from the given date. */
  50. + (instancetype)timestampWithDate:(NSDate *)date;
  51. /** Creates a new timestamp with the current date / time. */
  52. + (instancetype)timestamp;
  53. /** Returns a new `Date` corresponding to this timestamp. This may lose precision. */
  54. - (NSDate *)dateValue;
  55. /**
  56. * Returns the result of comparing the receiver with another timestamp.
  57. * @param other the other timestamp to compare.
  58. * @return `orderedAscending` if `other` is chronologically following self,
  59. * `orderedDescending` if `other` is chronologically preceding self,
  60. * `orderedSame` otherwise.
  61. */
  62. - (NSComparisonResult)compare:(FIRTimestamp *)other;
  63. /**
  64. * Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  65. * Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
  66. */
  67. @property(nonatomic, assign, readonly) int64_t seconds;
  68. /**
  69. * Non-negative fractions of a second at nanosecond resolution. Negative second values with
  70. * fractions must still have non-negative nanos values that count forward in time.
  71. * Must be from 0 to 999,999,999 inclusive.
  72. */
  73. @property(nonatomic, assign, readonly) int32_t nanoseconds;
  74. @end
  75. NS_ASSUME_NONNULL_END