GDTCORClock.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. */
  25. @property(nonatomic, readonly) int64_t kernelBootTime;
  26. /** The device uptime when this clock was created. */
  27. @property(nonatomic, readonly) int64_t uptime;
  28. /** Creates a GDTCORClock object using the current time and offsets.
  29. *
  30. * @return A new GDTCORClock object representing the current time state.
  31. */
  32. + (instancetype)snapshot;
  33. /** Creates a GDTCORClock object representing a time in the future, relative to now.
  34. *
  35. * @param millisInTheFuture The millis in the future from now this clock should represent.
  36. * @return An instance representing a future time.
  37. */
  38. + (instancetype)clockSnapshotInTheFuture:(uint64_t)millisInTheFuture;
  39. /** Compares one clock with another, returns YES if the caller is after the parameter.
  40. *
  41. * @return YES if the calling clock's time is after the given clock's time.
  42. */
  43. - (BOOL)isAfter:(GDTCORClock *)otherClock;
  44. @end
  45. NS_ASSUME_NONNULL_END