GDTCORClock.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /** This class manages the device clock and produces snapshots of the current time. */
  19. @interface GDTCORClock : NSObject <NSSecureCoding>
  20. /** The wallclock time, UTC, in milliseconds. */
  21. @property(nonatomic, readonly) int64_t timeMillis;
  22. /** The offset from UTC in seconds. */
  23. @property(nonatomic, readonly) int64_t timezoneOffsetSeconds;
  24. /** The kernel boot time when this clock was created in nanoseconds. */
  25. @property(nonatomic, readonly) int64_t kernelBootTimeNanoseconds;
  26. /** The device uptime when this clock was created in nanoseconds. */
  27. @property(nonatomic, readonly) int64_t uptimeNanoseconds;
  28. @property(nonatomic, readonly) int64_t kernelBootTime DEPRECATED_MSG_ATTRIBUTE(
  29. "Please use `kernelBootTimeNanoseconds` instead");
  30. @property(nonatomic, readonly)
  31. int64_t uptime DEPRECATED_MSG_ATTRIBUTE("Please use `uptimeNanoseconds` instead");
  32. /** Creates a GDTCORClock object using the current time and offsets.
  33. *
  34. * @return A new GDTCORClock object representing the current time state.
  35. */
  36. + (instancetype)snapshot;
  37. /** Creates a GDTCORClock object representing a time in the future, relative to now.
  38. *
  39. * @param millisInTheFuture The millis in the future from now this clock should represent.
  40. * @return An instance representing a future time.
  41. */
  42. + (instancetype)clockSnapshotInTheFuture:(uint64_t)millisInTheFuture;
  43. /** Compares one clock with another, returns YES if the caller is after the parameter.
  44. *
  45. * @return YES if the calling clock's time is after the given clock's time.
  46. */
  47. - (BOOL)isAfter:(GDTCORClock *)otherClock;
  48. /** Returns value of `uptime` property in milliseconds. */
  49. - (int64_t)uptimeMilliseconds;
  50. @end
  51. NS_ASSUME_NONNULL_END