GTLRDuration.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (c) 2016 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #import <Foundation/Foundation.h>
  16. NS_ASSUME_NONNULL_BEGIN
  17. /**
  18. * An immutable class representing a string data type 'google-duration'.
  19. * It is based off the protocol buffers definition:
  20. * https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto
  21. */
  22. @interface GTLRDuration : NSObject <NSCopying>
  23. /**
  24. * Signed seconds of the span of time. Must be from -315,576,000,000
  25. * to +315,576,000,000 inclusive.
  26. **/
  27. @property(nonatomic, readonly) int64_t seconds;
  28. /**
  29. * Signed fractions of a second at nanosecond resolution of the span
  30. * of time. Durations less than one second are represented with a 0
  31. * `seconds` field and a positive or negative `nanos` field. For durations
  32. * of one second or more, a non-zero value for the `nanos` field must be
  33. * of the same sign as the `seconds` field. Must be from -999,999,999
  34. * to +999,999,999 inclusive.
  35. **/
  36. @property(nonatomic, readonly) int32_t nanos;
  37. /**
  38. * This duration expressed as a NSTimeInterval.
  39. *
  40. * @note: Not all second/nanos combinations can be represented in a
  41. * NSTimeInterval, so this could be a lossy transform.
  42. **/
  43. @property(nonatomic, readonly) NSTimeInterval timeInterval;
  44. /**
  45. * Returns the string form used to send this data type in a JSON payload.
  46. */
  47. @property(nonatomic, readonly) NSString *jsonString;
  48. /**
  49. * Constructor for a new duration with the given seconds and nanoseconds.
  50. *
  51. * Will fail if seconds/nanos differ in sign or if nanos is more than one
  52. * second.
  53. **/
  54. + (nullable instancetype)durationWithSeconds:(int64_t)seconds
  55. nanos:(int32_t)nanos;
  56. /**
  57. * Constructor for a new duration from the given string form.
  58. *
  59. * Will return nil if jsonString is invalid.
  60. **/
  61. + (nullable instancetype)durationWithJSONString:(nullable NSString *)jsonString;
  62. /**
  63. * Constructor for a new duration from the NSTimeInterval.
  64. *
  65. * @note NSTimeInterval doesn't always express things as exactly as one might
  66. * expect, so coverting from to integer seconds & nanos can reveal this.
  67. **/
  68. + (instancetype)durationWithTimeInterval:(NSTimeInterval)timeInterval;
  69. @end
  70. NS_ASSUME_NONNULL_END