GTLRDateTime.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright (c) 2011 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 date and optionally a time in UTC.
  19. */
  20. @interface GTLRDateTime : NSObject <NSCopying>
  21. /**
  22. * Constructor from a string representation.
  23. */
  24. + (nullable instancetype)dateTimeWithRFC3339String:(nullable NSString *)str;
  25. /**
  26. * Constructor from a date and time representation.
  27. */
  28. + (instancetype)dateTimeWithDate:(NSDate *)date;
  29. /**
  30. * Constructor from a date and time representation, along with an offset
  31. * minutes value used when creating a RFC3339 string representation.
  32. *
  33. * The date value is independent of time zone; the offset affects how the
  34. * date will be rendered as a string.
  35. *
  36. * The offsetMinutes may be initialized from a NSTimeZone as
  37. * (timeZone.secondsFromGMT / 60)
  38. */
  39. + (instancetype)dateTimeWithDate:(NSDate *)date
  40. offsetMinutes:(NSInteger)offsetMinutes;
  41. /**
  42. * Constructor from a date for an all-day event.
  43. *
  44. * Use this constructor to create a @c GTLRDateTime that is "date only".
  45. *
  46. * @note @c hasTime will be set to NO.
  47. */
  48. + (instancetype)dateTimeForAllDayWithDate:(NSDate *)date;
  49. /**
  50. * Constructor from date components.
  51. */
  52. + (instancetype)dateTimeWithDateComponents:(NSDateComponents *)date;
  53. /**
  54. * The represented date and time.
  55. *
  56. * If @c hasTime is NO, the time is set to noon GMT so the date is valid for all time zones.
  57. */
  58. @property(nonatomic, readonly) NSDate *date;
  59. /**
  60. * The date and time as a RFC3339 string representation.
  61. */
  62. @property(nonatomic, readonly) NSString *RFC3339String;
  63. /**
  64. * The date and time as a RFC3339 string representation.
  65. *
  66. * This returns the same string as @c RFC3339String.
  67. */
  68. @property(nonatomic, readonly) NSString *stringValue;
  69. /**
  70. * The represented date and time as date components.
  71. */
  72. @property(nonatomic, readonly, copy) NSDateComponents *dateComponents;
  73. /**
  74. * The fraction of seconds represented, 0-999.
  75. */
  76. @property(nonatomic, readonly) NSInteger milliseconds;
  77. /**
  78. * The time offset displayed in the string representation, if any.
  79. *
  80. * If the offset is not nil, the date and time will be rendered as a string
  81. * for the time zone indicated by the offset.
  82. *
  83. * An app may create a NSTimeZone for this with
  84. * [NSTimeZone timeZoneForSecondsFromGMT:(offsetMinutes.integerValue * 60)]
  85. */
  86. @property(nonatomic, readonly, nullable) NSNumber *offsetMinutes;
  87. /**
  88. * Flag indicating if the object represents date only, or date with time.
  89. */
  90. @property(nonatomic, readonly) BOOL hasTime;
  91. /**
  92. * The calendar used by this class, Gregorian and UTC.
  93. */
  94. + (NSCalendar *)calendar;
  95. @end
  96. NS_ASSUME_NONNULL_END