GTLRDuration.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #import "GTLRDefines.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * An immutable class representing a string data type 'google-duration'.
  20. * It is based off the protocol buffers definition:
  21. * https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto
  22. */
  23. @interface GTLRDuration : NSObject <NSCopying>
  24. /**
  25. * Signed seconds of the span of time. Must be from -315,576,000,000
  26. * to +315,576,000,000 inclusive.
  27. **/
  28. @property(nonatomic, readonly) int64_t seconds;
  29. /**
  30. * Signed fractions of a second at nanosecond resolution of the span
  31. * of time. Durations less than one second are represented with a 0
  32. * `seconds` field and a positive or negative `nanos` field. For durations
  33. * of one second or more, a non-zero value for the `nanos` field must be
  34. * of the same sign as the `seconds` field. Must be from -999,999,999
  35. * to +999,999,999 inclusive.
  36. **/
  37. @property(nonatomic, readonly) int32_t nanos;
  38. /**
  39. * This duration expressed as a NSTimeInterval.
  40. *
  41. * @note: Not all second/nanos combinations can be represented in a
  42. * NSTimeInterval, so this could be a lossy transform.
  43. **/
  44. @property(nonatomic, readonly) NSTimeInterval timeInterval;
  45. /**
  46. * Returns the string form used to send this data type in a JSON payload.
  47. */
  48. @property(nonatomic, readonly) NSString *jsonString;
  49. /**
  50. * Constructor for a new duration with the given seconds and nanoseconds.
  51. *
  52. * Will fail if seconds/nanos differ in sign or if nanos is more than one
  53. * second.
  54. **/
  55. + (nullable instancetype)durationWithSeconds:(int64_t)seconds
  56. nanos:(int32_t)nanos;
  57. /**
  58. * Constructor for a new duration from the given string form.
  59. *
  60. * Will return nil if jsonString is invalid.
  61. **/
  62. + (nullable instancetype)durationWithJSONString:(nullable NSString *)jsonString;
  63. /**
  64. * Constructor for a new duration from the NSTimeInterval.
  65. *
  66. * @note NSTimeInterval doesn't always express things as exactly as one might
  67. * expect, so coverting from to integer seconds & nanos can reveal this.
  68. **/
  69. + (instancetype)durationWithTimeInterval:(NSTimeInterval)timeInterval;
  70. @end
  71. NS_ASSUME_NONNULL_END